@startuml
!include skin.inc

participant "<i>Browser</i>" as bro #ffffff
participant "Application" as app 
participant "Server" as srv 


note left of bro 
	Visit site and 
	download Application
end note
app -->> bro: <i>Create PeerConnection and set up media sources</i>
app -->> bro: <i>offerSdp1=peerConnection.CreateOffer()</i>
app -->> bro: <i>peerConnection.SetLocalDescription(offer, offerSdp1)</i>

app -> srv: POST VvoipSession(userId, offerSdp1)
srv --> app: Response with sessionId
note right of srv: pass on the offer\nand wait for answer
srv -> app: POST or NOTIFY\nVvoipAnswerNotification((pr)answer, answerSdp1)
app -->> bro: <i>peerConnection.SetRemoteDescription((pr)answer, answerSdp1)</i>

note over bro, srv
 Running ICE connectivity checks
end note
bro -->> app: <i>oniceconnectionstatechange(connected)</i>
app -> srv: PUT VvoipIceStatus(Connected)
srv --> app: Response

alt Alternative 1: answer arrives before acceptance
	srv -> app: POST or NOTIFY\nVvoipAnswerNotification(answer, answerSdp2)
	app -->> bro: <i>peerConnection.setRemoteDescription(answer, answerSdp2)</i>

	note right of srv: Terminating participant is alerted
	srv -> app: POST or NOTIFY VvoipEventNotification(Ringing)

	note right of srv: Terminating participant accepts
	srv -> app: POST or NOTIFY\nVvoipAcceptanceNotification()

else Alternative 2: Answer arrives in acceptance notification
	note right of srv: Terminating participant is alerted
	srv -> app: POST or NOTIFY VvoipEventNotification(Ringing)

	note right of srv: Terminating participant accepts
	srv -> app: POST or NOTIFY\nVvoipAcceptanceNotification(answer, answerSdp2)
	app -->> bro: <i>peerConnection.setRemoteDescription(answer, answerSdp2)</i>
end

note over bro, srv
 Originator and Terminating Participant are in a call now.
end note

app -> srv: DELETE VvoipSession with sessionId
srv --> app: Response
note right of srv: Send termination request
app -->> bro: <i>peerConnection.Close()</i>

@enduml