yiicod/yii2-socketio

View on GitHub
server/bundles/room-io.js

Summary

Maintainability
A
0 mins
Test Coverage
class RoomIO {
    constructor(socket) {
        this.socket = socket;
        this.room = [];
    }

    name() {
        return this.room[this.socket.id] || null;
    }

    join(room) {
        this.leave();
        this.room[this.socket.id] = room;

        this.socket.join(room);
    }

    leave() {
        this.socket.leave(this.room[this.socket.id]);
    }
}

module.exports = RoomIO;