Peer structure & WebRTC structure
This commit is contained in:
parent
7dd4797f00
commit
bbd2ff8057
|
@ -7,6 +7,12 @@ interface IPeerOptions{
|
|||
|
||||
};
|
||||
|
||||
enum IMessageSymbase
|
||||
{
|
||||
PayloadMessagePack = -12873.54,
|
||||
PayloadRTCBasePack = -12884.54
|
||||
}
|
||||
|
||||
|
||||
export default class Peer extends EventTarget
|
||||
{
|
||||
|
@ -23,10 +29,30 @@ export default class Peer extends EventTarget
|
|||
super();
|
||||
this.mwse = wsts;
|
||||
this.info = new PeerInfo(this);
|
||||
|
||||
this.on('pack',(data:{type?:string,action?:IMessageSymbase,payload?:any}) => {
|
||||
if(data.type == 'rtc')
|
||||
{
|
||||
if(data.action == IMessageSymbase.PayloadRTCBasePack)
|
||||
{
|
||||
if(this.rtc)
|
||||
{
|
||||
return this.rtc.emit("input", data.payload)
|
||||
}
|
||||
console.warn("Not active rtc but recaived rtc packs")
|
||||
};
|
||||
if(data.action == IMessageSymbase.PayloadMessagePack)
|
||||
{
|
||||
return this.emit("message", data.payload)
|
||||
}
|
||||
};
|
||||
this.emit("message", data);
|
||||
});
|
||||
}
|
||||
public createRTC() : WebRTC
|
||||
{
|
||||
this.rtc = new WebRTC();
|
||||
this.rtc.peer = this;
|
||||
this.rtc.on("connected", () => {
|
||||
this.peerConnection = true;
|
||||
});
|
||||
|
@ -35,22 +61,11 @@ export default class Peer extends EventTarget
|
|||
})
|
||||
this.rtc.on("output",(payload:object) => {
|
||||
this.send({
|
||||
type: 'rtc:session',
|
||||
type: 'rtc',
|
||||
action: IMessageSymbase.PayloadRTCBasePack,
|
||||
payload: payload
|
||||
})
|
||||
});
|
||||
this.on('message',(data:{type?:string,payload?:any}) => {
|
||||
if(data.type == 'rtc:session')
|
||||
{
|
||||
if(this.rtc)
|
||||
{
|
||||
this.rtc.emit("input", data.payload)
|
||||
}
|
||||
}else if(data.type == 'rtc:message')
|
||||
{
|
||||
this.emit("message", data.payload)
|
||||
}
|
||||
});
|
||||
return this.rtc;
|
||||
}
|
||||
public setPeerOptions(options: string | IPeerOptions){
|
||||
|
@ -137,7 +152,8 @@ export default class Peer extends EventTarget
|
|||
});
|
||||
}else{
|
||||
this.rtc?.send({
|
||||
type: 'rtc:message',
|
||||
type: 'rtc',
|
||||
action: IMessageSymbase.PayloadMessagePack,
|
||||
payload: pack
|
||||
})
|
||||
}
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import Peer from "./Peer";
|
||||
|
||||
interface TransferStreamInfo
|
||||
{
|
||||
senders : RTCRtpSender[];
|
||||
|
@ -22,6 +24,8 @@ export default class WebRTC
|
|||
public events : { [eventname:string]: Function[] } = {};
|
||||
public channel : RTCDataChannel | undefined;
|
||||
|
||||
public peer? : Peer;
|
||||
|
||||
public WebRTC()
|
||||
{
|
||||
this.rtc = new RTCPeerConnection({
|
||||
|
@ -337,7 +341,7 @@ export default class WebRTC
|
|||
if(this.connectionStatus != 'connected'){
|
||||
return
|
||||
}
|
||||
for (const [id, {stream}] of this.sendingStream) {
|
||||
for (const [, {stream}] of this.sendingStream) {
|
||||
if(stream == undefined)
|
||||
{
|
||||
continue;
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue