perfectnogation #20

Merged
saqut merged 6 commits from perfectnogation into stable 2025-07-14 23:25:51 +03:00
6 changed files with 26 additions and 9 deletions
Showing only changes of commit bd3373fd10 - Show all commits

View File

@ -1,11 +1,12 @@
import MWSE from "frontend";
export interface IConnection{ export interface IConnection{
endpoint: string; endpoint: string;
autoReconnect?: boolean | { autoReconnect?: boolean | {
timeout: number; timeout: number;
} },
autoCreateRTC: boolean
} }
const RootURL : string = ( <HTMLScriptElement> document.currentScript).src
export class Connection export class Connection
{ {
public ws! : WebSocket; public ws! : WebSocket;
@ -16,10 +17,11 @@ export class Connection
public autoReconnect : boolean = true; public autoReconnect : boolean = true;
public autoReconnectTimeout : number = 3000; public autoReconnectTimeout : number = 3000;
public autoReconnectTimer? : number; public autoReconnectTimer? : number;
constructor(options: IConnection){ constructor(mwse:MWSE, options: IConnection){
if(options.endpoint == "auto") if(options.endpoint == "auto")
{ {
const RootURL : string = ( <HTMLScriptElement> document.currentScript).src
let scriptPath = new URL(RootURL); let scriptPath = new URL(RootURL);
let isSecurity = scriptPath.protocol == "https:"; let isSecurity = scriptPath.protocol == "https:";
let dumeUrl = scriptPath.pathname.split('/').slice(0,-1).join('/') + '/'; let dumeUrl = scriptPath.pathname.split('/').slice(0,-1).join('/') + '/';
@ -34,6 +36,9 @@ 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;
@ -83,7 +88,7 @@ export class Connection
this.connected = false; this.connected = false;
if(this.autoReconnect) if(this.autoReconnect)
{ {
this.autoReconnectTimer = setTimeout(() => this.connect(), this.autoReconnectTimeout) this.autoReconnectTimer = setTimeout(() => this.connect(), this.autoReconnectTimeout) as unknown as number;
} }
} }
private eventError() private eventError()

View File

@ -35,6 +35,11 @@ export default class Peer extends EventTarget
if(this.rtc) 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") return console.warn("Not active rtc but recaived rtc packs")
}; };

View File

@ -309,7 +309,13 @@ export default class WebRTC
this.emit('connected'); 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) if(this.active)
{ {

View File

@ -17,6 +17,7 @@ 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= [];
@ -34,7 +35,7 @@ export default class MWSE extends EventTarget {
}*/ }*/
constructor(options: IConnection){ constructor(options: IConnection){
super(); super();
this.server = new Connection(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);
this.virtualPressure = new IPPressure(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