kerimamansaryyev / dart_pusher_channels

MIT License
44 stars 12 forks source link

How do i listen to whispers? #3

Closed YassineChe closed 2 years ago

YassineChe commented 2 years ago

Hello, @mcfugger

Is there is anyway to listen to Whispers? Cuz i can see 'em in log but i couldn't catch 'em on 'events' !!

Log by default set to enable, and there's no such way to disable it, will be nice to add an attribute like enableLogs: false

Thank you

kerimamansaryyev commented 2 years ago

Hello, @YassineChe. I will make printing the logs optional Tomorrow with a new version.

Shame on me, but I didn't get the meaning of Whispers. Do you mean Pusher's default events, like event: connection_established?

kerimamansaryyev commented 2 years ago

By this 3 things I can do it as soon as possible:

  1. Example log of Whisper.
  2. Sample portion of your code where you try to listen Whisper.
  3. Some brief explanation of what is Whisper because I haven't find anything in Pusher's official docs. There are few Stack Overflow questions, but I still don't separate it from other events.
YassineChe commented 2 years ago

@mcfugger, Thanks for quick reply, whisper event is only a client to client, for example when two users connected to the same channel you can broadcast an event

Here a snapshot for Laravel Echo. This is an example if user start typing.. You can broadcast event (client to client) that' you start typing

this.channel.listen(".sent-message", (e) => {
    if (
        this.conversation?.with_user?.id ==
            e.from &&
        this.conversation?.id ==
            e.conversation_id
    ) {
        //? Push the flow
        this.conversation?.chatflows.push(e);
    }
})
.listenForWhisper("typing", () => {
    this.isTyping = true;
})
.listenForWhisper("stop-typing", () => {
    this.isTyping = false;
});

Mobile log: I/flutter (26648): {"event":"client-typing","channel":"private-private.message.1"}

Its successfully received in library log

But i can catch it

privateChannelEventSubscription = channel?.bind('sent-message').listen(
  (event) {
    // I can't catch it here
  },
);

Thanks

kerimamansaryyev commented 2 years ago

You should bind to the whisper as if you'd bind to a separate event because method bind filters stream of the channel and gives you all events with name sent-message in your code. So here you bind to the whisper with name client-typing as to a separate event of your channel:

whisperClientTypeEventSubscription = channel?.bind('client-typing').listen(
  (event) {
    // Catch it!
  },
);

Both streams subscriptions will keep receiving their events, no worry.

kerimamansaryyev commented 2 years ago

As I understood from Pusher Client docs, the client side does not separate whispers from other events of a channel. So, the above code I provided should work.

Please, inform me if this could help you. I will be available tomorrow (Tuesday, August 2). I am going to have a sleep.

kerimamansaryyev commented 2 years ago

You should bind to the whisper as if you'd bind to a separate event because method bind filters stream of the channel and gives you all events with name sent-message in your code. So here you bind to the whisper with name client-typing as to a separate event of your channel:

whisperClientTypeEventSubscription = channel?.bind('client-typing').listen(
  (event) {
    // Catch it!
  },
);

Both streams subscriptions will keep receiving their events, no worry.

@YassineChe did it help you?

YassineChe commented 2 years ago

Hello @mcfugger,

It worked! Thanks <3

kerimamansaryyev commented 2 years ago

You are welcome! I will open another issue about enabling/disabling logs. Will do it soon, today was pretty hectic.

YassineChe commented 2 years ago

Not a urgent! Thanks for this great Lib again