@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 session invitation \nwithout offer
srv -> app: POST or NOTIFY WrtcsSessionInvitationNotification(sessionId, forceConnectingWithoutMedia={true, false})

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: PUT WrtcsOffer(offer, offerSdp1)
srv --> app: Response

alt Alternative 1 (default): forceConnectingWithoutMedia==false or absent
	note left of srv: Send offer reliably \nand wait for answer 

	srv -> app: POST or NOTIFY\nWrtcsAnswerNotification(answer, answerSdp1)
	app -->> bro: <i>peerConnection.SetRemoteDescription(answer, answerSdp1)</i>

	note over bro, srv
	 Running ICE connectivity checks
	end note
	note right of app: wait for ICE to finish before alerting
	bro -->> app: <i>oniceconnectionstatechange(connected)</i>
	app -> srv: PUT WrtcsIceStatus(Connected)
	srv --> app: Response

	app -> srv: PUT WrtcsSessionStatus(Ringing)
	srv --> app: Response

	note left of srv: Send ringing indication
	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: Send acceptance indication
else Alternative 2: forceConnectingWithoutMedia==true
	note left of srv: Indicate session progress 

	note right of app: start alerting immediately
	app -> srv: PUT WrtcsSessionStatus(Ringing)
	srv --> app: Response
	note left of srv: Send ringing indication 

	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: Send acceptance indication\nwith offer and receive answer 
	
	srv -> app: POST or NOTIFY\nWrtcsAnswerNotification(answer, answerSdp1)
	app -->> bro: <i>peerConnection.SetRemoteDescription(answer, answerSdp1)</i>

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

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

@enduml