feat(chat): pusher

This commit is contained in:
mso7nueh
2024-07-01 16:08:43 +03:00
parent 70296bc485
commit c9c8883e01
6 changed files with 114 additions and 39 deletions

View File

@@ -2,7 +2,6 @@ import 'package:eatvio_app/core/app_export.dart';
import 'package:eatvio_app/core/initialization_cubit/initialization_state.dart';
import 'package:eatvio_app/core/token_storage.dart';
import 'package:eatvio_app/features/chat/repositories/chat_repository.dart';
import 'package:pusher_client/pusher_client.dart';
class InitializationCubit extends Cubit<InitializationState> {
final ChatRepository chatRepository;
@@ -12,29 +11,47 @@ class InitializationCubit extends Cubit<InitializationState> {
runInitialization() async {
try {
await TokenStorage.haveTokenInStorage();
final wsUrl = await chatRepository.getWebsocket();
PusherOptions options = PusherOptions(
host: 'socket.mobile-stage.eatvio.ru',
wsPort: 443,
encrypted: true,
auth: PusherAuth(
'wss://' + wsUrl.host + '/app/' + wsUrl.key,
headers: {
'Authorization': 'Bearer ${await TokenStorage.getTokenFromStorage()}',
},
),
);
PusherClient pusherClient = await PusherClient(
wsUrl.key,
options,
autoConnect: true,
enableLogging: true,
);
await pusherClient.connect();
// final wsUrl = await chatRepository.getWebsocket();
// final options = PusherChannelsOptions.fromHost(
// scheme: 'wss',
// key: wsUrl.key,
// host: wsUrl.host,
// shouldSupplyMetadataQueries: true,
// metadata: PusherChannelsOptionsMetadata.byDefault(),
// port: 443,
// );
// final client = PusherChannelsClient.websocket(
// options: options,
// connectionErrorHandler: (exception, trace, refresh) {
// refresh();
// },
// minimumReconnectDelayDuration: const Duration(
// seconds: 1,
// ),
// defaultActivityDuration: const Duration(
// seconds: 120,
// ),
// activityDurationOverride: const Duration(
// seconds: 120,
// ),
// waitForPongDuration: const Duration(
// seconds: 30,
// ),
// );
// await client.connect();
// final myPrivateChannel = client.privateChannel(
// 'private-message-events.${wsUrl.userId}',
// authorizationDelegate: EndpointAuthorizableChannelTokenAuthorizationDelegate.forPrivateChannel(
// authorizationEndpoint: Uri.parse('https://mobile-stage.eatvio.ru/broadcasting/auth'),
// headers: {
// 'Authorization' : 'Bearer ${await TokenStorage.getTokenFromStorage()}',
// },
// ),
// );
// myPrivateChannel.subscribe();
// myPrivateChannel.bindToAll().listen((event) {
// print(event.name);
// });
emit(const InitializationState.success());
} catch (e) {
print(e);