【问题标题】:Why is my Parse subscription not receiving any events (not even 'open')?为什么我的 Parse 订阅没有收到任何事件(甚至没有“打开”)?
【发布时间】:2019-12-20 10:39:24
【问题描述】:

我正在尝试在本地托管我的解析服务器,但在我的前端我没有收到任何事件,甚至没有收到“打开”(打开连接)事件。我也没有收到任何可以帮助我解决问题的错误。

在我的服务器上,我使用以下代码:

var api = new ParseServer(
{
   (... more properties and keys)
   liveQuery:
   {
      classNames: ['Sticky', 'Canvas']
   }
});

var app = express();

var mountPath = something;
app.use(mountPath, api);

var httpServer = require('http').createServer(app);
httpServer.listen(port, function(){ console.log('Running on http://localhost:' + port); });

var parseLiveQueryServer = ParseServer.createLiveQueryServer(httpServer);

在前端我使用以下代码:

const stickyQuery = new Parse.Query(Sticky);

this.stickySubscription = await stickyQuery.subscribe();
console.log(this.stickySubscription);  // This gets printed, nothing weird

this.stickySubscription.on('open', () => {
   console.log('SUBSCRIPTION: opened');  // This is not printed
});

this.stickySubscription.on('create', (sticky) => {
   console.log('SUBSCRIPTION: Sticky created, ', sticky);  // This is also not printed
});

this.stickySubscription.on('update', (sticky) => {
   console.log('SUBSCRIPTION: Sticky updated, ', sticky);  // This is not printed
});

订阅被打印出来,我没有看到任何奇怪的东西。似乎与 Parse 服务器的连接出错了。有人知道我错过了什么或做错了什么吗?

更新:我在前端添加了以下代码来显示websocket状态以及是否触发了错误事件,但这些事件也没有被触发:

this.stickySubscription.on('close', () => {
   console.log('SUBSCRIPTION: closed');  //  This is not printed
});

Parse.LiveQuery.on('open', () => {
   console.log('socket connection established');  // Gets printed
});

Parse.LiveQuery.on('close', () => {
   console.log('socket connection closed');  // Is not printed
});

Parse.LiveQuery.on('error', (error) => {
   console.log('socket error: ', error);  // Is not printed
});

【问题讨论】:

  • 您能否尝试添加these 事件以检查您是否从那里收到一些消息,特别是来自错误事件?
  • 这就是你的意思吧?我没有收到任何消息,不幸的是没有错误事件..
  • 您运行的 Parse Server 版本是多少?
  • 我正在运行 3.1.3 版
  • 这个类的 CLP 是什么?你有什么触发它的地方吗?

标签: node.js parse-platform parse-server


【解决方案1】:

在您的订阅查询中,将您的 className 写在引号内:

const stickyQuery = new Parse.Query('Sticky');

【讨论】:

  • 这不是问题,因为我有一个扩展 Parse.Object 的 Sticky 类。因此,创建 Parse.Query(Sticky) 应该没问题。
  • 我知道,但由于某些原因,我遇到了同样的问题,并尝试了这个解决方案,它奏效了。
猜你喜欢
  • 1970-01-01
  • 2023-02-17
  • 2020-07-15
  • 1970-01-01
  • 1970-01-01
  • 2011-05-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多