Skip to content

Instantly share code, notes, and snippets.

@lcharette
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lcharette/a392e61b21069f20a75b to your computer and use it in GitHub Desktop.
Save lcharette/a392e61b21069f20a75b to your computer and use it in GitHub Desktop.
APE Event Push SSJS Example
Ape.registerCmd("objectPush", true, function(params, infos) {
//Make sure we have a channel defined
if (params.channel && params.channel != null) {
var chan = Ape.getChannelByName(params.channel);
if (!chan) return ["401", "UNKNOWN_CHANNEL"];
//Make data optional
if (!params.data) {
params.data = Array();
}
//Default Raw if none is givven
if (!params.raw) {
params.raw = 'data';
}
//Send to the channel. The sender won't receive it.
chan.pipe.sendRaw(params.raw, params.data, {'from': infos.user.pipe});
//If you want the sender to receive what he sent, comment the previous
//line and uncomment this one:
//chan.pipe.sendRaw(params.raw, params.data);
} else {
return 0;
}
});
myPipe.request.send('objectPush', {
'raw': 'objectPushed',
'channel': 'testchannel',
'data': {
'content': 'Heyyyy',
'more': 'you!'
}
});
ape.onRaw('objectPushed', function (raw, pipe) {
console.log('objectPushed', raw, pipe);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment