Last active
August 29, 2015 14:09
-
-
Save cultofmetatron/d221dd78399153dac2fb to your computer and use it in GitHub Desktop.
streamController - broken
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
var _ = require('lodash'); | |
var PUBNUB = require('pubnub'); | |
var Promise = require('bluebird'); | |
var secret = 'demo_secret'; | |
var pubnub = PUBNUB.init({ | |
publish_key: 'demo', | |
subscribe_key: 'demo', | |
secret_key: secret | |
}); | |
/* goal | |
* create a channel group | |
* group: 'foobarfuckshitz' | |
* channels: ['foobar1', 'foobar2'] | |
* grant access to a group to an auth_key | |
* see if it sticks | |
*/ | |
//pass the arguments from the callback into more than one function | |
var simul = function() { | |
var fns = Array.prototype.slice.call(arguments); | |
return function() { | |
var args = Array.prototype.slice.call(arguments); | |
return _.map(fns, function() { | |
return fns.apply(this, args); | |
}, this); | |
}; | |
}; | |
var displayCallback = function() { | |
console.log('?:=> ', arguments); | |
return null; | |
}; | |
var channel = "foobar1"; | |
var channelGroup = 'foobar'; | |
var pubWrapper = function(fnName) { | |
return function(opt) { | |
var opt = opt || {}; | |
return new Promise(function(resolve, reject) { | |
pubnub[fnName](_.extend({}, opt, { | |
callback: resolve, | |
error: reject | |
})); | |
}); | |
}; | |
}; | |
var addChannel = pubWrapper('channel_group_add_channel'); | |
var grant = pubWrapper('grant'); | |
var audit = pubWrapper('audit'); | |
/* | |
Promise.all([ | |
addChannel({ | |
channel_group: channelGroup, | |
channel: 'foobar1' | |
}), | |
addChannel({ | |
channel_group: channelGroup, | |
channel: 'foobar2' | |
}) | |
]) | |
*/ | |
Promise.try(function() { | |
}) | |
.then(function() { | |
console.log('granting channel') | |
return grant({ | |
channel_group: channelGroup, | |
read: true, | |
write: true, | |
manage: true, | |
ttl: 0, | |
auth_key: 'yolopants' | |
}); | |
}) | |
.then(function() { | |
console.log('adding channel to group') | |
return addChannel({ | |
channel_group: channelGroup, | |
channel: 'foobar1', | |
auth_key: 'yolopants' | |
}); | |
}) | |
.then(function() { | |
return audit({ | |
channel_group: channelGroup, | |
auth_key: 'yolopants' | |
}); | |
}) | |
.then(function(val) { | |
console.log('finally ', val); | |
}) | |
.catch(function(err) { | |
console.log('err', err.message); | |
console.log(err.stack) | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment