@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.

[-->>srv: <i>(re)INVITE offerSdp</i>
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
	[<<--srv: <i>488 Not Acceptable Here</i>
	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
	[<<--srv: <i>200 OK INVITE(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


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
