more fixes

This commit is contained in:
MathMan05 2024-10-09 19:32:38 -05:00
parent 68fb667615
commit 9c7daf8078
3 changed files with 88 additions and 68 deletions

View file

@ -483,33 +483,33 @@ type memberChunk = {
not_found: string[]; not_found: string[];
}; };
type voiceupdate={ type voiceupdate={
op: 0, op: 0,
t: "VOICE_STATE_UPDATE", t: "VOICE_STATE_UPDATE",
d: { d: {
guild_id: string, guild_id: string,
channel_id: string, channel_id: string,
user_id: string, user_id: string,
member: memberjson, member: memberjson,
session_id: string, session_id: string,
token: string, token: string,
deaf: boolean, deaf: boolean,
mute: boolean, mute: boolean,
self_deaf: boolean, self_deaf: boolean,
self_mute: boolean, self_mute: boolean,
self_video: boolean, self_video: boolean,
suppress: boolean suppress: boolean
}, },
s: number s: number
}; };
type voiceserverupdate={ type voiceserverupdate={
op: 0, op: 0,
t: "VOICE_SERVER_UPDATE", t: "VOICE_SERVER_UPDATE",
d: { d: {
token: string, token: string,
guild_id: string, guild_id: string,
endpoint: string endpoint: string
}, },
s: 6 s: 6
}; };
type memberlistupdatejson={ type memberlistupdatejson={
op: 0, op: 0,
@ -541,7 +541,7 @@ type memberlistupdatejson={
count: number, count: number,
id: string id: string
}[] }[]
} }
} }
type webRTCSocket= { type webRTCSocket= {
op: 8, op: 8,
@ -552,21 +552,21 @@ type webRTCSocket= {
op:6, op:6,
d:{t: number} d:{t: number}
}|{ }|{
op: 2, op: 2,
d: { d: {
ssrc: number, ssrc: number,
"streams": { "streams": {
type: "video",//probally more options, but idk type: "video",//probally more options, but idk
rid: string, rid: string,
quality: number, quality: number,
ssrc: number, ssrc: number,
rtx_ssrc:number rtx_ssrc:number
}[], }[],
ip: number, ip: number,
port: number, port: number,
"modes": [],//no clue "modes": [],//no clue
"experiments": []//no clue "experiments": []//no clue
} }
}|sdpback|opRTC12; }|sdpback|opRTC12;
type sdpback={ type sdpback={
op: 4, op: 4,
@ -578,29 +578,29 @@ type sdpback={
} }
}; };
type opRTC12={ type opRTC12={
op: 12, op: 12,
d: { d: {
user_id: string, user_id: string,
audio_ssrc: number, audio_ssrc: number,
video_ssrc: number, video_ssrc: number,
streams: [ streams: [
{ {
type: "video", type: "video",
rid: "100", rid: "100",
ssrc: number, ssrc: number,
active: boolean, active: boolean,
quality: 100, quality: 100,
rtx_ssrc: number, rtx_ssrc: number,
max_bitrate: 2500000, max_bitrate: 2500000,
max_framerate: number, max_framerate: number,
max_resolution: { max_resolution: {
type: "fixed", type: "fixed",
width: number, width: number,
height: number height: number
} }
} }
] ]
} }
} }
export{ export{
readyjson, readyjson,

View file

@ -507,6 +507,9 @@ class Localuser{
waitingForVoice?:((arg:voiceupdate|undefined)=>void); waitingForVoice?:((arg:voiceupdate|undefined)=>void);
currentVoice?:Voice; currentVoice?:Voice;
async joinVoice(voice:Voice){ async joinVoice(voice:Voice){
if(this.currentVoice){
this.currentVoice.leave();
}
this.currentVoice=voice; this.currentVoice=voice;
if(this.ws){ if(this.ws){
this.ws.send(JSON.stringify({ this.ws.send(JSON.stringify({

View file

@ -62,6 +62,10 @@ class Voice{
setTimeout(this.sendAlive.bind(this), 1000); setTimeout(this.sendAlive.bind(this), 1000);
break; break;
case 12: case 12:
if(!this.users.has(json.d.audio_ssrc)){
console.log("redo 12!");
this.makeOp12();
}
this.users.set(json.d.audio_ssrc,json.d.user_id); this.users.set(json.d.audio_ssrc,json.d.user_id);
break break
@ -176,8 +180,6 @@ a=rtcp-mux\r`;
})).sdp; })).sdp;
await pc.setLocalDescription({sdp:this.offer}); await pc.setLocalDescription({sdp:this.offer});
if(!this.counter) throw new Error("counter isn't defined"); if(!this.counter) throw new Error("counter isn't defined");
const counter=this.counter; const counter=this.counter;
const remote:{sdp:string,type:RTCSdpType}={sdp:this.cleanServerSDP(counter),type:"answer"}; const remote:{sdp:string,type:RTCSdpType}={sdp:this.cleanServerSDP(counter),type:"answer"};
@ -188,7 +190,7 @@ a=rtcp-mux\r`;
for(const thing of (await sender.getStats())){ for(const thing of (await sender.getStats())){
if(thing[1].ssrc){ if(thing[1].ssrc){
this.ssrcMap.set(sender,thing[1].ssrc); this.ssrcMap.set(sender,thing[1].ssrc);
this.makeOp12(sender) this.makeOp12(sender);
} }
} }
} }
@ -196,7 +198,11 @@ a=rtcp-mux\r`;
}); });
} }
} }
async makeOp12(sender:RTCRtpSender){ async makeOp12(sender:RTCRtpSender|undefined|[RTCRtpSender,string]=(this.ssrcMap.entries().next().value)){
if(!sender) throw new Error("sender doesn't exist");
if(sender instanceof Array){
sender=sender[0];
}
if(this.ws){ if(this.ws){
this.ws.send(JSON.stringify({ this.ws.send(JSON.stringify({
op: 12, op: 12,
@ -480,5 +486,16 @@ a=rtcp-mux\r`;
//pc.setRemoteDescription({sdp:json.d.token,type:""}) //pc.setRemoteDescription({sdp:json.d.token,type:""})
*/ */
} }
async leave(){
this.status="Left voice chat";
if(this.ws){
this.ws.close();
this.ws=undefined;
}
if(this.pc){
this.pc.close();
this.pc=undefined;
}
}
} }
export {Voice}; export {Voice};