Closed zahid--ali closed 6 years ago
Thanks ! I will update the README for adding examples. But you can use the doc of the offcial Laravel Echo lib in JavaScript (https://github.com/laravel/echo). I've just translated the JS code in Java, it's the same function names as the JS version.
@MrBin99 you did great work I am using your library. Can you please let me know how to broadcast to a presence channel.
Use like this :
EchoOptions options = new EchoOptions();
options.host = "your-host:port";
// Add header(s) to authenticate your user : like a Bearer token
options.headers.put("", "");
Echo echo = new Echo(options);
echo.connect(new EchoCallback() {
@Override
public void call(Object... args) {
// Success connect
}
}, new EchoCallback() {
@Override
public void call(Object... args) {
// Error connect
}
});
/*
* When calling presenceChannel, this will automatically subscribe to this
* channel and broadcasting your presence in it according to headers
* placed in options above.
*/
SocketIOPresenceChannel channel = echo.presenceChannel("channel-name");
channel.here(new EchoCallback() {
@Override
public void call(Object... args) {
// When list of user in this channel change.
}
})
.leaving(new EchoCallback() {
@Override
public void call(Object... args) {
// When someone leaving the channel.
}
})
.joining(new EchoCallback() {
@Override
public void call(Object... args) {
// When someone joining the channel.
}
});
// Use this to quit the channel
echo.leave("channel-name");
/*
* Or you can disconnect the socket, to automatically unsubscribe
* this client on all channels you subscribed (private, public and presence).
*/
echo.disconnect();
You can refer to the Laravel official doc (https://laravel.com/docs/5.6/broadcasting#broadcasting-to-presence-channels), my library is just code ported from Javascript to Java.
Hi MrBin99, Hope you are well. I am using laravel echo server with redis for broadcasting event in laravel. I successfully implemented and deployed on aws. It's working fine on web application for private chat. For android side we are using LaravelEchoAndroid. Accroding to above replies it work like laravel echo. Laravel echo is just client side receiving. Android app listening events broadcast by laravel like web app but not broadcasting event from android side, although user is joined private channel successfully. Could you please guide us where are doing mistake? Thanks in advance
Hi, If I understand well, you have an application Web and an Android app. On the Web everything is fine, on Android the app is receiving events but not broadcasting events. That's right ?
Hello, Exactly.
Ok, it's very weird because if your Android app is joining private channels, broadcasting events from Android is working. Can you show me the piece of code you've wrote to broadcast events from Android.
privateChannel.whisper(WebConstants.KEY_MESSAGE_EVENT, data, new EchoCallback() { @Override public void call(Object... args) { // Whisper received Log.e(TAG, "message_sent" + args.toString()); } });
Sorry first i mixed code. This is event broadcast code.
Are you connected to the channel when you send this message ? Maybe you send the message to early. Do you have a log on your Echo server or on redis saying that a message has been sent ?
Yes i continuously observed joined channel log from laravel echo server. When i broadcast event from web it show me following detail.
[4:01:21 PM] - 06y1xvMZ_P8HEYhAAAAO authenticated for: private-messages.41 [4:01:21 PM] - 06y1xvMZ_P8HEYhAAAAO joined channel: private-messages.41 Channel: private-messages.45 Event: App\Events\NewMessage
When joined from android app. It show following detail.
[7:13:42 PM] - Sending auth request to: https://domain/api/broadcasting/auth
[7:13:42 PM] - oyLT3qMZQpIq-5UEAAAO authenticated for: private-messages.4 [7:13:42 PM] - oyLT3qMZQpIq-5UEAAAO joined channel: private-messages.4
Ok but on Android are you sure you are connected to the channel before you whisper things ?
Can you show me what you have in this variable WebConstants.KEY_MESSAGE_EVENT
Yes i am sure after connected to channel i broadcast event. Actually i saw the log then send broadcast event.
Event Name: WebConstants.KEY_MESSAGE_EVENT = NewMessage
I think I found your problem, whispering does not correspond to Laravel broadcasting events. Whispering correspond to sending directly websockets messages to users in this channel. I think it's normal that it will not appear on logs. If you want to send Laravel events you need to call an API endpoint of your Laravel app that propagate this event on the channel.
Ok. I appreciate your technical help. Thanks
Hey Dear,
Can you help me implement this in android? I got message callback but I don't understand how to send a message in this channel and make a successful conversation. and I am confused in channel flow. how does it work?
Hi Dear,
I can help you for successful implementation of laravel echo with Android app.
Thanks
On Wed, May 29, 2019, 5:00 PM ankurbhut notifications@github.com wrote:
Hey Dear,
Can you help me implement this in android? I got message callback but I don't understand how to send a message in this channel and make a successful conversation. and I am confused in channel flow. how does it work?
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/MrBin99/LaravelEchoAndroid/issues/1?email_source=notifications&email_token=ALZSRIVT5H6GEL6VDUEQTCLPXZV65A5CNFSM4E7FWSU2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODWPDCXY#issuecomment-496906591, or mute the thread https://github.com/notifications/unsubscribe-auth/ALZSRIUYNK7U6TUQHTAMC2DPXZV65ANCNFSM4E7FWSUQ .
Do you have examples of implementation? if yes then please share with me. I will be thankful for help.
I don't have separate example. I can share links that i followed for laravel echo server. Android app use api to broadcast message.
Thanks
On Thu, May 30, 2019, 9:47 AM ankurbhut notifications@github.com wrote:
Do you have examples of implementation? if yes then please share with me. I will be thankful for help.
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/MrBin99/LaravelEchoAndroid/issues/1?email_source=notifications&email_token=ALZSRITBWV5GGCAXSUOG3TLPX5L7DA5CNFSM4E7FWSU2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODWRK6EQ#issuecomment-497200914, or mute the thread https://github.com/notifications/unsubscribe-auth/ALZSRIVOPNYOWHR4ILH5VGLPX5L7DANCNFSM4E7FWSUQ .
Okay, No Problem Please share a link so I can check that.
Hey @MrBin99, Great work. I am looking for something exactly like this. Can you please post an example project so that I can use this library in my project? Thanks