musonza / chat-demo

Demo Application for https://github.com/musonza/chat/
104 stars 58 forks source link

Issue with pusher, again #17

Open horaceho opened 4 years ago

horaceho commented 4 years ago

I follow the above instruction https://github.com/horaceho/chat-demo/commit/0e99f41c5fef792d905506feffe0d5243c12bfb6 and re-run the demo.

Pusher is connected:

Screen 2020-02-14 at 10 52 18

However, new message only shows up after manual refresh page (pressing Cmd-R, 1 & 2 are shown), the new message (e.g. enter 3 and click Send) does not show up in own window:

Screen 2020-02-14 at 10 54 01

or remote window:

Screen 2020-02-14 at 10 54 03

Any suggestion?

Originally posted by @horaceho in https://github.com/musonza/chat-demo/issues/15#issuecomment-586076233

williambeeler commented 4 years ago

I'm also having this problem. I had it with another attempt at a chat system with Laravel/pusher as well.

byronCoetzee commented 4 years ago

same issue for me - using laravel 7 and php server 7.4.4

micos7 commented 4 years ago

Got it to work - in the enablePusher function I use

window.Echo.private(`mc-chat-conversation.${this.conversation}`)
                    .listen(".Musonza\\Chat\\Eventing\\MessageWasSent", (e) => {
                        console.log(e)
                        this.messages.data.push(e.message);
                    })

Or you could use broadcastAs() function on the events in the Eventing folder and name them as you like. Dont forget the dot.

Echo config in bootstrap.js

window.Echo = new Echo({
  broadcaster: 'pusher',
  key: process.env.MIX_PUSHER_APP_KEY,
  cluster: process.env.MIX_PUSHER_APP_CLUSTER,
  wsHost: window.location.hostname,
  wssHost: window.location.hostname,
  wsPort: 6001,
  wssPort: 6001,
  encrypted: false,
    enabledTransports: ['ws','wss'],
});

I`m using https://github.com/beyondcode/laravel-websockets

cvlug commented 3 years ago

The same problem here: followed the instructions of horaceho@0e99f41 and re-run the demo Messages are succesfully send to pusher.com. However, new message only shows up after manual refresh page. The fix of micos7 does not solve the problem, but causes this error: "VM401:1 POST http://127.0.0.1:8000/broadcasting/auth 403 (Forbidden)"

How to make the demo work?