perfectnogation #20
			
				
			
		
		
		
	| 
						 | 
				
			
			@ -1,11 +1,12 @@
 | 
			
		|||
import MWSE from "frontend";
 | 
			
		||||
 | 
			
		||||
export interface IConnection{
 | 
			
		||||
    endpoint: string;
 | 
			
		||||
    autoReconnect?: boolean | {
 | 
			
		||||
        timeout: number;
 | 
			
		||||
    }
 | 
			
		||||
    },
 | 
			
		||||
    autoCreateRTC: boolean
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const RootURL : string = ( <HTMLScriptElement> document.currentScript).src
 | 
			
		||||
export class Connection
 | 
			
		||||
{
 | 
			
		||||
    public ws! : WebSocket;
 | 
			
		||||
| 
						 | 
				
			
			@ -16,10 +17,11 @@ export class Connection
 | 
			
		|||
    public autoReconnect : boolean = true;
 | 
			
		||||
    public autoReconnectTimeout : number = 3000;
 | 
			
		||||
    public autoReconnectTimer? : number;
 | 
			
		||||
    constructor(options: IConnection){
 | 
			
		||||
    constructor(mwse:MWSE, options: IConnection){
 | 
			
		||||
 | 
			
		||||
        if(options.endpoint == "auto")
 | 
			
		||||
        {
 | 
			
		||||
            const RootURL : string = ( <HTMLScriptElement> document.currentScript).src
 | 
			
		||||
            let scriptPath = new URL(RootURL);
 | 
			
		||||
            let isSecurity  = scriptPath.protocol == "https:";
 | 
			
		||||
            let dumeUrl = scriptPath.pathname.split('/').slice(0,-1).join('/') + '/';
 | 
			
		||||
| 
						 | 
				
			
			@ -34,6 +36,9 @@ export class Connection
 | 
			
		|||
                throw new Error("endpoint is required")
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        if(options.autoCreateRTC === false){
 | 
			
		||||
            mwse.autoCreateRTC = false;
 | 
			
		||||
        }
 | 
			
		||||
        if(typeof options.autoReconnect == "boolean")
 | 
			
		||||
        {
 | 
			
		||||
            this.autoReconnect = true;
 | 
			
		||||
| 
						 | 
				
			
			@ -83,7 +88,7 @@ export class Connection
 | 
			
		|||
        this.connected = false;
 | 
			
		||||
        if(this.autoReconnect)
 | 
			
		||||
        {
 | 
			
		||||
            this.autoReconnectTimer = setTimeout(() => this.connect(), this.autoReconnectTimeout)
 | 
			
		||||
            this.autoReconnectTimer = setTimeout(() => this.connect(), this.autoReconnectTimeout) as unknown as number;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    private eventError()
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -35,6 +35,11 @@ export default class Peer extends EventTarget
 | 
			
		|||
                if(this.rtc)
 | 
			
		||||
                {
 | 
			
		||||
                    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")
 | 
			
		||||
            };
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -309,7 +309,13 @@ export default class WebRTC
 | 
			
		|||
                this.emit('connected');
 | 
			
		||||
            }
 | 
			
		||||
        };
 | 
			
		||||
        if(this.connectionStatus == 'failed' || this.connectionStatus == "disconnected" || this.connectionStatus == "closed")
 | 
			
		||||
 | 
			
		||||
        if(this.connectionStatus == 'failed')
 | 
			
		||||
        {
 | 
			
		||||
            this.rtc.restartIce();
 | 
			
		||||
        };
 | 
			
		||||
        
 | 
			
		||||
        if(this.connectionStatus == "closed")
 | 
			
		||||
        {
 | 
			
		||||
            if(this.active)
 | 
			
		||||
            {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -17,6 +17,7 @@ export default class MWSE extends EventTarget {
 | 
			
		|||
    public peers : Map<string, Peer> = new Map();
 | 
			
		||||
    public virtualPressure : IPPressure;
 | 
			
		||||
    public me! : Peer;
 | 
			
		||||
    public autoCreateRTC : boolean = true;
 | 
			
		||||
    /*public static compress(message:string, callback:(e:any) => any)
 | 
			
		||||
    {
 | 
			
		||||
        let u : any= [];
 | 
			
		||||
| 
						 | 
				
			
			@ -34,7 +35,7 @@ export default class MWSE extends EventTarget {
 | 
			
		|||
    }*/
 | 
			
		||||
    constructor(options: IConnection){
 | 
			
		||||
        super();
 | 
			
		||||
        this.server = new Connection(options);
 | 
			
		||||
        this.server = new Connection(this,options);
 | 
			
		||||
        this.WSTSProtocol = new WSTSProtocol(this);
 | 
			
		||||
        this.EventPooling = new EventPool(this);
 | 
			
		||||
        this.virtualPressure = new IPPressure(this);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
										
											
												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