Commit e393819e authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Carry raw SDP in the protocol.

parent ddafca57
...@@ -174,8 +174,7 @@ type clientMessage struct { ...@@ -174,8 +174,7 @@ type clientMessage struct {
Group string `json:"group,omitempty"` Group string `json:"group,omitempty"`
Value interface{} `json:"value,omitempty"` Value interface{} `json:"value,omitempty"`
Time int64 `json:"time,omitempty"` Time int64 `json:"time,omitempty"`
Offer *webrtc.SessionDescription `json:"offer,omitempty"` SDP string `json:"sdp,omitempty"`
Answer *webrtc.SessionDescription `json:"answer,omitempty"`
Candidate *webrtc.ICECandidateInit `json:"candidate,omitempty"` Candidate *webrtc.ICECandidateInit `json:"candidate,omitempty"`
Labels map[string]string `json:"labels,omitempty"` Labels map[string]string `json:"labels,omitempty"`
Request rateMap `json:"request,omitempty"` Request rateMap `json:"request,omitempty"`
...@@ -464,7 +463,7 @@ func negotiate(c *webClient, down *rtpDownConnection, renegotiate, restartIce bo ...@@ -464,7 +463,7 @@ func negotiate(c *webClient, down *rtpDownConnection, renegotiate, restartIce bo
Id: down.id, Id: down.id,
Source: source, Source: source,
Username: username, Username: username,
Offer: &offer, SDP: offer.SDP,
Labels: labels, Labels: labels,
}) })
} }
...@@ -481,7 +480,7 @@ func sendICE(c *webClient, id string, candidate *webrtc.ICECandidate) error { ...@@ -481,7 +480,7 @@ func sendICE(c *webClient, id string, candidate *webrtc.ICECandidate) error {
}) })
} }
func gotOffer(c *webClient, id string, offer webrtc.SessionDescription, renegotiate bool, labels map[string]string) error { func gotOffer(c *webClient, id string, sdp string, renegotiate bool, labels map[string]string) error {
if !renegotiate { if !renegotiate {
// unless the client indicates that this is a compatible // unless the client indicates that this is a compatible
// renegotiation, tear down the existing connection. // renegotiation, tear down the existing connection.
...@@ -496,12 +495,15 @@ func gotOffer(c *webClient, id string, offer webrtc.SessionDescription, renegoti ...@@ -496,12 +495,15 @@ func gotOffer(c *webClient, id string, offer webrtc.SessionDescription, renegoti
up.userId = c.Id() up.userId = c.Id()
up.username = c.Username() up.username = c.Username()
err = up.pc.SetRemoteDescription(offer) err = up.pc.SetRemoteDescription(webrtc.SessionDescription{
Type: webrtc.SDPTypeOffer,
SDP: sdp,
})
if err != nil { if err != nil {
if renegotiate && !isnew { if renegotiate && !isnew {
// create a new PC from scratch // create a new PC from scratch
log.Printf("SetRemoteDescription(offer): %v", err) log.Printf("SetRemoteDescription(offer): %v", err)
return gotOffer(c, id, offer, false, labels) return gotOffer(c, id, sdp, false, labels)
} }
return err return err
} }
...@@ -524,18 +526,21 @@ func gotOffer(c *webClient, id string, offer webrtc.SessionDescription, renegoti ...@@ -524,18 +526,21 @@ func gotOffer(c *webClient, id string, offer webrtc.SessionDescription, renegoti
return c.write(clientMessage{ return c.write(clientMessage{
Type: "answer", Type: "answer",
Id: id, Id: id,
Answer: &answer, SDP: answer.SDP,
}) })
} }
var ErrUnknownId = errors.New("unknown id") var ErrUnknownId = errors.New("unknown id")
func gotAnswer(c *webClient, id string, answer webrtc.SessionDescription) error { func gotAnswer(c *webClient, id string, sdp string) error {
down := getDownConn(c, id) down := getDownConn(c, id)
if down == nil { if down == nil {
return ErrUnknownId return ErrUnknownId
} }
err := down.pc.SetRemoteDescription(answer) err := down.pc.SetRemoteDescription(webrtc.SessionDescription{
Type: webrtc.SDPTypeAnswer,
SDP: sdp,
})
if err != nil { if err != nil {
return err return err
} }
...@@ -1128,21 +1133,15 @@ func handleClientMessage(c *webClient, m clientMessage) error { ...@@ -1128,21 +1133,15 @@ func handleClientMessage(c *webClient, m clientMessage) error {
}) })
return c.error(group.UserError("not authorised")) return c.error(group.UserError("not authorised"))
} }
if m.Offer == nil {
return group.ProtocolError("null offer")
}
err := gotOffer( err := gotOffer(
c, m.Id, *m.Offer, m.Kind == "renegotiate", m.Labels, c, m.Id, m.SDP, m.Kind == "renegotiate", m.Labels,
) )
if err != nil { if err != nil {
log.Printf("gotOffer: %v", err) log.Printf("gotOffer: %v", err)
return failUpConnection(c, m.Id, "negotiation failed") return failUpConnection(c, m.Id, "negotiation failed")
} }
case "answer": case "answer":
if m.Answer == nil { err := gotAnswer(c, m.Id, m.SDP)
return group.ProtocolError("null answer")
}
err := gotAnswer(c, m.Id, *m.Answer)
if err != nil { if err != nil {
log.Printf("gotAnswer: %v", err) log.Printf("gotAnswer: %v", err)
message := "" message := ""
......
...@@ -183,8 +183,7 @@ function ServerConnection() { ...@@ -183,8 +183,7 @@ function ServerConnection() {
* @property {Object<string,boolean>} [permissions] * @property {Object<string,boolean>} [permissions]
* @property {string} [group] * @property {string} [group]
* @property {unknown} [value] * @property {unknown} [value]
* @property {RTCSessionDescriptionInit} [offer] * @property {string} [sdp]
* @property {RTCSessionDescriptionInit} [answer]
* @property {RTCIceCandidate} [candidate] * @property {RTCIceCandidate} [candidate]
* @property {Object<string,string>} [labels] * @property {Object<string,string>} [labels]
* @property {Object<string,(boolean|number)>} [request] * @property {Object<string,(boolean|number)>} [request]
...@@ -265,10 +264,10 @@ ServerConnection.prototype.connect = async function(url) { ...@@ -265,10 +264,10 @@ ServerConnection.prototype.connect = async function(url) {
break; break;
case 'offer': case 'offer':
sc.gotOffer(m.id, m.labels, m.source, m.username, sc.gotOffer(m.id, m.labels, m.source, m.username,
m.offer, m.kind === 'renegotiate'); m.sdp, m.kind === 'renegotiate');
break; break;
case 'answer': case 'answer':
sc.gotAnswer(m.id, m.answer); sc.gotAnswer(m.id, m.sdp);
break; break;
case 'renegotiate': case 'renegotiate':
sc.gotRenegotiate(m.id) sc.gotRenegotiate(m.id)
...@@ -525,11 +524,11 @@ ServerConnection.prototype.groupAction = function(kind, message) { ...@@ -525,11 +524,11 @@ ServerConnection.prototype.groupAction = function(kind, message) {
* @param {Object<string, string>} labels * @param {Object<string, string>} labels
* @param {string} source * @param {string} source
* @param {string} username * @param {string} username
* @param {RTCSessionDescriptionInit} offer * @param {string} sdp
* @param {boolean} renegotiate * @param {boolean} renegotiate
* @function * @function
*/ */
ServerConnection.prototype.gotOffer = async function(id, labels, source, username, offer, renegotiate) { ServerConnection.prototype.gotOffer = async function(id, labels, source, username, sdp, renegotiate) {
let sc = this; let sc = this;
let c = sc.down[id]; let c = sc.down[id];
if(c && !renegotiate) { if(c && !renegotiate) {
...@@ -598,7 +597,10 @@ ServerConnection.prototype.gotOffer = async function(id, labels, source, usernam ...@@ -598,7 +597,10 @@ ServerConnection.prototype.gotOffer = async function(id, labels, source, usernam
sc.ondownstream.call(sc, c); sc.ondownstream.call(sc, c);
try { try {
await c.pc.setRemoteDescription(offer); await c.pc.setRemoteDescription({
type: 'offer',
sdp: sdp,
});
await c.flushRemoteIceCandidates(); await c.flushRemoteIceCandidates();
...@@ -609,7 +611,7 @@ ServerConnection.prototype.gotOffer = async function(id, labels, source, usernam ...@@ -609,7 +611,7 @@ ServerConnection.prototype.gotOffer = async function(id, labels, source, usernam
this.send({ this.send({
type: 'answer', type: 'answer',
id: id, id: id,
answer: answer, sdp: answer.sdp,
}); });
} catch(e) { } catch(e) {
try { try {
...@@ -631,15 +633,18 @@ ServerConnection.prototype.gotOffer = async function(id, labels, source, usernam ...@@ -631,15 +633,18 @@ ServerConnection.prototype.gotOffer = async function(id, labels, source, usernam
* Called when we receive an answer from the server. Don't call this. * Called when we receive an answer from the server. Don't call this.
* *
* @param {string} id * @param {string} id
* @param {RTCSessionDescriptionInit} answer * @param {string} sdp
* @function * @function
*/ */
ServerConnection.prototype.gotAnswer = async function(id, answer) { ServerConnection.prototype.gotAnswer = async function(id, sdp) {
let c = this.up[id]; let c = this.up[id];
if(!c) if(!c)
throw new Error('unknown up stream'); throw new Error('unknown up stream');
try { try {
await c.pc.setRemoteDescription(answer); await c.pc.setRemoteDescription({
type: 'answer',
sdp: sdp,
});
} catch(e) { } catch(e) {
try { try {
if(c.onerror) if(c.onerror)
...@@ -1038,7 +1043,7 @@ Stream.prototype.negotiate = async function (restartIce) { ...@@ -1038,7 +1043,7 @@ Stream.prototype.negotiate = async function (restartIce) {
kind: this.localDescriptionSent ? 'renegotiate' : '', kind: this.localDescriptionSent ? 'renegotiate' : '',
id: c.id, id: c.id,
labels: c.labelsByMid, labels: c.labelsByMid,
offer: offer, sdp: offer.sdp,
}); });
this.localDescriptionSent = true; this.localDescriptionSent = true;
c.flushLocalIceCandidates(); c.flushLocalIceCandidates();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment