Integration of Laravel Reverb with Flutter Mobile App WebSocket #51766
-
Description: Specifically, I'd like guidance on: Setting up WebSocket connection handling in Flutter. |
Beta Was this translation helpful? Give feedback.
Replies: 8 comments 17 replies
-
Have you find any solution |
Beta Was this translation helpful? Give feedback.
-
I use this https://pub.dev/packages/dart_pusher_channels. The only one maintained well so far according to my research. Couldn't get to work with private channels though. Public channels does work however. |
Beta Was this translation helpful? Give feedback.
-
did anyone find solution for that ? |
Beta Was this translation helpful? Give feedback.
-
You can use web_socket_channel. |
Beta Was this translation helpful? Give feedback.
-
please i need help on this also |
Beta Was this translation helpful? Give feedback.
-
What about on android, what's the best library I can use? |
Beta Was this translation helpful? Give feedback.
-
I also have this problem for a long time. This is how I was able to make it work using I added the following in my ...
->withBroadcasting(
channels: __DIR__ . '/../routes/channels.php',
attributes: ['prefix' => 'api', 'middleware' => ['auth:sanctum']],
)
... Then did this in flutter. import 'dart:async';
import 'package:dart_pusher_channels/dart_pusher_channels.dart';
Future<void> connect() async {
const hostOptions = PusherChannelsOptions.fromHost(
scheme: 'ws',
host: '192.168.1.2',
key: '<YOUR REVERB KEY>',
shouldSupplyMetadataQueries: true,
metadata: PusherChannelsOptionsMetadata.byDefault(),
port: 8080,
);
final client = PusherChannelsClient.websocket(
options: hostOptions,
connectionErrorHandler: (exception, trace, refresh) {
refresh();
});
final channel = client.publicChannel(
'user.5.wallet',
);
final private = client.privateChannel(
'private-App.Models.User.5',
authorizationDelegate:
EndpointAuthorizableChannelTokenAuthorizationDelegate.forPrivateChannel(
authorizationEndpoint: Uri.parse('http://192.168.1.2:8000/api/broadcasting/auth'),
headers: const {
'Authorization': 'Bearer <USER SANCTUM TOKEN>',
},
),
);
StreamSubscription<ChannelReadEvent> channelSubscription =
channel.bind('App\\Events\\WalletUpdatedEvent').listen((event) {
print('Event received: ${event.data}');
});
StreamSubscription<ChannelReadEvent> privateSubscription =
private.bind('App\\Events\\WalletUpdatedEvent').listen((event) {
print('Private event received: ${event.data}');
});
client.onConnectionEstablished.listen((s) {
print('Connection established');
channel.subscribe();
private.subscribe();
});
await client.connect();
} |
Beta Was this translation helpful? Give feedback.
-
I am using Sanctum.
…On Fri, Nov 22, 2024 at 12:06 PM musibaforreal ***@***.***> wrote:
@jbeduya <https://github.com/jbeduya> what form authorization were you
using for the private channels were you using laravel sanctum tokens or any
other forms of auth
—
Reply to this email directly, view it on GitHub
<#51766 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AALXSAO5XL5SW5Z5K2E7NMD2B2UT7AVCNFSM6AAAAABJD3A7BSVHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTCMZUGQYTKNQ>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
You can use web_socket_channel.