Skip to content

API Reference

Yu Xia edited this page Jun 28, 2015 · 4 revisions

Built-in Controllers

push

A powerful push service, features:

  • Channel subscribe control
  • Message history persistent
  • Offline message

You can use push controller to implement chat, notification in your game

pushConfig

Settings for push

  • maxMsgCount - max message count perserved in history. default 100.
  • maxPlayerCount - max player count in one channel. default 1000.

DO NOT set too large 'maxMsgCount', 'maxPlayerCount', or push large messages, which can slow down performance.

app.set('pushConfig', {maxMsgCount : 100, maxPlayerCount : 1000});

push.connectAsync(playerId, connectorId)

You should call push.connectAsync when a player connected

  • playerId - playerId
  • connectorId - frontendId
yield pushController.connectAsync('player1', 'connector-server-1');

push.disconnectAsync(playerId)

You should call push.disconnectAsync when a player disconnected

  • playerId - playerId
yield pushController.disconnectAsync('player1');

push.joinAsync(channelId, playerId, connectorId)

Player join a channel. A new channel will be created if channel doesn't exist.

  • channelId - channelId
  • playerId - playerId
  • connectorId - frontendId
yield pushController.joinAsync('channel1', 'player1', 'connector-server-1');

push.quitAsync(channelId, playerId)

Player quit a channel. Channel will be removed if there is no player in it.

  • channelId - channelId
  • playerId - playerId
yield pushController.quitAsync('channel1', 'player1');

push.pushAsync(channelId, playerIds, route, msg, persistent)

Push message to channel

  • channelId - channelId
  • playerIds - [playerId]. Push to specified players in the channel, left null to push all in channels.
  • route - route of pomelo notify message
  • msg - message content, must be JSON
  • persistent - true/false. If persistent is true, message will be stored on channel history, and offline players can receive offline message. Otherwise, message will be only push to online players, and do not store in history.
yield pushController.pushAsync('channel1', null, 'chat', {'content' : 'hello'}, true);
yield pushController.pushAsync('channel1', null, 'notify', {'content' : 'hello'}, false);
yield pushController.pushAsync('channel1', ['player1', 'player2'], 'chat', {'content' : 'hello'}, true);

push.getMsgsAsync(channelId, seq, count)

Get message history for channel

Only persistent message can be get here. Note the history capacity is limited, previous history will automatically removed when history becomes full.

  • channelId - channelId
  • seq - the start message sequence to return. Sequence is strictly incremental from 0. left null to return from the first history.
  • count - return message count. left null to return all messages.
yield pushController.getMsgsAsync('channel1', 10, 20);
yield pushController.getMsgsAsync('channel1', 10);

client.on(route, function(msg){})

Notify message on client. route and msg is passed from push.pushAsync

// This is client code
pomeloClient.on(route, function(msg){
   // process msgs
});