@startuml
!include skin.inc

autonumber "#'.'"

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

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

note left of srv: Receive session \nmodification request
srv -> app: POST or NOTIFY WrtcsOfferNotification(offerSdp)
note right of app: Decide whether adding a stream is acceptable, \npossibly involving the user

alt Alternative 1: Decline update
	app -> srv: DELETE 
	srv --> app: Response
	note left of srv: indicate rejection to \nUpdate Originator
	note over bro, srv: Call goes ahead without modification.
else Alternative 2: Accept update
	app -->> bro: <i>peerConnection.setRemoteDescription(offer, offerSdp)</i>
	bro -->> app: <i>onnaddstream() / onremovestream()</i>
	app -->> app: <i>Take notice of stream changes</i>
	app -->> bro: <i>peerConnection.createAnswer(answerSDP)</i>
	app -> srv: PUT WrtcsAnswer(answer)
	srv --> app: Response
	note left of srv: pass on answer 

	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


app -> srv: POST WrtcsOffer(sessionId, offerSdp)
srv --> app: Response 
note right of srv: pass on the offer
note right of srv: receive answer

srv -> app: POST or NOTIFY WrtcsAnswerNotification(answer, answerSdp)
app -->> bro: <i>peerConnection.setRemoteDescription(answer, answerSdp)</i>

bro -->> app: <i>onnaddstream() / onremovestream()</i>
app -->> app: <i>Take notice of stream changes</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 right of srv: receive acceptance notification

srv -> app: POST or NOTIFY WrtcsAcceptanceNotification()
app -->> bro: <i>peerConnection.setRemoteDescription(answer, answerSdp)</i>

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

note over bro, srv: TODO: reINVITE, find a way to signal acceptance without SDP, and 18x
