node.js - How to get channelid in pubnub subscribe/or publish function? -
this subscribe code want channelid used this.channel in code got undefined. there way can channelid
pubnub.subscribe({ channel: changing dynamically, presence: function (m) { console.log(m) }, message: function (m) { console.log(m); console.log("channel ==" + this.channel) }, error: function (error) { // handle error here console.log(json.stringify(error)); } })
result: channel==undefined
looking @ the fine manual, should work:
pubnub.subscribe({ channel: changing dynamically, presence: function (m) { console.log(m) }, message: function (m, env, channel) { console.log(m); console.log("channel ==" + channel) }, error: function (error) { // handle error here console.log(json.stringify(error)); } })
in other words, channel passed argument message
callback.
the reason this.channel
being undefined message
callback isn't called in context of object passed pubnub.subscribe()
.
Comments
Post a Comment