From 52c4f1a399b47150db09be5caa8f163430f21f3e Mon Sep 17 00:00:00 2001 From: Juliusz Chroboczek Date: Wed, 12 Aug 2020 13:56:35 +0200 Subject: [PATCH] Restructure offers. --- static/sfu.js | 4 ++-- webclient.go | 22 ++++++++++++++-------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/static/sfu.js b/static/sfu.js index 7c01dd9..19d3988 100644 --- a/static/sfu.js +++ b/static/sfu.js @@ -646,7 +646,7 @@ function serverConnect() { let m = JSON.parse(e.data); switch(m.type) { case 'offer': - gotOffer(m.id, m.labels, m.offer, !!m.renegotiate); + gotOffer(m.id, m.labels, m.offer, m.kind === 'renegotiate'); break; case 'answer': gotAnswer(m.id, m.answer); @@ -1276,10 +1276,10 @@ async function negotiate(id, restartIce) { send({ type: 'offer', + kind: 'renegotiate', id: id, labels: c.labelsByMid, offer: offer, - renegotiate: true, }); } diff --git a/webclient.go b/webclient.go index 1e67dde..2e8647d 100644 --- a/webclient.go +++ b/webclient.go @@ -173,17 +173,16 @@ func (v rateMap) MarshalJSON() ([]byte, error) { type clientMessage struct { Type string `json:"type"` + Kind string `json:"kind,omitempty"` Id string `json:"id,omitempty"` Username string `json:"username,omitempty"` Password string `json:"password,omitempty"` Permissions clientPermission `json:"permissions,omitempty"` Group string `json:"group,omitempty"` Value string `json:"value,omitempty"` - Kind string `json:"kind,omitempty"` Offer *webrtc.SessionDescription `json:"offer,omitempty"` Answer *webrtc.SessionDescription `json:"answer,omitempty"` Candidate *webrtc.ICECandidateInit `json:"candidate,omitempty"` - Renegotiate bool `json:"renegotiate,omitempty"` Labels map[string]string `json:"labels,omitempty"` Request rateMap `json:"request,omitempty"` } @@ -431,12 +430,17 @@ func negotiate(c *webClient, down *rtpDownConnection, renegotiate, restartIce bo } } + kind := "" + if renegotiate { + kind = "renegotiate" + } + return c.write(clientMessage{ - Type: "offer", - Id: down.id, - Offer: &offer, - Renegotiate: renegotiate, - Labels: labels, + Type: "offer", + Kind: kind, + Id: down.id, + Offer: &offer, + Labels: labels, }) } @@ -964,7 +968,9 @@ func handleClientMessage(c *webClient, m clientMessage) error { if m.Offer == nil { return protocolError("null offer") } - err := gotOffer(c, m.Id, *m.Offer, m.Renegotiate, m.Labels) + err := gotOffer( + c, m.Id, *m.Offer, m.Kind == "renegotiate", m.Labels, + ) if err != nil { log.Printf("gotOffer: %v", err) return failConnection(c, m.Id, "negotiation failed")