Stage 255
This commit is contained in:
parent
f7158a83cf
commit
454b820669
|
@ -127,6 +127,21 @@ addService(({
|
||||||
})
|
})
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case 'is/reachable':{
|
||||||
|
if(Client.clients.has(to))
|
||||||
|
{
|
||||||
|
let otherPeer = Client.clients.get(to);
|
||||||
|
if(otherPeer.requiredPair && !otherPeer.pairs.has(to))
|
||||||
|
{
|
||||||
|
end(false);
|
||||||
|
}else{
|
||||||
|
end(true);
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
end(false);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
case 'auth/check':{
|
case 'auth/check':{
|
||||||
let auth = client.store.has('user');
|
let auth = client.store.has('user');
|
||||||
return end({
|
return end({
|
||||||
|
|
|
@ -43,6 +43,13 @@ export default class Peer extends EventTarget
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
async isReachable()
|
||||||
|
{
|
||||||
|
return await this.mwse.EventPooling.request({
|
||||||
|
type:'is/reachable',
|
||||||
|
to: this.socketId
|
||||||
|
});
|
||||||
|
}
|
||||||
async enablePairAuth(){
|
async enablePairAuth(){
|
||||||
await this.mwse.EventPooling.request({
|
await this.mwse.EventPooling.request({
|
||||||
type:'auth/pair-system',
|
type:'auth/pair-system',
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import EventTarget from "./EventTarget";
|
import EventTarget from "./EventTarget";
|
||||||
import MWSE from "./index";
|
import MWSE from "./index";
|
||||||
|
import Peer from "./Peer";
|
||||||
|
|
||||||
export interface IRoomOptions
|
export interface IRoomOptions
|
||||||
{
|
{
|
||||||
|
@ -26,6 +27,7 @@ export default class Room extends EventTarget
|
||||||
public joinType? : "free"|"invite"|"password"|"lock";
|
public joinType? : "free"|"invite"|"password"|"lock";
|
||||||
public name? : string;
|
public name? : string;
|
||||||
public owner? : string;
|
public owner? : string;
|
||||||
|
public peers? : Map<string,Peer>;
|
||||||
|
|
||||||
constructor(wsts:MWSE){
|
constructor(wsts:MWSE){
|
||||||
super();
|
super();
|
||||||
|
@ -37,6 +39,14 @@ export default class Room extends EventTarget
|
||||||
{
|
{
|
||||||
this.roomId = options;
|
this.roomId = options;
|
||||||
}else{
|
}else{
|
||||||
|
Object.assign({
|
||||||
|
joinType: "free",
|
||||||
|
ifexistsJoin: true,
|
||||||
|
accessType: "private",
|
||||||
|
notifyActionInvite: true,
|
||||||
|
notifyActionJoined: true,
|
||||||
|
notifyActionEjected: true
|
||||||
|
},options);
|
||||||
this.options = options;
|
this.options = options;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -90,4 +100,18 @@ export default class Room extends EventTarget
|
||||||
wom
|
wom
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
async fetchAllPeers(){
|
||||||
|
let {type, peers} = await this.mwse.EventPooling.request({
|
||||||
|
type:'room-peers',
|
||||||
|
roomId: this.roomId
|
||||||
|
}) as {type:"success"|"fail", peers: string[]};
|
||||||
|
if(type == 'fail')
|
||||||
|
{
|
||||||
|
throw new Error("Cant using peers on room")
|
||||||
|
}else if(type == 'success'){
|
||||||
|
for (const peer of peers) {
|
||||||
|
this.mwse.peer(peer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -41,7 +41,24 @@ export default class MWSE extends EventTarget {
|
||||||
let {to,pack} = payload;
|
let {to,pack} = payload;
|
||||||
this.room(to).emit('message', pack);
|
this.room(to).emit('message', pack);
|
||||||
})
|
})
|
||||||
|
this.EventPooling.signal('room/joined',(payload : {id:string,roomid:any,ownerid:string}) => {
|
||||||
|
let {id,roomid} = payload;
|
||||||
|
let room = this.room(roomid);
|
||||||
|
let peer = this.peer(id);
|
||||||
|
room.emit('join', peer);
|
||||||
|
})
|
||||||
|
this.EventPooling.signal('room/ejected',(payload : {id:string,roomid:any,ownerid:string}) => {
|
||||||
|
let {id,roomid} = payload;
|
||||||
|
let room = this.room(roomid);
|
||||||
|
let peer = this.peer(id);
|
||||||
|
room.emit('eject', peer);
|
||||||
|
})
|
||||||
|
this.EventPooling.signal('room/closed',(payload : {roomid:any}) => {
|
||||||
|
let {roomid} = payload;
|
||||||
|
let room = this.room(roomid);
|
||||||
|
room.emit('close');
|
||||||
|
this.rooms.delete(roomid);
|
||||||
|
})
|
||||||
}
|
}
|
||||||
public room(options: IRoomOptions | string) : Room
|
public room(options: IRoomOptions | string) : Room
|
||||||
{
|
{
|
||||||
|
@ -51,13 +68,10 @@ export default class MWSE extends EventTarget {
|
||||||
{
|
{
|
||||||
return this.rooms.get(options) as Room
|
return this.rooms.get(options) as Room
|
||||||
}
|
}
|
||||||
if(this.rooms.has(options))
|
|
||||||
{
|
|
||||||
return this.rooms.get(options) as Room
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
let room = new Room(this);
|
let room = new Room(this);
|
||||||
room.setRoomOptions(options);
|
room.setRoomOptions(options);
|
||||||
|
this.rooms.set(room.roomId as string, room);
|
||||||
this.emit('room');
|
this.emit('room');
|
||||||
return room;
|
return room;
|
||||||
}
|
}
|
||||||
|
@ -76,6 +90,7 @@ export default class MWSE extends EventTarget {
|
||||||
}
|
}
|
||||||
let peer = new Peer(this);
|
let peer = new Peer(this);
|
||||||
peer.setPeerOptions(options);
|
peer.setPeerOptions(options);
|
||||||
|
this.peers.set(peer.socketId as string, peer);
|
||||||
this.emit('peer', peer);
|
this.emit('peer', peer);
|
||||||
return peer;
|
return peer;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,8 @@
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"description": "Mikro WebSocket Engine",
|
"description": "Mikro WebSocket Engine",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"compile": "parcel watch --no-hmr"
|
"compile": "parcel watch --no-hmr",
|
||||||
|
"build": "parcel build"
|
||||||
},
|
},
|
||||||
"source": "./frontend/index.ts",
|
"source": "./frontend/index.ts",
|
||||||
"targets": {
|
"targets": {
|
||||||
|
|
542
script/index.js
542
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