Stage 2 : Finish Alpha, Begin Beta #2
			
				
			
		
		
		
	| 
						 | 
				
			
			@ -26,30 +26,30 @@ addService(({
 | 
			
		|||
    switch(type)
 | 
			
		||||
    {
 | 
			
		||||
        case "pack/to":{
 | 
			
		||||
            let {to,pack} = message;
 | 
			
		||||
            let {to,pack,handshake} = message;
 | 
			
		||||
            if(Client.clients.has(to))
 | 
			
		||||
            {
 | 
			
		||||
                Client.clients.get(to).send([{
 | 
			
		||||
                    from: client.id,
 | 
			
		||||
                    pack: pack
 | 
			
		||||
                }, 'pack']);
 | 
			
		||||
                end({
 | 
			
		||||
                handshake && end({
 | 
			
		||||
                    type: 'success'
 | 
			
		||||
                })
 | 
			
		||||
            }else{
 | 
			
		||||
                end({
 | 
			
		||||
                handshake && end({
 | 
			
		||||
                    type: 'fail'
 | 
			
		||||
                })
 | 
			
		||||
            }
 | 
			
		||||
            break;
 | 
			
		||||
        }
 | 
			
		||||
        case "pack/room":{
 | 
			
		||||
            let {to,pack} = message;
 | 
			
		||||
            let {to,pack, handshake} = message;
 | 
			
		||||
            if(Room.rooms.has(to))
 | 
			
		||||
            {
 | 
			
		||||
                if(!client.rooms.has(to))
 | 
			
		||||
                {
 | 
			
		||||
                    return end({
 | 
			
		||||
                    return handshake && end({
 | 
			
		||||
                        type: 'fail'
 | 
			
		||||
                    })
 | 
			
		||||
                };
 | 
			
		||||
| 
						 | 
				
			
			@ -57,11 +57,11 @@ addService(({
 | 
			
		|||
                    from: client.id,
 | 
			
		||||
                    pack: pack
 | 
			
		||||
                }, 'pack']);
 | 
			
		||||
                end({
 | 
			
		||||
                handshake && end({
 | 
			
		||||
                    type: 'success'
 | 
			
		||||
                })
 | 
			
		||||
            }else{
 | 
			
		||||
                end({
 | 
			
		||||
                handshake && end({
 | 
			
		||||
                    type: 'fail'
 | 
			
		||||
                })
 | 
			
		||||
            }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,24 +1,27 @@
 | 
			
		|||
function WSJS()
 | 
			
		||||
{
 | 
			
		||||
    this.isActive = false;
 | 
			
		||||
    this.ws = null;
 | 
			
		||||
    this.ws = WSJS.activeWS || null;
 | 
			
		||||
    this.endpoint = null;
 | 
			
		||||
};
 | 
			
		||||
WSJS.activeWS = null;
 | 
			
		||||
WSJS.prototype.connect = function(url){
 | 
			
		||||
    this.ws = new WebSocket(url);
 | 
			
		||||
    this.addListeners();
 | 
			
		||||
}
 | 
			
		||||
WSJS.prototype.addListeners = function(url){
 | 
			
		||||
WSJS.prototype.addListeners = function(){
 | 
			
		||||
    this.ws.addEventListener("close", this.closedEvent.bind(this));
 | 
			
		||||
    this.ws.addEventListener("message", this.messageEvent.bind(this));
 | 
			
		||||
    this.ws.addEventListener("open", this.openMessage.bind(this));
 | 
			
		||||
}
 | 
			
		||||
WSJS.prototype.closedEvent = function(){
 | 
			
		||||
    WSJS.activeWS = null;
 | 
			
		||||
    this.isActive = false;
 | 
			
		||||
    this.ws = null;
 | 
			
		||||
    this.events.dispatchEvent(new Event("close"));
 | 
			
		||||
}
 | 
			
		||||
WSJS.prototype.openMessage = function(){
 | 
			
		||||
    WSJS.activeWS = this.ws;
 | 
			
		||||
    this.isActive = true;
 | 
			
		||||
    this.events.dispatchEvent(new Event("open"));
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -141,7 +144,7 @@ WSJS.prototype.createRoom = async function(options){
 | 
			
		|||
    return result;
 | 
			
		||||
};
 | 
			
		||||
WSJS.prototype.roomInfo = async function(name){
 | 
			
		||||
    let result =  await this.request({
 | 
			
		||||
    let result = await this.request({
 | 
			
		||||
        type: 'room-info',
 | 
			
		||||
        name
 | 
			
		||||
    });
 | 
			
		||||
| 
						 | 
				
			
			@ -167,16 +170,18 @@ WSJS.prototype.getRoomPeers = async function(id){
 | 
			
		|||
    });
 | 
			
		||||
};
 | 
			
		||||
WSJS.prototype.sendPackToPeer = async function(roomId, pack){
 | 
			
		||||
    return await this.request({
 | 
			
		||||
    return await this.sendOnly({
 | 
			
		||||
        type: 'pack/to',
 | 
			
		||||
        to: roomId,
 | 
			
		||||
        pack
 | 
			
		||||
        pack,
 | 
			
		||||
        handshake: false
 | 
			
		||||
    });
 | 
			
		||||
};
 | 
			
		||||
WSJS.prototype.sendPackToRoom = async function(roomId, pack){
 | 
			
		||||
    return await this.request({
 | 
			
		||||
    return await this.sendOnly({
 | 
			
		||||
        type: 'pack/room',
 | 
			
		||||
        to: roomId,
 | 
			
		||||
        pack
 | 
			
		||||
        pack,
 | 
			
		||||
        handshake: false
 | 
			
		||||
    });
 | 
			
		||||
};
 | 
			
		||||
		Loading…
	
		Reference in New Issue