Last active
August 29, 2015 14:01
-
-
Save lcharette/a392e61b21069f20a75b to your computer and use it in GitHub Desktop.
APE Event Push SSJS Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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