@startuml
!include skin.inc

autonumber "#'.'"

participant "Server" as srv 
participant "Application" as app 
participant "Browser" as bro 

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

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

app -> srv: PUT VvoipAnswer(answer, answerSdp1)
srv --> app: Response

note left of srv: Indicate an initial answer\nbut do not ring yet
[<- srv: 183 Session Progress (answerSdp1; 100rel)
[->	srv: PRACK
[<-	srv: 200 OK PRACK

note over bro, srv
 Running ICE connectivity checks
end note
bro -> app: oniceconnectionstatechange(completed)
app -> srv: PUT VvoipIceStatus(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: UPDATE(offerSdp2)
srv -> app: VvoipOfferAnswerNotification(offer, offerSdp2)
app -> bro: peerConnection.setRemoteDescription(offer, offerSdp2)
app -> bro: answerSdp2=peerConnection.CreateAnswer()
app -> bro: peerConnection.SetLocalDescription(answer, answerSdp2)
app -> srv: PUT VvoipAnswer(answer, answerSdp2)
[<- srv: 200 OK UPDATE (answerSdp2)

app -> srv: PUT VvoipSessionStatus(Ringing)
srv --> app: Response
note left of srv: Indicate that user is being alerted
[<- srv: 180 Ringing

note right of app: After receiving offer\nwithout "holdAlerting" flag,\nalerting can now take place
app -> app: Alert the user
note right of app: User accepts
app -> srv: PUT VvoipSessionStatus(Connected)
srv --> app: Response
note left of srv: Accept invitation (no new answer is sent)
[<- srv: 200 OK INVITE
[-> srv: ACK

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

note left of srv: Session termination request
[-> srv: BYE
[<- srv: 200 OK BYE
srv -> app: POST or NOTIFY VvoipEventNotification(SessionEnded)
app -> bro: peerConnection.Close()

@enduml