mirror of
https://github.com/jech/galene.git
synced 2024-11-10 02:35:58 +01:00
Allow both sides to initiate renegotiation.
More reliable reaction to network failures when they are detected by just one side.
This commit is contained in:
parent
7aab79c4c6
commit
6a37033ca8
2 changed files with 49 additions and 11 deletions
|
@ -648,6 +648,17 @@ function serverConnect() {
|
||||||
case 'answer':
|
case 'answer':
|
||||||
gotAnswer(m.id, m.answer);
|
gotAnswer(m.id, m.answer);
|
||||||
break;
|
break;
|
||||||
|
case 'renegotiate':
|
||||||
|
let c = up[id];
|
||||||
|
if(c) {
|
||||||
|
try {
|
||||||
|
c.pc.restartIce()
|
||||||
|
} catch(e) {
|
||||||
|
console.error(e);
|
||||||
|
displayError(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
case 'close':
|
case 'close':
|
||||||
gotClose(m.id);
|
gotClose(m.id);
|
||||||
break;
|
break;
|
||||||
|
@ -743,6 +754,11 @@ async function gotOffer(id, labels, offer, renegotiate) {
|
||||||
|
|
||||||
pc.oniceconnectionstatechange = e => {
|
pc.oniceconnectionstatechange = e => {
|
||||||
setMediaStatus(id);
|
setMediaStatus(id);
|
||||||
|
if(pc.iceConnectionState === 'failed') {
|
||||||
|
send({type: 'renegotiate',
|
||||||
|
id: id,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
c.pc.ontrack = function(e) {
|
c.pc.ontrack = function(e) {
|
||||||
|
@ -1179,7 +1195,7 @@ async function newUpStream(id) {
|
||||||
|
|
||||||
pc.onnegotiationneeded = async e => {
|
pc.onnegotiationneeded = async e => {
|
||||||
try {
|
try {
|
||||||
await negotiate(id);
|
await negotiate(id, false);
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
displayError(e);
|
displayError(e);
|
||||||
|
@ -1213,7 +1229,7 @@ async function newUpStream(id) {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function negotiate(id) {
|
async function negotiate(id, restartIce) {
|
||||||
let c = up[id];
|
let c = up[id];
|
||||||
if(!c)
|
if(!c)
|
||||||
throw new Error('unknown connection');
|
throw new Error('unknown connection');
|
||||||
|
@ -1221,7 +1237,7 @@ async function negotiate(id) {
|
||||||
if(typeof(c.pc.getTransceivers) !== 'function')
|
if(typeof(c.pc.getTransceivers) !== 'function')
|
||||||
throw new Error('Browser too old, please upgrade');
|
throw new Error('Browser too old, please upgrade');
|
||||||
|
|
||||||
let offer = await c.pc.createOffer({});
|
let offer = await c.pc.createOffer({iceRestart: restartIce});
|
||||||
if(!offer)
|
if(!offer)
|
||||||
throw(new Error("Didn't create offer"));
|
throw(new Error("Didn't create offer"));
|
||||||
await c.pc.setLocalDescription(offer);
|
await c.pc.setLocalDescription(offer);
|
||||||
|
|
36
webclient.go
36
webclient.go
|
@ -236,6 +236,12 @@ func addUpConn(c *webClient, id string) (*rtpUpConnection, bool, error) {
|
||||||
sendICE(c, id, candidate)
|
sendICE(c, id, candidate)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
conn.pc.OnICEConnectionStateChange(func(state webrtc.ICEConnectionState) {
|
||||||
|
if state == webrtc.ICEConnectionStateFailed {
|
||||||
|
c.action(connectionFailedAction{id: id})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
return conn, true, nil
|
return conn, true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -772,14 +778,11 @@ func clientLoop(c *webClient, conn *websocket.Conn) error {
|
||||||
go a.c.pushConn(u.id, u, ts, u.label)
|
go a.c.pushConn(u.id, u, ts, u.label)
|
||||||
}
|
}
|
||||||
case connectionFailedAction:
|
case connectionFailedAction:
|
||||||
down := getDownConn(c, a.id)
|
if down := getDownConn(c, a.id); down != nil {
|
||||||
if down == nil {
|
|
||||||
log.Printf("Failed indication for " +
|
|
||||||
"unknown connection")
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
err := negotiate(c, down, true, true)
|
err := negotiate(c, down, true, true)
|
||||||
if err != nil {
|
if err == nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
tracks := make(
|
tracks := make(
|
||||||
[]upTrack, len(down.tracks),
|
[]upTrack, len(down.tracks),
|
||||||
)
|
)
|
||||||
|
@ -790,7 +793,16 @@ func clientLoop(c *webClient, conn *websocket.Conn) error {
|
||||||
down.remote.Id(), down.remote,
|
down.remote.Id(), down.remote,
|
||||||
tracks, down.remote.Label(),
|
tracks, down.remote.Label(),
|
||||||
)
|
)
|
||||||
|
} else if up := getUpConn(c, a.id); up != nil {
|
||||||
|
c.write(clientMessage{
|
||||||
|
Type: "renegotiate",
|
||||||
|
Id: a.id,
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
log.Printf("Attempting to renegotiate " +
|
||||||
|
"unknown connection")
|
||||||
}
|
}
|
||||||
|
|
||||||
case permissionsChangedAction:
|
case permissionsChangedAction:
|
||||||
c.write(clientMessage{
|
c.write(clientMessage{
|
||||||
Type: "permissions",
|
Type: "permissions",
|
||||||
|
@ -930,6 +942,16 @@ func handleClientMessage(c *webClient, m clientMessage) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
case "renegotiate":
|
||||||
|
down := getDownConn(c, m.Id)
|
||||||
|
if down != nil {
|
||||||
|
err := negotiate(c, down, true, true)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log.Printf("Trying to renegotiate unknown connection")
|
||||||
|
}
|
||||||
case "close":
|
case "close":
|
||||||
found := delUpConn(c, m.Id)
|
found := delUpConn(c, m.Id)
|
||||||
if !found {
|
if !found {
|
||||||
|
|
Loading…
Reference in a new issue