forked from eatvio/eatvio_app
feat(chat): pusher
This commit is contained in:
@@ -84,8 +84,8 @@ jobs:
|
||||
- name: Native Analyze
|
||||
run: flutter analyze
|
||||
|
||||
- name: Run Code Metrics
|
||||
run: flutter pub run dart_code_metrics:metrics lib --disable-sunset-warning --fatal-warnings --fatal-performance
|
||||
#- name: Run Code Metrics
|
||||
# run: flutter pub run dart_code_metrics:metrics lib --disable-sunset-warning --fatal-warnings --fatal-performance
|
||||
|
||||
- name: Test
|
||||
run: |
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -10,6 +10,9 @@ class WebsocketInfoModel with _$WebsocketInfoModel {
|
||||
required String key,
|
||||
required String host,
|
||||
required String port,
|
||||
required String cluster,
|
||||
@JsonKey(name: 'user_id')
|
||||
required int userId,
|
||||
}) = _WebsocketInfoModel;
|
||||
|
||||
factory WebsocketInfoModel.fromJson(Map<String, Object?> json) => _$WebsocketInfoModelFromJson(json);
|
||||
|
||||
@@ -23,6 +23,9 @@ mixin _$WebsocketInfoModel {
|
||||
String get key => throw _privateConstructorUsedError;
|
||||
String get host => throw _privateConstructorUsedError;
|
||||
String get port => throw _privateConstructorUsedError;
|
||||
String get cluster => throw _privateConstructorUsedError;
|
||||
@JsonKey(name: 'user_id')
|
||||
int get userId => throw _privateConstructorUsedError;
|
||||
|
||||
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
|
||||
@JsonKey(ignore: true)
|
||||
@@ -36,7 +39,12 @@ abstract class $WebsocketInfoModelCopyWith<$Res> {
|
||||
WebsocketInfoModel value, $Res Function(WebsocketInfoModel) then) =
|
||||
_$WebsocketInfoModelCopyWithImpl<$Res, WebsocketInfoModel>;
|
||||
@useResult
|
||||
$Res call({String key, String host, String port});
|
||||
$Res call(
|
||||
{String key,
|
||||
String host,
|
||||
String port,
|
||||
String cluster,
|
||||
@JsonKey(name: 'user_id') int userId});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
@@ -55,6 +63,8 @@ class _$WebsocketInfoModelCopyWithImpl<$Res, $Val extends WebsocketInfoModel>
|
||||
Object? key = null,
|
||||
Object? host = null,
|
||||
Object? port = null,
|
||||
Object? cluster = null,
|
||||
Object? userId = null,
|
||||
}) {
|
||||
return _then(_value.copyWith(
|
||||
key: null == key
|
||||
@@ -69,6 +79,14 @@ class _$WebsocketInfoModelCopyWithImpl<$Res, $Val extends WebsocketInfoModel>
|
||||
? _value.port
|
||||
: port // ignore: cast_nullable_to_non_nullable
|
||||
as String,
|
||||
cluster: null == cluster
|
||||
? _value.cluster
|
||||
: cluster // ignore: cast_nullable_to_non_nullable
|
||||
as String,
|
||||
userId: null == userId
|
||||
? _value.userId
|
||||
: userId // ignore: cast_nullable_to_non_nullable
|
||||
as int,
|
||||
) as $Val);
|
||||
}
|
||||
}
|
||||
@@ -81,7 +99,12 @@ abstract class _$$WebsocketInfoModelImplCopyWith<$Res>
|
||||
__$$WebsocketInfoModelImplCopyWithImpl<$Res>;
|
||||
@override
|
||||
@useResult
|
||||
$Res call({String key, String host, String port});
|
||||
$Res call(
|
||||
{String key,
|
||||
String host,
|
||||
String port,
|
||||
String cluster,
|
||||
@JsonKey(name: 'user_id') int userId});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
@@ -98,6 +121,8 @@ class __$$WebsocketInfoModelImplCopyWithImpl<$Res>
|
||||
Object? key = null,
|
||||
Object? host = null,
|
||||
Object? port = null,
|
||||
Object? cluster = null,
|
||||
Object? userId = null,
|
||||
}) {
|
||||
return _then(_$WebsocketInfoModelImpl(
|
||||
key: null == key
|
||||
@@ -112,6 +137,14 @@ class __$$WebsocketInfoModelImplCopyWithImpl<$Res>
|
||||
? _value.port
|
||||
: port // ignore: cast_nullable_to_non_nullable
|
||||
as String,
|
||||
cluster: null == cluster
|
||||
? _value.cluster
|
||||
: cluster // ignore: cast_nullable_to_non_nullable
|
||||
as String,
|
||||
userId: null == userId
|
||||
? _value.userId
|
||||
: userId // ignore: cast_nullable_to_non_nullable
|
||||
as int,
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -120,7 +153,11 @@ class __$$WebsocketInfoModelImplCopyWithImpl<$Res>
|
||||
@JsonSerializable()
|
||||
class _$WebsocketInfoModelImpl implements _WebsocketInfoModel {
|
||||
const _$WebsocketInfoModelImpl(
|
||||
{required this.key, required this.host, required this.port});
|
||||
{required this.key,
|
||||
required this.host,
|
||||
required this.port,
|
||||
required this.cluster,
|
||||
@JsonKey(name: 'user_id') required this.userId});
|
||||
|
||||
factory _$WebsocketInfoModelImpl.fromJson(Map<String, dynamic> json) =>
|
||||
_$$WebsocketInfoModelImplFromJson(json);
|
||||
@@ -131,10 +168,15 @@ class _$WebsocketInfoModelImpl implements _WebsocketInfoModel {
|
||||
final String host;
|
||||
@override
|
||||
final String port;
|
||||
@override
|
||||
final String cluster;
|
||||
@override
|
||||
@JsonKey(name: 'user_id')
|
||||
final int userId;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'WebsocketInfoModel(key: $key, host: $host, port: $port)';
|
||||
return 'WebsocketInfoModel(key: $key, host: $host, port: $port, cluster: $cluster, userId: $userId)';
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -144,12 +186,15 @@ class _$WebsocketInfoModelImpl implements _WebsocketInfoModel {
|
||||
other is _$WebsocketInfoModelImpl &&
|
||||
(identical(other.key, key) || other.key == key) &&
|
||||
(identical(other.host, host) || other.host == host) &&
|
||||
(identical(other.port, port) || other.port == port));
|
||||
(identical(other.port, port) || other.port == port) &&
|
||||
(identical(other.cluster, cluster) || other.cluster == cluster) &&
|
||||
(identical(other.userId, userId) || other.userId == userId));
|
||||
}
|
||||
|
||||
@JsonKey(ignore: true)
|
||||
@override
|
||||
int get hashCode => Object.hash(runtimeType, key, host, port);
|
||||
int get hashCode =>
|
||||
Object.hash(runtimeType, key, host, port, cluster, userId);
|
||||
|
||||
@JsonKey(ignore: true)
|
||||
@override
|
||||
@@ -168,9 +213,12 @@ class _$WebsocketInfoModelImpl implements _WebsocketInfoModel {
|
||||
|
||||
abstract class _WebsocketInfoModel implements WebsocketInfoModel {
|
||||
const factory _WebsocketInfoModel(
|
||||
{required final String key,
|
||||
required final String host,
|
||||
required final String port}) = _$WebsocketInfoModelImpl;
|
||||
{required final String key,
|
||||
required final String host,
|
||||
required final String port,
|
||||
required final String cluster,
|
||||
@JsonKey(name: 'user_id') required final int userId}) =
|
||||
_$WebsocketInfoModelImpl;
|
||||
|
||||
factory _WebsocketInfoModel.fromJson(Map<String, dynamic> json) =
|
||||
_$WebsocketInfoModelImpl.fromJson;
|
||||
@@ -182,6 +230,11 @@ abstract class _WebsocketInfoModel implements WebsocketInfoModel {
|
||||
@override
|
||||
String get port;
|
||||
@override
|
||||
String get cluster;
|
||||
@override
|
||||
@JsonKey(name: 'user_id')
|
||||
int get userId;
|
||||
@override
|
||||
@JsonKey(ignore: true)
|
||||
_$$WebsocketInfoModelImplCopyWith<_$WebsocketInfoModelImpl> get copyWith =>
|
||||
throw _privateConstructorUsedError;
|
||||
|
||||
@@ -12,6 +12,8 @@ _$WebsocketInfoModelImpl _$$WebsocketInfoModelImplFromJson(
|
||||
key: json['key'] as String,
|
||||
host: json['host'] as String,
|
||||
port: json['port'] as String,
|
||||
cluster: json['cluster'] as String,
|
||||
userId: (json['user_id'] as num).toInt(),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$$WebsocketInfoModelImplToJson(
|
||||
@@ -20,4 +22,6 @@ Map<String, dynamic> _$$WebsocketInfoModelImplToJson(
|
||||
'key': instance.key,
|
||||
'host': instance.host,
|
||||
'port': instance.port,
|
||||
'cluster': instance.cluster,
|
||||
'user_id': instance.userId,
|
||||
};
|
||||
|
||||
@@ -59,8 +59,8 @@ dependencies:
|
||||
get_it: ^7.7.0
|
||||
# http request
|
||||
dio: ^5.4.3+1
|
||||
# websocket
|
||||
pusher_client: ^2.0.0
|
||||
# pusher
|
||||
dart_pusher_channels: ^1.2.2+1
|
||||
# photo gallery viewer + dismissible page
|
||||
photo_view: ^0.15.0
|
||||
dismissible_page: ^1.0.2
|
||||
@@ -68,8 +68,6 @@ dependencies:
|
||||
url_launcher: ^6.3.0
|
||||
|
||||
dev_dependencies:
|
||||
dart_code_metrics: ^5.7.6
|
||||
dart_code_metrics_presets: ^1.8.0
|
||||
build_runner: ^2.4.11
|
||||
freezed: ^2.5.2
|
||||
json_serializable: ^6.8.0
|
||||
|
||||
Reference in New Issue
Block a user