1

Here is the current code (subscription to a single item)

podio.authenticate('password', {
    'username': podioUser.username,
    'password': podioUser.password
}, function (response, body) {
    const item_id = 1234567;
    podio.get('/item/' + item_id, {}, function (response, body) {
        push.addSubscription(body.push);
    });
});

Here is the complete code,

// Initialize faye client
var fayeClient = new faye.Client('https://push.podio.com/faye');
// Extend faye client with signature and timestamp used for authentication
fayeClient.addExtension({
    'outgoing': function (message, callback) {
        message.ext = message.ext || {};
        message.ext = {private_pub_signature: push.channel.signature, private_pub_timestamp: push.channel.timestamp};
        callback(message);
    }
});
const push = {
    subscription: null,
    channel: null,
    addSubscription: function (channel) {
        this.channel = channel;
        this.subscription = fayeClient.subscribe(this.channel.channel).withChannel(function (channel, message) {
            var client = new faye.Client('http://localhost:8000/');
            client.publish('/messages', {
                text: message
            });
        });
        this.subscription.then(function () {
            console.log('Subscription is now active');
        }, function (error) {
            console.error('Subscription failed: ', error.message, error);
        });
    }
};
podio.authenticate('password', {
    'username': podioUser.username,
    'password': podioUser.password
}, function (response, body) {
    const item_id = 1234567;
    podio.get('/item/' + item_id, {}, function (response, body) {
        push.addSubscription(body.push);
    });
});
bayeux.attach(server);
server.listen(8002);

Is it possible to subscribe multiple items? I tried item id loop through and subscribe, it doesn't work.

Nikhil
  • 1,450
  • 11
  • 24

0 Answers0