pomelo init chatofpomelo
pomelo.request('connector.entryHandler.enter', {username: username}, function(){ });
handler.enter = function(msg, session, next) { session.bind(uid); session.on('closed', onUserLeave.bind(null, this.app)); };
app.rpc.chat.chatRemote.add(session, uid, app.get('serverId'), function(data){});
remote.add = function(uid, sid, cb){ var channel = channelService.getChannel('pomelo', true); if(!!channel) channel.add(uid, sid); };
pomelo.request('chat.chatHandler.send', {content: msg, from: username, target: target}, function(){});
handler.send = function(msg, session, next) { var param = {route: 'onChat', msg: msg.content, from: msg.from, target: msg.target}; // send messages };
var channel = channelService.getChannel('pomelo', false); channel.pushMessage(param);
pomelo.on('onChat', function() { addMessage(data.from, data.target, data.msg); $("#chatHistory").show(); };
app.rpc.chat.chatRemote.kick(session, session.uid, app.get('serverId'), 'pomelo', null);
handler.kick = function(uid, sid, name){ var channel = channelService.getChannel(name, false); if (!!channel) { channel.leave(uid,sid); } };
{ "development":{ "connector":[ { "id":"connector-server-1", "host":"127.0.0.1", "clientPort":3050, "frontend": true } ], "chat":[ { "id":"chat-server-1", "host":"127.0.0.1", "port":6050 } ] }, "production":{ "connector":[ { "id":"connector-server-1", "host":"127.0.0.1", "clientPort":3050, "frontend": true } ], "chat":[ { "id":"chat-server-1", "host":"127.0.0.1", "port":6050 } ] } }
pomelo start
{ "development":{ "gate":[ { "id":"gate-server-1", "host":"127.0.0.1", "clientPort":3014, "frontend": true } ], "connector":[ { "id":"connector-server-1", "host":"127.0.0.1", "clientPort":3050, "frontend": true }, { "id":"connector-server-2", "host":"127.0.0.1", "clientPort":3051, "frontend": true }, { "id":"connector-server-3", "host":"127.0.0.1", "clientPort":3052, "frontend": true } ], "chat":[ { "id":"chat-server-1", "host":"127.0.0.1", "port":6050 }, { "id":"chat-server-2", "host":"127.0.0.1", "port":6051 }, { "id":"chat-server-3", "host":"127.0.0.1", "port":6052 } ] }, "production":{ "gate":[ { "id":"gate-server-1", "host":"127.0.0.1", "clientPort":3014, "frontend": true } ], "connector":[ { "id":"connector-server-1", "host":"127.0.0.1", "clientPort":3050, "frontend": true }, { "id":"connector-server-2", "host":"127.0.0.1", "clientPort":3051, "frontend": true }, { "id":"connector-server-3", "host":"127.0.0.1", "clientPort":3052, "frontend": true } ], "chat":[ { "id":"chat-server-1", "host":"127.0.0.1", "port":6050 }, { "id":"chat-server-2", "host":"127.0.0.1", "port":6051 }, { "id":"chat-server-3", "host":"127.0.0.1", "port":6052 } ] } }
//routeUtil.js exp.chat = function(session, msg, app, cb) { var chatServers = app.getServersByType('chat'); if (!chatServers) { cb(new Error('can not find chat servers.')); return; } var res = dispatcher.dispatch(session.get('rid'), chatServers); cb(null, res.id); }; //app.js app.configure('production|development', function() { app.route('chat', routeUtil.chat); });
// app configuration app.configure('production|development', 'connector', function(){ app.set('connectorConfig', { connector : pomelo.connectors.hybridconnector, heartbeat : 3, useDict : true, useProtobuf : true }); }); app.configure('production|development', 'gate', function(){ app.set('connectorConfig', { connector : pomelo.connectors.hybridconnector, }); });
来源:即时通讯网 - 即时通讯开发者社区!
轻量级开源移动端即时通讯框架。
快速入门 / 性能 / 指南 / 提问
轻量级Web端即时通讯框架。
详细介绍 / 精编源码 / 手册教程
移动端实时音视频框架。
详细介绍 / 性能测试 / 安装体验
基于MobileIMSDK的移动IM系统。
详细介绍 / 产品截图 / 安装体验
一套产品级Web端IM系统。
详细介绍 / 产品截图 / 演示视频
精华主题数超过100个。
连续任职达2年以上的合格正式版主
为论区做出突出贡献的开发者、版主等。
Copyright © 2014-2024 即时通讯网 - 即时通讯开发者社区 / 版本 V4.4
苏州网际时代信息科技有限公司 (苏ICP备16005070号-1)
Processed in 0.156250 second(s), 40 queries , Gzip On.