Skip to content

Commit

Permalink
Improving handling of closed sessions, fixes #227
Browse files Browse the repository at this point in the history
  • Loading branch information
daonb committed Jul 8, 2022
1 parent fa08795 commit 1e6e310
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
4 changes: 4 additions & 0 deletions src/gate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,10 @@ export class Gate {
* state changes.
*/
onSessionState(state: RTState, failure: Failure) {
if (!this.session) {
this.t7.log(`Ignoring ${this.name} change state to ${state} as session is closed`)
return
}
this.t7.log(`updating ${this.name} state to ${state}`)
if (state == "connected") {
this.notify("Connected")
Expand Down
13 changes: 9 additions & 4 deletions src/terminal7.js
Original file line number Diff line number Diff line change
Expand Up @@ -967,6 +967,15 @@ peer_name = "${peername}"\n`
this.log("received bad gate", m)
return
}
if (m.peer_update !== undefined) {
g.online = m.peer_update.online
return
}
// next to are for connected session, ignore if no session
if (!g.session) {
console.log("session is close ignoring message", m)
return
}
if (m.candidate !== undefined) {
g.session.peerCandidate(m.candidate)
return
Expand All @@ -976,10 +985,6 @@ peer_name = "${peername}"\n`
g.session.peerAnswer(answer)
return
}
if (m.peer_update !== undefined) {
g.online = m.peer_update.online
return
}
}
log (...args) {
var line = ""
Expand Down
8 changes: 4 additions & 4 deletions src/webrtc_session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ abstract class WebRTCSession extends BaseSession {
try {
this.t7.iceServers = await this.getIceServers()
} catch(e) {
console.log("Faield to get ice servers", e.toString())
this.t7.iceServers = []
console.log(e)
}
}
console.log("got ice server", this.t7.iceServers)
Expand Down Expand Up @@ -339,7 +340,7 @@ export class PeerbookSession extends WebRTCSession {
getIceServers() {
return new Promise((resolve, reject) => {
const ctrl = new AbortController(),
tId = setTimeout(() => ctrl.abort(), TIMEOUT),
tId = setTimeout(() => ctrl.abort(), 1000),
insecure = this.t7.conf.peerbook.insecure,
schema = insecure?"http":"https"

Expand All @@ -358,9 +359,8 @@ export class PeerbookSession extends WebRTCSession {
...answer["ice_servers"]])

}).catch(err => {
console.log("failed to get ice servers " + err.toString())
clearTimeout(tId)
reject()
reject("failed to get ice servers " + err.toString())
})
})
}
Expand Down

0 comments on commit 1e6e310

Please sign in to comment.