Skip to content

Commit e41f992

Browse files
committed
various fixes
1 parent 22a2d13 commit e41f992

File tree

1 file changed

+45
-36
lines changed

1 file changed

+45
-36
lines changed

src/webpage/voice.ts

Lines changed: 45 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ class Voice {
223223
(!this.users.has(json.d.audio_ssrc) && json.d.audio_ssrc !== 0) ||
224224
(!this.vidusers.has(json.d.video_ssrc) && json.d.video_ssrc !== 0)
225225
) {
226+
this.sendtosend12 = false;
226227
console.log("redo 12!");
227228
this.makeOp12();
228229
}
@@ -435,6 +436,7 @@ a=rtcp-mux\r`;
435436
async makeOp12(
436437
sender: RTCRtpSender | undefined | [RTCRtpSender, number] = this.ssrcMap.entries().next().value,
437438
) {
439+
if (!this.ws) return;
438440
if (!sender) throw new Error("sender doesn't exist");
439441
if (sender instanceof Array) {
440442
sender = sender[0];
@@ -460,33 +462,32 @@ a=rtcp-mux\r`;
460462
//width = settings.width || 0;
461463
//height = settings.height || 0;
462464
}
463-
if (this.ws) {
464-
console.log(this.ssrcMap);
465-
this.ws.send(
466-
JSON.stringify({
467-
op: 12,
468-
d: {
469-
audio_ssrc: this.ssrcMap.get(sender),
470-
video_ssrc,
471-
rtx_ssrc,
472-
streams: [
473-
{
474-
type: "video",
475-
rid: "100",
476-
ssrc: video_ssrc,
477-
active: !!video_ssrc,
478-
quality: 100,
479-
rtx_ssrc: rtx_ssrc,
480-
max_bitrate: 2500000, //TODO
481-
max_framerate, //TODO
482-
max_resolution: {type: "fixed", width, height},
483-
},
484-
],
485-
},
486-
}),
487-
);
488-
this.status = "Sending audio streams";
489-
}
465+
466+
console.log(this.ssrcMap);
467+
this.ws.send(
468+
JSON.stringify({
469+
op: 12,
470+
d: {
471+
audio_ssrc: this.ssrcMap.get(sender),
472+
video_ssrc,
473+
rtx_ssrc,
474+
streams: [
475+
{
476+
type: "video",
477+
rid: "100",
478+
ssrc: video_ssrc,
479+
active: !!video_ssrc,
480+
quality: 100,
481+
rtx_ssrc: rtx_ssrc,
482+
max_bitrate: 2500000, //TODO
483+
max_framerate, //TODO
484+
max_resolution: {type: "fixed", width, height},
485+
},
486+
],
487+
},
488+
}),
489+
);
490+
this.status = "Sending audio streams";
490491
}
491492
senders: Set<RTCRtpSender> = new Set();
492493
recivers = new Set<RTCRtpReceiver>();
@@ -586,21 +587,25 @@ a=rtcp-mux\r`;
586587
this.owner.video = false;
587588
if (!this.cammera) return;
588589
this.cammera.stop();
590+
this.cammera = undefined;
591+
589592
this.cam.sender.replaceTrack(null);
593+
this.cam.direction = "inactive";
594+
595+
this.pc?.setLocalDescription();
590596

591597
this.owner.updateSelf();
592-
this.cammera = undefined;
593598

594599
this.videos.delete(this.userid);
595600
this.onUserChange(this.userid, {
596601
deaf: false,
597602
muted: this.owner.mute,
598603
video: false,
599604
});
600-
601-
this.makeOp12();
602605
}
606+
videoStarted = false;
603607
async startVideo(caml: MediaStream) {
608+
console.warn("test test test test video sent!");
604609
if (!this.cam) return;
605610
const tracks = caml.getVideoTracks();
606611
const [cam] = tracks;
@@ -614,10 +619,10 @@ a=rtcp-mux\r`;
614619
this.videos.set(this.userid, video);
615620
video.srcObject = caml;
616621
video.autoplay = true;
617-
await this.cam.sender.replaceTrack(cam);
618-
619-
//await this.pc?.setLocalDescription();
620-
await this.makeOp12();
622+
this.cam.direction = "sendonly";
623+
const sender = this.cam.sender;
624+
await sender.replaceTrack(cam);
625+
this.pc?.setLocalDescription();
621626

622627
this.owner.updateSelf();
623628
}
@@ -819,6 +824,7 @@ a=rtcp-mux\r`;
819824
}),
820825
);
821826
}
827+
console.warn("done with this!");
822828
}
823829
static parsesdp(sdp: string) {
824830
let currentA = new Map<string, Set<string>>();
@@ -877,8 +883,11 @@ a=rtcp-mux\r`;
877883
const vals = {deaf: update.deaf, muted: update.mute, video: update.self_video};
878884
this.onUserChange(update.user_id, vals);
879885
this.userids.set(update.user_id, vals);
880-
881-
if (update.user_id === this.userid && this.open && !(this.status === "Done")) {
886+
if (update.user_id === this.userid && this.videoStarted !== update.self_video) {
887+
this.makeOp12();
888+
this.videoStarted = update.self_video;
889+
}
890+
if (update.user_id === this.userid && this.open && !this.ws) {
882891
if (!update) {
883892
this.status = "bad responce from WS";
884893
return;

0 commit comments

Comments
 (0)