【问题标题】:Angular 10 + PubNub - Problem reading messages from a specific channelAngular 10 + PubNub - 从特定频道读取消息时出现问题
【发布时间】:2021-12-27 18:18:21
【问题描述】:

我正在尝试使用 PubNub 来阅读在特定频道中发布的消息。发布工作正常。

在我的 Angular 10 前端我正在尝试以下操作:

this.pubnubService.subscribe({ channels: ['channel1'], triggerEvents: true });

this.pubnubService.getMessage(this.currentlySubscribedPubNubChannels, message => {
  console.log(message);
});

但是,发布时没有收到任何消息(通过我的 API 或 pubnub.com 上的调试控制台)。

另一方面,如果我指定一个监听器,我可以在所有通道上接收消息(这不是我想要实现的):

this.pubnubService.addListener({
  message: (message) => {
    console.log(message);
  }
});

谁能告诉我为什么一般的听众在工作,但在特定频道上收听却没有?

任何帮助表示赞赏, 谢谢, 帕斯卡

【问题讨论】:

    标签: angular pubnub


    【解决方案1】:

    好像是这个包: https://www.npmjs.com/package/pubnub-angular2 不再支持。

    结合使用“pubnub”(https://www.npmjs.com/package/pubnub) 包: https://www.npmjs.com/package/@types/pubnub

    似乎可以解决问题。

    import * as Pubnub from 'pubnub';
    ...
    export class MyApp {
    
      private pubnubService;
    
      constructor() {
        this.pubnubService = new Pubnub({
          subscribeKey : '<SUBSCRIBER KEY>'
        });
    
        this.pubnubService.subscribe({
          channels: [<YOUR CHANNEL>]
        });
    
        this.pubnubService.addListener({
          message: ((msg) => {
            // handle event
          }).bind(this)
        });
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-07-06
      • 2019-11-26
      • 2020-06-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多