@startuml
!include skin.inc

autonumber "#'.'"

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


note left of srv: Receive invitation \nwhich informs about \npreconditions not met
[-->>srv: <i>INVITE(userId, offerSdp1 with PreCo)</i>
srv -> app: POST or NOTIFY WrtcsSessionInvitationNotification(\nofferSdp1, holdAlerting, sessionId)

app -->> bro: <i>Create PeerConnection and set up media sources</i>
app -->> bro: <i>peerConnection.SetRemoteDescription(offer, offerSdp1)</i>
app -->> bro: <i>answerSdp1=peerConnection.CreateAnswer()</i>
app -->> bro: <i>peerConnection.SetLocalDescription(answer, answerSdp1)</i>

note right of app: Indicate an initial answer\nbut do not ring yet
app -> srv: PUT WrtcsAnswer(answer, answerSdp1)
srv --> app: Response

note left of srv: Send answer reliably
[<<-- srv: <i>183 Session Progress (answerSdp1; 100rel)</i>
[-->>	srv: <i>PRACK</i>
[<<--	srv: <i>200 OK PRACK</i>

note over bro, srv
 Running ICE connectivity checks
end note
bro -> app: oniceconnectionstatechange(connected)</i>
app -> srv: PUT WrtcsIceStatus(Connected)
srv --> app: Response
note right of app: Own ICE finished but still cannot ring

note left of srv: Receive offer informing \nthat preconditions are met
[-->> srv: <i>UPDATE(offerSdp2)</i>
srv -> app: WrtcsOfferNotification(offerSdp2)
app -->> bro: <i>peerConnection.setRemoteDescription(offer, offerSdp2)</i>
app -->> bro: <i>answerSdp2=peerConnection.CreateAnswer()</i>
app -->> bro: <i>peerConnection.SetLocalDescription(answer, answerSdp2)</i>
app -> srv: PUT WrtcsAnswer(answer, answerSdp2)
app <-- srv: Response
[<<-- srv: <i>200 OK UPDATE (answerSdp2)</i>

note right of app: After receiving offer\nwithout "holdAlerting" flag,\nalerting can now take place
app -> srv: PUT WrtcsSessionStatus(Ringing)
srv --> app: Response
note left of srv: Indicate that user \nis being alerted
[<<-- srv: <i>180 Ringing</i>
app -->> app: <i>Alert the user</i>

note right of app: User accepts
app -> srv: PUT WrtcsSessionStatus(Connected)
srv --> app: Response
note left of srv: Accept invitation (no new answer is sent)
[<<-- srv: <i>200 OK INVITE</i>
[-->> srv: <i>ACK</i>

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

@enduml