﻿// opt => {channel,room, socket, io}

// fnc =>  joinroom,
//         leaveroom,
//         changeroom,
//         watchallroom,
//         watchoneroom,
//         sID,

module.exports = function (opt) {
    var init = function (opt) {
        this.io = opt.io || null;
        this.channel = opt.channel || 'default';
        this.room = opt.room || 'default';
        this.socket = opt.socket || null;
        return this;
    };

    //join room
    var joinroom = function (room, cb) {
        var socket = this.socket;
        socket.join(room, function () {
            cb(true);
        });
    };

    //leave room
    var leaveroom = function (room, cb) {
        var socket = this.socket;
        socket.leave(room, function () {
            cb(true);
        });
    };

    //change room will leave old room first
    var changeroom = function (room, cb) {
        var socket = this.socket;
        var oldroom = this.room;
        var newroom = room;
        socket.leave(oldroom, function () {
            socket.join(newroom, function () {
                cb(true);
            });
        });
    };

    //watch all room list from socket.io namespace
    var watchallroom = function () {
        var io = this.io;
        var socket = this.socket;
        var name = io.sockets.name;
        return io.nsps[name].adapter.rooms;
    };

    //watch one room list from socket.io namespace
    var watchoneroom = function (room) {
        var io = this.io;
        var socket = this.socket;
        var name = io.sockets.name;
        return io.nsps[name].adapter.rooms[room];
    };

    //watch the sessionID from socket.io
    var sID = function () {
        var socket = this.socket;
        return socket.handshake.sessionID;
    };

    var channel = {
        init: init,
        joinroom: joinroom,
        leaveroom: leaveroom,
        changeroom: changeroom,
        watchallroom: watchallroom,
        watchoneroom: watchoneroom,
        sID: sID
    };

    return channel.init(opt);
}

@@ -29,16 +29,26 @@
 cket, io
+, auto:t/f
 %7D%0A%0A// fn
@@ -57,24 +57,34 @@
 =%3E  joinroom
+(room, cb)
 ,%0A//        
@@ -89,24 +89,34 @@
    leaveroom
+(room, cb)
 ,%0A//        
@@ -122,24 +122,34 @@
   changeroom
+(room, cb)
 ,%0A//        
@@ -182,24 +182,30 @@
 watchoneroom
+(room)
 ,%0A//        
@@ -209,16 +209,78 @@
     sID,
+%0A//         FileBOT(base64, kind, cb)%0A%0Avar fs = require('fs');
 %0A%0Amodule
@@ -407,33 +407,28 @@
 .channel %7C%7C 
-'default'
+null
 ;%0A        th
@@ -514,19 +514,287 @@
     
-return this
+if (opt.auto == true) %7B%0A            return auto(this);%0A        %7D else %7B%0A            return this;%0A        %7D;%0A    %7D;%0A%0A    //start%0A    var auto = function (object) %7B%0A        var socket = object.socket;%0A        var room = object.room;%0A        socket.join(room);%0A        return object
 ;%0A  
@@ -1500,24 +1500,34 @@
 ch all room 
+and users 
 list from so
@@ -1750,16 +1750,26 @@
 ne room 
+and users 
 list fro
@@ -2135,24 +2135,423 @@
 ID;%0A    %7D;%0A%0A
+    //File System BOT Fnc%0A    function base64_encode(file) %7B%0A        var f = fs.readFileSync(file);%0A        return new Buffer(f).toString('base64');%0A    %7D;%0A    function base64_decode(base64str, file) %7B%0A        var f = new Buffer(base64str, 'base64');%0A        fs.writeFileSync(file, f);%0A    %7D;%0A    var FileBOT = function (base64, kind, cb) %7B%0A        base64_decode(base64, './files/' + kind);%0A    %7D;%0A%0A
     var chan
@@ -2756,16 +2756,42 @@
 sID: sID
+,%0A        FileBOT: FileBOT
 %0A    %7D;%0A
@@ -2822,9 +2822,9 @@
 (opt);%0A%7D
-%0A
+;

Add File Bot fnc