diff options
Diffstat (limited to 'client-web')
-rw-r--r-- | client-web/source/room.ts | 1 | ||||
-rw-r--r-- | client-web/source/user/remote.ts | 25 |
2 files changed, 14 insertions, 12 deletions
diff --git a/client-web/source/room.ts b/client-web/source/room.ts index 207b40d..1fa8f86 100644 --- a/client-web/source/room.ts +++ b/client-web/source/room.ts @@ -40,7 +40,6 @@ export class Room { const ru = new RemoteUser(this, p.id) this.local_user.add_initial_to_remote(ru) this.local_user.identify(ru.id) - ru.offer() } } else if (packet.client_leave) { log("ws", `<- [client leave]: `, packet); diff --git a/client-web/source/user/remote.ts b/client-web/source/user/remote.ts index 07d8cf5..bee3042 100644 --- a/client-web/source/user/remote.ts +++ b/client-web/source/user/remote.ts @@ -21,38 +21,41 @@ export class RemoteUser extends User { this.peer = new RTCPeerConnection(RTC_CONFIG) this.peer.onicecandidate = ev => { if (!ev.candidate) return - this.update_stats() - log("webrtc", `ICE candidate set`, ev.candidate) room.signaling.send_relay({ ice_candidate: ev.candidate.toJSON() }, this.id) + log("webrtc", `ICE candidate set`, ev.candidate) + this.update_stats() } this.peer.ontrack = ev => { const t = ev.track - this.update_stats() log("media", `remote track: ${this.display_name}`, t) this.add_track(new TrackHandle(t)) + this.update_stats() } - this.peer.onnegotiationneeded = async () => { + this.peer.onnegotiationneeded = () => { log("webrtc", `negotiation needed: ${this.display_name}`) - this.update_stats() - while (this.negotiation_busy) { - await new Promise<void>(r => setTimeout(() => r(), 100)) - } + if (this.negotiation_busy && this.peer.signalingState == "stable") return this.offer() + this.update_stats() } this.peer.onicecandidateerror = () => { + console.log("onicecandidateerror") log({ scope: "webrtc", warn: true }, "ICE error") this.update_stats() } this.peer.oniceconnectionstatechange = () => { + console.log("oniceconnectionstatechange") this.update_stats() } this.peer.onicegatheringstatechange = () => { + console.log("onicegatheringstatechange") this.update_stats() } this.peer.onsignalingstatechange = () => { + console.log("onsignalingstatechange") this.update_stats() } this.peer.onconnectionstatechange = () => { + console.log("onconnectionstatechange") this.update_stats() } this.update_stats() @@ -82,15 +85,15 @@ export class RemoteUser extends User { try { const stats = await this.peer.getStats() let stuff = ""; - stuff += `ice-conn=${this.peer.iceConnectionState}; ice-gathering=${this.peer.iceGatheringState}; signaling=${this.peer.signalingState}\n` + stuff += `ice-conn=${this.peer.iceConnectionState}; ice-gathering=${this.peer.iceGatheringState}; ice-trickle=${this.peer.canTrickleIceCandidates}; signaling=${this.peer.signalingState};\n` stats.forEach(s => { console.log("stat", s); if (s.type == "candidate-pair" && s.selected) { //@ts-ignore spec is weird.... - if (!stats.get) return + if (!stats.get) return console.warn("no RTCStatsReport.get"); //@ts-ignore spec is weird.... const cpstat = stats.get(s.localCandidateId) - if (!cpstat) return + if (!cpstat) return console.warn("no stats"); console.log("cp", cpstat); stuff += `via ${cpstat.candidateType}:${cpstat.protocol}:${cpstat.address}\n` } else if (s.type == "codec") { |