To create a real-time chat system for my flutter app, I am using Laravel Echo and Pusher Client. Unfortunately, even though I have included every configuration into my application, I am still not receiving a response from the pusher.
Laravel Echo Configuration in Flutter
class LaravelEcho {
static LaravelEcho? _singleton;
static late Echo _echo;
final String token;
LaravelEcho._({
required this.token,
}) {
_echo = createLaravelEcho(token);
}
factory LaravelEcho.init({
required String token,
}) {
if (_singleton == null || token != _singleton?.token) {
_singleton = LaravelEcho._(token: token);
}
return _singleton!;
}
static Echo get instance => _echo;
static String get socketId => _echo.socketId() ?? "11111.11111111";
}
class PusherConfig {
static const appId = "13***69";
static const key = "e0131******a186b1d";
static const secret = "46de951******14b205";
static const cluster = "mt1";
static const hostEndPoint = RemoteUrls.baseUrl;
static const hostAuthEndPoint = "${hostEndPoint}broadcasting/auth";
static const port = 6001;
}
PusherClient createPusherClient(String token) {
PusherOptions options = PusherOptions(
wsPort: PusherConfig.port,
encrypted: true,
host: PusherConfig.hostEndPoint,
cluster: PusherConfig.cluster,
auth: PusherAuth(
PusherConfig.hostAuthEndPoint,
headers: {
'Authorization': "Bearer $token",
'Content-Type': "application/json",
'Accept': 'application/json'
},
),
);
PusherClient pusherClient = PusherClient(
PusherConfig.key,
options,
autoConnect: false,
enableLogging: true,
);
return pusherClient;
}
Echo createLaravelEcho(String token) {
return Echo(
client: createPusherClient(token),
broadcaster: EchoBroadcasterType.Pusher,
);
}
Trying to listen like way
try {
LaravelEcho.instance
.channel('chat.${widget.recentChat.participants.first.inboxId}')
.listen('.chat-message', (e) {
print("laravel echo success: $e");
if (e is PusherEvent) {
if (e.data != null) {
vLog(jsonDecode(e.data!));
_handleNewMessage(jsonDecode(e.data!));
}
}
}).error((err) {
eLog(err);
print("laravel echo error: $err");
});
} catch (e) {
print("err: $e");
}
Console log error
com.pusher.client.AuthorizationFailureException: java.io.FileNotFoundException: https://baseUrl.com/broadcasting/auth
at com.pusher.client.util.HttpAuthorizer.authorize(HttpAuthorizer.java:146)
W/System.err(21922): at com.pusher.client.channel.impl.PrivateChannelImpl.getAuthResponse(PrivateChannelImpl.java:130)
W/System.err(21922): at com.pusher.client.channel.impl.PrivateChannelImpl.toSubscribeMessage(PrivateChannelImpl.java:90)
W/System.err(21922): at com.pusher.client.channel.impl.ChannelManager$1.run(ChannelManager.java:149)
W/System.err(21922): at com.pusher.client.util.Factory$1.run(Factory.java:119)
W/System.err(21922): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
W/System.err(21922): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
W/System.err(21922): at java.lang.Thread.run(Thread.java:920)
Caused by: java.io.FileNotFoundException: https://lsaeducation.com/broadcasting/auth
W/System.err(21922): at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:255)
W/System.err(21922): at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getInputStream(DelegatingHttpsURLConnection.java:211)
W/System.err(21922): at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:30)
W/System.err(21922): at com.pusher.client.util.HttpAuthorizer.authorize(HttpAuthorizer.java:128)
W/System.err(21922): ... 7 more
D/PusherClientPlugin(21922): [ON_ERROR]: message: Connection not authorized within timeout, code: 4009
D/PusherClientPlugin(21922): [DISCONNECTING]
D/PusherClientPlugin(21922): [DISCONNECTED]
How might this problem be resolved? Any advice or suggestions on how to solve this would be greatly appreciated. Thank you