@startuml
!include skin.inc

autonumber "#'.'"

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

note over bro, srv:  Both parties are in a call already.

note right of app: User requests addition / \nremoval of video

app -->> bro: <i>Update PeerConnection, e.g. adding or removing video stream</i>
app -->> bro: <i>offerSdp=peerConnection.CreateOffer()</i>
app -->> bro: <i>peerConnection.SetLocalDescription(offer, offerSdp)</i>

app -> srv: POST WrtcsOffer(sessionId, offerSdp)
srv --> app: Response 
srv-->>]: <i>(re)INVITE offerSdp</i>

alt Alternative 1: Terminating participant declines update
	srv<<--]: <i>488 Not Acceptable Here</i>
	srv -> app: POST or NOTIFY WrtcsEventNotification(Declined)
	app -->> bro: <i>peerConnection.SetLocalDescription(rollback, null)</i>

	note over bro, srv: Call goes ahead without modification.
else Alternative 2: Terminating participant accepts update
	srv<<--]: <i>200 OK INVITE(answerSdp)</i>
	srv -> app: POST or NOTIFY WrtcsAcceptanceNotification(answer, answerSdp)
	app -->> bro: <i>peerConnection.setRemoteDescription(answer, answerSdp)</i>

	bro -->> app: <i>oniceconnectionstatechange(new)</i>
	app -> srv: PUT WrtcsIceStatus(New)
	srv --> app: Response
	note over bro, srv: Running ICE connectivity checks (if applicable).

	bro -->> app: <i>oniceconnectionstatechange(connected)</i>
	app -> srv: PUT WrtcsIceStatus(Connected)
	srv --> app: Response

	note over bro, srv: Call goes ahead with modified media streams.
end
@enduml