Test added perfect nogation
This commit is contained in:
parent
965ca07853
commit
055fdd47bd
|
@ -4,8 +4,7 @@ export interface IConnection{
|
||||||
endpoint: string;
|
endpoint: string;
|
||||||
autoReconnect?: boolean | {
|
autoReconnect?: boolean | {
|
||||||
timeout: number;
|
timeout: number;
|
||||||
},
|
}
|
||||||
autoCreateRTC: boolean
|
|
||||||
}
|
}
|
||||||
export class Connection
|
export class Connection
|
||||||
{
|
{
|
||||||
|
@ -36,9 +35,6 @@ export class Connection
|
||||||
throw new Error("endpoint is required")
|
throw new Error("endpoint is required")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(options.autoCreateRTC === false){
|
|
||||||
mwse.autoCreateRTC = false;
|
|
||||||
}
|
|
||||||
if(typeof options.autoReconnect == "boolean")
|
if(typeof options.autoReconnect == "boolean")
|
||||||
{
|
{
|
||||||
this.autoReconnect = true;
|
this.autoReconnect = true;
|
||||||
|
|
|
@ -22,26 +22,18 @@ export default class Peer extends EventTarget
|
||||||
public selfSocket : boolean = false;
|
public selfSocket : boolean = false;
|
||||||
public active : boolean = false;
|
public active : boolean = false;
|
||||||
public info : PeerInfo;
|
public info : PeerInfo;
|
||||||
public rtc? : WebRTC;
|
public rtc : WebRTC;
|
||||||
public peerConnection : boolean = false;
|
public peerConnection : boolean = false;
|
||||||
public primaryChannel : "websocket" | "datachannel" = "datachannel";
|
public primaryChannel : "websocket" | "datachannel" = "datachannel";
|
||||||
constructor(wsts:MWSE){
|
constructor(wsts:MWSE){
|
||||||
super();
|
super();
|
||||||
this.mwse = wsts;
|
this.mwse = wsts;
|
||||||
|
this.rtc = this.createRTC();
|
||||||
this.info = new PeerInfo(this);
|
this.info = new PeerInfo(this);
|
||||||
this.on('pack',(data:{type?:string,action?:IMessageSymbase,payload?:any}) => {
|
this.on('pack',(data:{type?:string,action?:IMessageSymbase,payload?:any}) => {
|
||||||
if(data.type == ':rtcpack:')
|
if(data.type == ':rtcpack:')
|
||||||
{
|
|
||||||
if(this.rtc)
|
|
||||||
{
|
{
|
||||||
return this.rtc.emit("input", data.payload)
|
return this.rtc.emit("input", data.payload)
|
||||||
}else{
|
|
||||||
if(this.mwse.autoCreateRTC)
|
|
||||||
{
|
|
||||||
this.createRTC().emit("input", data.payload);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return console.warn("Not active rtc but recaived rtc packs")
|
|
||||||
};
|
};
|
||||||
this.emit("message", data);
|
this.emit("message", data);
|
||||||
});
|
});
|
||||||
|
|
|
@ -59,6 +59,8 @@ export default class WebRTC
|
||||||
public ignoreOffer = false;
|
public ignoreOffer = false;
|
||||||
public isSettingRemoteAnswerPending = false;
|
public isSettingRemoteAnswerPending = false;
|
||||||
|
|
||||||
|
candicatePack : RTCIceCandidate[] = [];
|
||||||
|
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
rtcConfig?: RTCConfiguration,
|
rtcConfig?: RTCConfiguration,
|
||||||
|
@ -112,7 +114,17 @@ export default class WebRTC
|
||||||
switch(data.type)
|
switch(data.type)
|
||||||
{
|
{
|
||||||
case "icecandidate":{
|
case "icecandidate":{
|
||||||
|
try{
|
||||||
|
if(this.rtc.remoteDescription){
|
||||||
await this.rtc.addIceCandidate(new RTCIceCandidate(data.value));
|
await this.rtc.addIceCandidate(new RTCIceCandidate(data.value));
|
||||||
|
}else{
|
||||||
|
this.candicatePack.push(new RTCIceCandidate(data.value))
|
||||||
|
}
|
||||||
|
}catch(error){
|
||||||
|
debugger;
|
||||||
|
}finally{
|
||||||
|
console.log("ICE Canbet")
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "offer":{
|
case "offer":{
|
||||||
|
@ -132,6 +144,9 @@ export default class WebRTC
|
||||||
|
|
||||||
this.isSettingRemoteAnswerPending = false;
|
this.isSettingRemoteAnswerPending = false;
|
||||||
|
|
||||||
|
for (const candidate of this.candicatePack) {
|
||||||
|
await this.rtc.addIceCandidate(candidate);
|
||||||
|
}
|
||||||
|
|
||||||
let answer = await this.rtc.createAnswer({
|
let answer = await this.rtc.createAnswer({
|
||||||
offerToReceiveAudio: true,
|
offerToReceiveAudio: true,
|
||||||
|
@ -145,19 +160,11 @@ export default class WebRTC
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "answer":{
|
case "answer":{
|
||||||
|
|
||||||
let readyForOffer = !this.makingOffer && (this.rtc.signalingState == "stable" || this.isSettingRemoteAnswerPending);
|
|
||||||
|
|
||||||
const offerCollision = !readyForOffer;
|
|
||||||
|
|
||||||
this.ignoreOffer = !this.isPolite() && offerCollision;
|
|
||||||
|
|
||||||
if(this.ignoreOffer){
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.isSettingRemoteAnswerPending = true;
|
|
||||||
await this.rtc.setRemoteDescription(new RTCSessionDescription(data.value))
|
await this.rtc.setRemoteDescription(new RTCSessionDescription(data.value))
|
||||||
this.isSettingRemoteAnswerPending = false;
|
|
||||||
|
for (const candidate of this.candicatePack) {
|
||||||
|
await this.rtc.addIceCandidate(candidate);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "streamInfo":{
|
case "streamInfo":{
|
||||||
|
|
|
@ -17,7 +17,6 @@ export default class MWSE extends EventTarget {
|
||||||
public peers : Map<string, Peer> = new Map();
|
public peers : Map<string, Peer> = new Map();
|
||||||
public virtualPressure : IPPressure;
|
public virtualPressure : IPPressure;
|
||||||
public me! : Peer;
|
public me! : Peer;
|
||||||
public autoCreateRTC : boolean = true;
|
|
||||||
/*public static compress(message:string, callback:(e:any) => any)
|
/*public static compress(message:string, callback:(e:any) => any)
|
||||||
{
|
{
|
||||||
let u : any= [];
|
let u : any= [];
|
||||||
|
@ -35,6 +34,7 @@ export default class MWSE extends EventTarget {
|
||||||
}*/
|
}*/
|
||||||
constructor(options: IConnection){
|
constructor(options: IConnection){
|
||||||
super();
|
super();
|
||||||
|
MWSE.rtc = MWSE as unknown as WebRTC;
|
||||||
this.server = new Connection(this,options);
|
this.server = new Connection(this,options);
|
||||||
this.WSTSProtocol = new WSTSProtocol(this);
|
this.WSTSProtocol = new WSTSProtocol(this);
|
||||||
this.EventPooling = new EventPool(this);
|
this.EventPooling = new EventPool(this);
|
||||||
|
|
|
@ -6,14 +6,6 @@ let mwse;
|
||||||
* @type {string}
|
* @type {string}
|
||||||
*/
|
*/
|
||||||
let mySocketId;
|
let mySocketId;
|
||||||
/**
|
|
||||||
* @type {string}
|
|
||||||
*/
|
|
||||||
let myIPAddress;
|
|
||||||
/**
|
|
||||||
* @type {string}
|
|
||||||
*/
|
|
||||||
let myNumber;
|
|
||||||
/**
|
/**
|
||||||
* @type {string}
|
* @type {string}
|
||||||
*/
|
*/
|
||||||
|
@ -42,6 +34,14 @@ function connect()
|
||||||
endpoint: "wss://ws.saqut.com"
|
endpoint: "wss://ws.saqut.com"
|
||||||
});
|
});
|
||||||
|
|
||||||
|
MWSE.rtc.defaultICEServers = [{
|
||||||
|
urls: "turn:20.166.82.187:3478",
|
||||||
|
username: "turnserver",
|
||||||
|
credential: "turnserver"
|
||||||
|
},{
|
||||||
|
urls: "stun:stun.l.google.com:19302"
|
||||||
|
}];
|
||||||
|
|
||||||
mwse.scope(beginEngine);
|
mwse.scope(beginEngine);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,8 +124,6 @@ async function beginEngine()
|
||||||
let me = mwse.peer("me");
|
let me = mwse.peer("me");
|
||||||
me.disablePairAuth();
|
me.disablePairAuth();
|
||||||
mySocketId = me.socketId;
|
mySocketId = me.socketId;
|
||||||
myIPAddress = await mwse.virtualPressure.allocAPIPAddress();
|
|
||||||
myNumber = await mwse.virtualPressure.allocAPNumber();
|
|
||||||
|
|
||||||
let url = new URL(window.location);
|
let url = new URL(window.location);
|
||||||
roomid = url.searchParams.get("room");
|
roomid = url.searchParams.get("room");
|
||||||
|
@ -203,11 +201,13 @@ async function connectRoom()
|
||||||
});
|
});
|
||||||
await room.createRoom();
|
await room.createRoom();
|
||||||
|
|
||||||
room.on("join", peer => IncomingPeer(peer, true));
|
room.on("join", peer => IncomingPeer(peer,true));
|
||||||
room.on("eject", peer => OutgoingPeer(peer));
|
room.on("eject", peer => OutgoingPeer(peer));
|
||||||
|
|
||||||
for (const peer of await room.fetchPeers()) {
|
for (const peer of await room.fetchPeers()) {
|
||||||
IncomingPeer(peer)
|
if(peer.socketId != mwse.peer('me').socketId){
|
||||||
|
IncomingPeer(peer,false)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
addVideoList("My Webcam",outgoingStream, mwse.peer("me"), true)
|
addVideoList("My Webcam",outgoingStream, mwse.peer("me"), true)
|
||||||
|
@ -219,21 +219,13 @@ async function connectRoom()
|
||||||
*/
|
*/
|
||||||
function IncomingPeer(peer,activeConnect)
|
function IncomingPeer(peer,activeConnect)
|
||||||
{
|
{
|
||||||
peer.createRTC({
|
|
||||||
iceCandidatePoolSize: 0
|
|
||||||
},[{
|
|
||||||
urls: "turn:20.166.82.187:3478",
|
|
||||||
username: "turnserver",
|
|
||||||
credential: "turnserver"
|
|
||||||
},{
|
|
||||||
urls: "stun:stun.l.google.com:19302"
|
|
||||||
}]);
|
|
||||||
if(activeConnect)
|
if(activeConnect)
|
||||||
{
|
{
|
||||||
peer.rtc.connect();
|
peer.rtc.connect();
|
||||||
}
|
}
|
||||||
peer.rtc.rtc.turboBitrate = 0;
|
peer.rtc.rtc.turboBitrate = 0;
|
||||||
peer.rtc.on('connected',() => {
|
peer.rtc.on('connected',() => {
|
||||||
|
console.log("Connected");
|
||||||
if(!activeConnect)
|
if(!activeConnect)
|
||||||
{
|
{
|
||||||
peer.rtc.sendStream(outgoingStream, "Webcam", {});
|
peer.rtc.sendStream(outgoingStream, "Webcam", {});
|
||||||
|
@ -241,6 +233,7 @@ function IncomingPeer(peer,activeConnect)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
peer.rtc.on('disconnected',() => {
|
peer.rtc.on('disconnected',() => {
|
||||||
|
console.log("Disconnected");
|
||||||
removeVideoList(peer.streamY, peer);
|
removeVideoList(peer.streamY, peer);
|
||||||
delete activePeers[peer.socketId];
|
delete activePeers[peer.socketId];
|
||||||
});
|
});
|
||||||
|
|
4296
script/index.js
4296
script/index.js
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