/config/server.json
{
"development":{
"room":[
{"id":"room-server-3", "host":"127.0.0.1", "port":6056}
]
},
"production":{
"room":[
{"id":"room-server-3", "host":"127.0.0.1", "port":6056}
]
}
}
/config/adminServer.json
[ {
"type": "room",
"token": "agarxhqb98rpajloaxn34ga8xrunpagkjwlaw3ruxnpaagl29w4rxn"
} ]
/app/servers/room/remote/roomRemote.js
module.exports = function(app) {
return new RoomRemote(app);
};
var RoomRemote = function(app) {
this.app = app;
this.channelService = app.get('channelService');
};
/**
* Add user into chat channel.
*
* @param {String} uid unique id for user
* @param {String} sid server id
* @param {String} name channel name
* @param {boolean} flag channel parameter
*
*/
RoomRemote.prototype.add = function(uid, sid, name, flag, cb) {
console.log("-----------------------------RoomRemote-------------222---------------------")
var channel = this.channelService.getChannel(name, flag);
var username = uid.split('*')[0];
cb(this.get(name, flag));
};
/**
* Get user from chat channel.
*
* @param {Object} opts parameters for request
* @param {String} name channel name
* @param {boolean} flag channel parameter
* @return {Array} users uids in channel
*
*/
RoomRemote.prototype.get = function(name, flag) {
var users = [];
var channel = this.channelService.getChannel(name, flag);
if( !! channel) {
users = channel.getMembers();
}
for(var i = 0; i < users.length; i++) {
users[i] = users[i].split('*')[0];
}
return users;
};
/**
* Kick user out chat channel.
*
* @param {String} uid unique id for user
* @param {String} sid server id
* @param {String} name channel name
*
*/
RoomRemote.prototype.kick = function(uid, sid, name, cb) {
var channel = this.channelService.getChannel(name, false);
// leave channel
if( !! channel) {
channel.leave(uid, sid);
}
var username = uid.split('*')[0];
var param = {
route: 'onLeave',
user: username
};
channel.pushMessage(param);
cb();
};