0

我正在按照此链接创建一个协作绘图应用程序。我能够运行应用程序,但没有发生协作绘图。我已成功创建PUSHER_APP_ID, PUSHER_KEY, PUSHER_SECRET& 放置在.env.

协同绘图代码 -

  ngAfterViewInit() {
    const channel = this.pusher.init();
    console.log("ngAfterViewInit called :: line 142 : ", this.userId);
    channel.bind('draw', (data) => {
      console.log("line 144");
      if (data.userId !== this.userId) {
        console.log("line 146");
        data.line.forEach((position) => {
          console.log("line 148");
          this.draw(position.start, position.stop, this.guestStrokeStyle);
        });
      }
    });
  }

如果我在不同的浏览器中点击它,我可以看到不同的用户 ID。但它不会进入下面的循环。

channel.bind('draw', (data) => {
...
}

server.js我可以从代码中看到日志-

app.post('/draw', (req, res) => {
    console.log("draw :: in server :: ", req.body);
    pusher.trigger('painting', 'draw', req.body);
    res.json(req.body);
});

日志 -

draw :: in server ::  { line:
   [ { start: [Object], stop: [Object] },
     { start: [Object], stop: [Object] },
     { start: [Object], stop: [Object] },
     { start: [Object], stop: [Object] },
     { start: [Object], stop: [Object] },
     { start: [Object], stop: [Object] },
     { start: [Object], stop: [Object] },
     { start: [Object], stop: [Object] },
     { start: [Object], stop: [Object] },
     { start: [Object], stop: [Object] },
     { start: [Object], stop: [Object] },
     { start: [Object], stop: [Object] },
     { start: [Object], stop: [Object] },
     { start: [Object], stop: [Object] },
     { start: [Object], stop: [Object] },
     { start: [Object], stop: [Object] },
     { start: [Object], stop: [Object] },
     { start: [Object], stop: [Object] },
     { start: [Object], stop: [Object] },
     { start: [Object], stop: [Object] },
     { start: [Object], stop: [Object] },
     { start: [Object], stop: [Object] },
     { start: [Object], stop: [Object] },
     { start: [Object], stop: [Object] },
     { start: [Object], stop: [Object] },
     { start: [Object], stop: [Object] },
     { start: [Object], stop: [Object] },
     { start: [Object], stop: [Object] },
     { start: [Object], stop: [Object] },
     { start: [Object], stop: [Object] },
     { start: [Object], stop: [Object] },
     { start: [Object], stop: [Object] },
     { start: [Object], stop: [Object] } ],
userId: 'ggfe565r-68ae-6cc6-878a-7g7j9d3b6b94' }

如果我在任何地方做错或遗漏任何东西,任何人都可以帮助/指导。

4

1 回答 1

0

我通过更改cluster: 'eu'cluster: 'ap2'.

于 2020-03-19T11:22:22.957 回答