Skip to content

Instantly share code, notes, and snippets.

@lcharette lcharette/objectPush.js
Last active Aug 29, 2015

Embed
What would you like to do?
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
You can’t perform that action at this time.