From 4d57f2dc4979177f9d074157b0d0767327d5fd67 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Mon, 3 Oct 2022 12:45:24 +0200 Subject: first code for file transfer --- client-web/source/user/remote.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'client-web/source/user/remote.ts') diff --git a/client-web/source/user/remote.ts b/client-web/source/user/remote.ts index 677d362..e143625 100644 --- a/client-web/source/user/remote.ts +++ b/client-web/source/user/remote.ts @@ -45,10 +45,19 @@ export class RemoteUser extends User { r.on_enable(new TrackHandle(t), () => { this.request_resource_stop(r) }) - // else { ev.transceiver.stop(); return log({ scope: "media", warn: true }, "got a track for a resource that should use data channel") } log("media", `remote track: ${this.display_name}`, t) this.update_stats() } + this.pc.ondatachannel = ({ channel }) => { + const id = channel.label + const r = this.resources.get(id) + if (!r) { channel.close(); return log({ scope: "media", warn: true }, "got an unassociated channel") } + r.on_enable(channel, () => { + this.request_resource_stop(r) + }) + log("media", `remote channel: ${this.display_name}`, channel) + this.update_stats() + } this.pc.onnegotiationneeded = () => { log("webrtc", `negotiation needed: ${this.display_name}`) if (this.negotiation_busy && this.pc.signalingState == "stable") return @@ -97,7 +106,7 @@ export class RemoteUser extends User { if (message.request) { const r = this.room.local_user.resources.get(message.request.id) if (!r) return log({ scope: "*", warn: true }, "somebody requested an unknown resource") - const channel = r.on_request(this, label => this.pc.createDataChannel(label)) + const channel = r.on_request(this, () => this.pc.createDataChannel(r.info.id)) if (channel instanceof TrackHandle) { const sender = this.pc.addTrack(channel.track, channel.stream) this.senders.set(channel.id, sender) -- cgit v1.2.3-70-g09d2