Pomelo游戏服务器端开发系列(2)-pushMessage
2017-05-08 00:00
211 查看
摘要: 消息通知方法介绍
推送消息给指定的用户集合uids:[{uid:1001,sid:'connector-server-1'},{uid:1002,sid:'connector-server-2'}].
推送消息方法
pushMessage
以channel为单位推送消息, 每个channel可比作一个房间。代码示例
/** * Push message to all the members in the channel * * @param {String} route message route * @param {Object} msg message that would be sent to client * @param {Object} opts user-defined push options, optional * @param {Function} cb callback function */ var channelService = pomelo.app.get('channelService'); var channel = channelService.getChannel(channelName, false); var params = { route: 'onChat', msg: {}, }; channel.pushMessage(params);
pushMessageByUids
该方法只在channelService中定义, channel不可使用该方法。推送消息给指定的用户集合uids:[{uid:1001,sid:'connector-server-1'},{uid:1002,sid:'connector-server-2'}].
代码示例
/** * Push message by uids. * Group the uids by group. ignore any uid if sid not specified. * * @param {String} route message route * @param {Object} msg message that would be sent to client * @param {Array} uids the receiver info list, [{uid: userId, sid: frontendServerId}] * @param {Object} opts user-defined push options, optional * @param {Function} cb cb(err) * @memberOf ChannelService */ var channelService = pomelo.app.get('channelService'); channelService.pushMessageByUids(route, msg, uids, opt, callback);
broadcast
广播消息。 推送给所有用户代码示例
/** * Broadcast message to all the connected clients. * * @param {String} stype frontend server type string * @param {String} route route string * @param {Object} msg message * @param {Object} opts user-defined broadcast options, optional * opts.binded: push to binded sessions or all the sessions * opts.filterParam: parameters for broadcast filter. * @param {Function} cb callback * @memberOf ChannelService */ var channelService = pomelo.app.get('channelService'); //ex: stype -> connector channelService.broadcast(stype, route, msg, opts, callback)
相关文章推荐
- Pomelo游戏服务器端开发系列(5)-globalErrorHandler
- Pomelo游戏服务器端开发系列(4)-Connector
- Pomelo游戏服务器端开发系列(1)-介绍
- Pomelo游戏服务器端开发系列(3)-Router
- Pomelo游戏服务器端开发系列(7)--高可用
- Pomelo游戏服务器端开发系列(6)--Component
- Pomelo游戏服务器端开发系列(8)--消息类型
- Pomelo游戏服务器端开发系列(9)--配置RPC
- (pomelo系列入门教程)深入浅出node.js游戏服务器开发——Pomelo框架的设计动机与架构介绍
- 系列文章之二 用cocos2d-js和pomelo开发MMORPG传奇手游-启动游戏(一)
- (pomelo系列入门教程)深入浅出Node.js游戏服务器开发--分布式聊天服务器搭建
- 系列文章之二 用cocos2d-js和pomelo开发MMORPG传奇手游-启动游戏续(一)
- (pomelo系列入门教程)深入浅出node.js游戏服务器开发——基于Pomelo的MMO RPG开发
- (pomelo系列入门教材)深入浅出node.js游戏服务器开发1——基础架构与框架介绍
- [导入]视频游戏开发系列课程(5):Transformation and Collision of Sprites
- 【转载】上海软星仙剑开发组解散真正内幕-献给所有喜欢仙剑系列游戏的朋友们...
- 游戏开发技术系列丛书 献给游戏研发的专业人士
- 3D游戏开发步步高系列课程(视频课程讲师:付仲恺)
- Silverlight 2.0游戏《抢滩登陆战2D》开发系列开篇
- [导入]视频游戏开发系列课程(7):让你的游戏更“声”动——音乐和音效