Stabilization 234

This commit is contained in:
Abdussamed 2024-03-19 01:14:20 +03:00
parent e9e7ebbbc1
commit 88d87c2c68
10 changed files with 67 additions and 106 deletions

View File

@ -77,7 +77,7 @@ addService(({
pack: pack,
id:messageId
}, 'request']);
};
}else console.error("request/to error not finded Peer");
break;
}
case "response/to":{
@ -93,7 +93,7 @@ addService(({
from: client.id,
pack: pack
}, id]);
};
}else console.error("response/to error not finded Peer");
break;
}
case "pack/room":{

View File

@ -65,8 +65,16 @@ wsServer.addListener("connect",(socket) => {
CLIENT_DESTROY(id);
Client.clients.set(id, xClient);
clearInterval(timer);
clearInterval(pingTimer);
});
let pingTimer = setInterval(()=> socket.ping('saQut') , 10_000);
socket.addListener("pong",validationText => {
if(validationText.toString('utf8') != "saQut"){
socket.close();
}
})
socket.addListener("message",({type,utf8Data}) => {
stats.ws_recaived_packs++;
stats.ws_total_packs++;

View File

@ -36,6 +36,11 @@ export class Connection
}
public disconnect()
{
/**
* Eğer bilinerek elle kapatıldıysa otomatik tekrar bağlanmasının
* önüne geçmek için autoReconnect bayrağını her zaman kapalı tutmak gerekir
*/
this.autoReconnect = false;
this.ws.close();
}
public addWSEvents()
@ -54,6 +59,9 @@ export class Connection
}
private eventClose()
{
for (const callback of this.passiveConnectionEvent) {
callback(void 0);
}
this.connected = false;
if(this.autoReconnect)
{
@ -79,6 +87,16 @@ export class Connection
this.activeConnectionEvent.push(func);
}
}
private passiveConnectionEvent : Function[] = [];
public onPassive(func:Function)
{
if(!this.connected)
{
func()
}else{
this.passiveConnectionEvent.push(func);
}
}
private eventMessage(data: string | ArrayBuffer)
{
if(typeof data == "string")

View File

@ -30,7 +30,7 @@ export default class Peer extends EventTarget
this.mwse = wsts;
this.info = new PeerInfo(this);
this.on('pack',(data:{type?:string,action?:IMessageSymbase,payload?:any}) => {
if(data.type == ':rtcbase_pack:')
if(data.type == ':rtcpack:')
{
if(this.rtc)
{
@ -53,7 +53,7 @@ export default class Peer extends EventTarget
})
this.rtc.on("output",(payload:object) => {
this.send({
type: ':rtcbase_pack:',
type: ':rtcpack:',
payload: payload
})
});

View File

@ -115,16 +115,33 @@ export default class Room extends EventTarget
this.mwse.rooms.delete(this.roomId as string);
}
}
async send(pack: any, wom:boolean = false){
async send(pack: any, wom:boolean = false, handshake = false){
if(!this.mwse.writable){
return console.warn("Socket is not writable");
}
await this.mwse.EventPooling.request({
type:'pack/room',
pack,
to: this.roomId,
wom
});
if(handshake)
{
let {type} = await this.mwse.EventPooling.request({
type:'pack/room',
pack,
to: this.roomId,
wom,
handshake
}) as {
type:"success"|"fail"
};
if(type == "fail"){
throw new Error("Cant send message to room")
}
}else{
await this.mwse.EventPooling.request({
type:'pack/room',
pack,
to: this.roomId,
wom,
handshake
})
}
}
async fetchPeers(filter?:{[key:string]:any}, onlyNumber:boolean = false) : Promise<Number | Peer[]>
{

View File

@ -50,12 +50,20 @@ export default class MWSE extends EventTarget {
this.emit('scope');
this.activeScope = true;
});
this.server.onPassive(async ()=>{
this.emit('close');
});
this.packMessagingSystem();
}
public writable = 1;
public readable = 1;
public destroy()
{
this.server.disconnect();
}
public enableRecaiveData(){
this.WSTSProtocol.SendOnly({ type: 'connection/packrecaive', value: 1 })
this.readable = 1

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -18,39 +18,11 @@
wsjs.scope(async ()=>{
let me = wsjs.peer('me');
me.disablePairAuth();
console.log(me.socketId);
let room = wsjs.room({
accessType: "public",
description: "Benim odam",
joinType: "free",
name: "M.E.",
notifyActionInvite: true,
notifyActionJoined: true,
notifyActionEjected: false,
ifexistsJoin: true
});
room.on('updateinfo',(name,value) => {
console.log(`Odanın ${name} özelliği ${value} olarak değişti`)
})
window.room = room;
await room.createRoom();
room.on('message',(...args)=>{
gg.r++
gg()
console.log(args[0],gg.r)
let room = wsjs.datastore({
type: 'temp',
sha256: 'f1290186a5d0b1ceab27f4e77c0c5d68'
});
iroom = room;
setInterval(()=>{
room.send({
type: "merhaba"
})
gg.w++;
gg()
}, 2000)
});
};

View File

@ -1,62 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script src="http://127.0.0.1:7707/script"></script>
<script>
const wsjs = new MWSE({
endpoint: "ws://127.0.0.1:7707"
});
wsjs.scope(async () => {
let me = wsjs.peer('me');
await me.info.set("name","Abdussamed");
await me.info.set("surname","ULUTAŞ");
await me.info.set("age","25");
await me.info.set("date",1);
let t = 2;
setInterval(()=>{
me.info.set("date", t);
t++;
},2000)
let room = wsjs.room({
name: "saqut.com",
description: "saqut.com try",
joinType: "free",
ifexistsJoin: true,
accessType: "private",
notifyActionInvite: false,
notifyActionJoined: true,
notifyActionEjected: true
});
await room.createRoom();
let peers = await room.fetchPeers();
for (const peer of peers) {
await peer.info.fetch();
console.log("Peer info fetched",peer.socketId,peer.info.get());
peer.on('info', (name, value) => {
console.log("Peer info changed", peer.socketId, name, value, peer.info.get());
})
}
room.on('join', async peer => {
await peer.info.fetch();
console.log("Peer info fetched",peer.socketId,peer.info.get());
peer.on('info', (name, value) => {
console.log("Peer info changed", peer.socketId, name, value, peer.info.get());
})
});
});
</script>
</body>
</html>