- es6 语法 - 兼容 pomelo2.x 系列 - 内置 redis使用 - 发送消息给某一个或多个玩家 - 发送消息给指定的channelName - 发送消息给指定 sid 和 channelName - 发送消息给用户列表中指定sid的用户
npm install pomeloGlobalChannel- es6 语法
- 兼容 pomelo2.x 系列
- 内置 redis使用
- 发送消息给某一个或多个玩家
- 发送消息给指定的channelName
- 发送消息给指定 sid 和 channelName
- 发送消息给用户列表中指定sid的用户
##Installation
```
npm install pomeloGlobalChannel
##Usage
`
var globalChannel = require('pomeloGlobalChannel');
app.use(globalChannel, {GlobalChannel: {
url : 'redis://127.0.0.1:6379',
db: 5 // optinal, from 0 to 15 with default redis configure
}});
`
- GlobalChannelService
- constructor
- pushMessageForUid
- pushMessageByUidArr
- pushMessage
- getMembersByChannelName
- getMembersBySid
- getSidsByUid
- getSidsByUidArr
- destroyChannel
- add
- leave
Global channel service.
GlobalChannelService is created by globalChannel component which is a default
component of pomelo enabled by app.set('globalChannelConfig', {...})app.get('globalChannelService')
and global channel service would be accessed by.
Parameters
- app opts
-
构造函数
Parameters
- app any pomelo instanceopts
- Object 参数列表
发送消息给指定服务器 中的某一些人
Parameters
- route String route stringmsg
- Object 消息内容uids
- Array userId arrayserverType
- String frontend server typefrontServerId
- String frontend server Id
Returns Array send message fail userList
群发消息给玩家
Parameters
- uidArr (String \| Array) 要发送的玩家列表route
- String 消息号msg
- String 消息内容frontServerId
- (String | null) 指定的前端服务器Id, 默认不指定 (optional, default null)
Returns Array send message fail userList
Send message by global channel.
发送消息给指定 channelName 的所有玩家
Parameters
- serverType String frontend server typeroute
- String route stringmsg
- Object message would be sent to clientschannelName
- String channel name
Get members by channel name.
获取指定 channelName 和 服务器类型的成员
Parameters
- serverType String frontend server type stringchannelName
- String channel name
Get members by frontend server id.
获取指定服务器和channelName 的玩家列表
Parameters
- channelName String channel namefrontId
- String frontend server id
获得指定玩家在所在的服务器
Parameters
- uid 要查找的 玩家id
Returns Array
获取指定玩家的服务器列表
Parameters
- uidArr 要查找的玩家列表
Returns Object
Destroy a global channel.
Parameters
- channelName String global channel name
添加一个玩家 到指定channelName
Add a member into channel.
Parameters
- uid String user idsid
- String frontend server idchannelName
- (String \| Array) 指定的 channelName (optional, default null)
Returns number is add: 1 add success, 0 fail
Remove user from channel.
移除一个玩家
Parameters
- uid String user idsid
- String frontend server idchannelName
- (String \| Array) channel name (optional, default null)
##Notice
Global channel use redis as a default persistent storage, you can change it with your own implementation.
自定义管理
`
var globalChannel = require('pomeloGlobalChannel');
var mysqlGlobalChannelManager = require('./mysqlGlobalChannelManager');
app.use(globalChannel, {globalChannel: {
url : 'redis://127.0.0.1:6379',
channelManager: mysqlGlobalChannelManager
}});
``