summaryrefslogtreecommitdiff
path: root/source/client/remote_user.ts
diff options
context:
space:
mode:
Diffstat (limited to 'source/client/remote_user.ts')
-rw-r--r--source/client/remote_user.ts26
1 files changed, 20 insertions, 6 deletions
diff --git a/source/client/remote_user.ts b/source/client/remote_user.ts
index f859dd9..c7a9249 100644
--- a/source/client/remote_user.ts
+++ b/source/client/remote_user.ts
@@ -6,6 +6,7 @@ import { User } from "./user"
export class RemoteUser extends User {
peer: RTCPeerConnection
+ negotiation_busy: boolean = false
constructor(room: Room, name: string) {
super(room, name)
@@ -16,16 +17,26 @@ export class RemoteUser extends User {
}
this.peer.ontrack = ev => {
log("media", "remote track", ev.streams)
- if (!ev.streams.length) return console.warn("no remote tracks")
- ev.streams.forEach(s => s.getTracks().forEach(t => {
- if (this.stream.find(u => u.id == t.id)) return
- this.stream.push(t)
- this.update_view()
- }))
+ console.log(ev.track);
+ this.stream.addTrack(ev.track)
+ // if (!ev.streams.length) return console.warn("no remote tracks")
+ // ev.streams.forEach(s => s.getTracks().forEach(t => {
+ // this.stream.addTrack(t)
+ // }))
+ this.update_view()
+ }
+ this.peer.onnegotiationneeded = async () => {
+ log("webrtc", "negotiation needed")
+ while (this.negotiation_busy) {
+ await new Promise<void>(r => setTimeout(() => r(), 100))
+ }
+ this.offer()
}
}
+
async offer() {
+ this.negotiation_busy = true
const offer_description = await this.peer.createOffer()
await this.peer.setLocalDescription(offer_description)
const offer = { type: offer_description.type, sdp: offer_description.sdp }
@@ -33,6 +44,7 @@ export class RemoteUser extends User {
this.room.websocket_send({ receiver: this.name, offer })
}
async on_offer(offer: RTCSessionDescriptionInit) {
+ this.negotiation_busy = true
log("webrtc", "got offer", offer)
const offer_description = new RTCSessionDescription(offer)
await this.peer.setRemoteDescription(offer_description)
@@ -44,11 +56,13 @@ export class RemoteUser extends User {
const answer = { type: answer_description.type, sdp: answer_description.sdp }
log("webrtc", "sent answer", answer)
this.room.websocket_send({ receiver: this.name, answer })
+ this.negotiation_busy = false
}
async on_answer(answer: RTCSessionDescriptionInit) {
log("webrtc", "got answer", answer)
const answer_description = new RTCSessionDescription(answer)
await this.peer.setRemoteDescription(answer_description)
+ this.negotiation_busy = false
}
add_ice_candidate(candidate: RTCIceCandidateInit) {