Pubnub.getMessageEventNameFor () does not start

I took days to figure this out, but I don’t understand the problem, to start here Pubnub codes in relatives files:

File 1) where the event does not fire:

this.$rootScope.$on(this.Pubnub.getMessageEventNameFor("activity_" + this.activity.id + "_tables"), function (ngEvent, envelope) {
        console.log("envelope", envelope);
    });

File 2) (This is a copy of file 1), where the event trigger (just changed the name of the channel):

this.$rootScope.$on(this.Pubnub.getMessageEventNameFor("kitchen_" + this.activity.id + "_tables"), function (ngEvent, envelope) {
                console.log("envelope", envelope);
            });

File 3) that fires the event:

this.Pubnub.publish({
            channel: "kitchen_" + sessionStorage.getItem('activity_id') + "_tables",
            message: angular.toJson({ msg: "New Table", table: new_table})
        }, function (status, response) {
        });

this.Pubnub.publish({
            channel: "activity_" + sessionStorage.getItem('activity_id') + "_tables",
            message: angular.toJson({ msg: "New Table", table: new_table})
        }, function (status, response) {
        });
  • activity.id it is the same for all (verified)
  • I created console.log (this is. $ RootScope) in File 1 , and this event exists:
.

$$ listeners ["pubnub: default: subscribe: callback: activity_SUyNTii1He_tables"] ["0"]

( , , " ", , )

  • 3... 1 :

pubnub.4.3.3.js: 1670 XHR : GET " http://ps1.pubnub.com/v2/subscribe/MY_KEY_AND_UUID&pnsdk=PubNub-JS-Web%2F4.3.3".

, , JSON, , 3:

{
"t": {
    "t": "14970265478466724",
    "r": 12
},
"m": [
    {
        "a": "0",
        "f": 0,
        "i": "...other-key...",
        "p": {
            "t": "14970265478474153",
            "r": 12
        },
        "k": "...subscribe-key...",
        "c": "activity_SUyNTii1He_tables",
        "d": "{
            ...all my data...
        }",
        "b": "activity_SUyNTii1He_tables"
    }
]

}

Pubnub, , - ...

UPDATE . "" 2 , html, - "", Pubnub. "" , ( Pubnub 2), . , . Angular , ,

+4
2

? ,

Pubnub.subscribe({
    channel: $scope.channel, 
    triggerEvents: ['event1', 'event2', 'event3', '...']
});
+1

Op , , channel .

:.

Pubnub.subscribe({
    channels: [ $scope.channel ],
    triggerEvents: true
});

https://github.com/pubnub/pubnub-angular#events

, -.

0

Source: https://habr.com/ru/post/1678897/


All Articles