Skip to content
This repository was archived by the owner on Nov 8, 2021. It is now read-only.
Gentilhomme edited this page Aug 25, 2017 · 4 revisions

Room

uVyper Room. Create a new room where you can manage connection and disconnect like a socket server.

const {Room} = require('uvyper'); 

const RoomA = new Room('RoomA'); 

RoomA.on('connection',function(socket) {
    console.log(`socket ${socket.id} connected to RoomA!`);
    RoomA.deleteSocket(socket);
});

RoomA.on('disconnect',function(socket) {
    console.log(`socket ${socket.id} disconnected from RoomA!`);
});

Properties

name type
name String
sockets SocketMap
alive Boolean

Methods

constructor(roomName)

addSocket(socket)

A new socket into the room.

deleteSocket(socket)

Delete a socket from the room.

disconnectAll()

Disconnect all sockets connected to the room.

destroy()

Disconnect all clients and delete the room from the global registery. You should put the room variable to undefined to let the garbage collector destroy the room completely.

Events

connection -> socket

disconnect -> socket

Global rooms & events

const { Server } = require('uvyper'); 

Server.EventsObserver.on('new_room',function(room) {
    console.log(`room ${room.name} has been created!`);
});

Server.EventsObserver.on('delete_room',function(room) {
    console.log(`room ${room.name} has been deleted!`);
});

for(let room of Server.EventsObserver.rooms) {
    console.log(room.name);
}

Clone this wiki locally