val-bubbleflat / laravel-echo-ios

A wrapper for Laravel Echo in Swift
MIT License
22 stars 17 forks source link

Laravel echo Whisper()/listenForWhisper() #9

Open nielsezeka opened 5 years ago

nielsezeka commented 5 years ago

I follow the docs that lead me to :"See full Echo documentation for all available methods" So the Echo documentation i want to use the broadcast in room by using Whisper function. I checked and it completely existed in code. But when i try to broadcast by:

guard let channelEmit = channel as? IPrivateChannel else{ return } channelEmit.whisper(eventName: "xxxx", data: [])

Actually packet was emit to the server as the socketio log recorded. So i can make sure this function called and it actually send some data to server. But the problems is their is nothing received in another client(s) when i try to using listening code: _ = channel!.listenForWhisper(event: "xxxx", callback: { (data, ack) in print("received") })

So could you please help me on this problem? This repo support broadcast as Echo documentation describe?

nielsezeka commented 5 years ago

I found problems, 1- we need to set the broadcast channel name same with backend setting(their was an configuration about formatting name in server-side). In my case the name must be format "channel.xx" with "xx" is an int number(ex: "channel.1", "channel.2".....). 2- Another problem is: we need to listen by listen(event....)(i dont know why the listenForWhisper(..) not work). The event comes to you with format: "client-xxxx" with xxxx is your sending name. For your refer, my working code is: channel = self.echoLaravel.privateChannel(channel: "channel.1")

To send: guard let channelEmit = channel as? IPrivateChannel else{ return } channelEmit.whisper(eventName: "xxxx", data: []) To received _ = privateChannel.listen(event: "client-xxx", callback: { data, ack in ..... })

Hope these information helpful!