From c9281e0c89b6ed3f5188c64fa863da1cf41076e0 Mon Sep 17 00:00:00 2001 From: Sacha Arbonel Date: Thu, 4 Aug 2022 16:07:13 -0400 Subject: [PATCH 01/10] third party video integration --- melos.yaml | 4 +-- .../stream_chat/lib/src/client/client.dart | 13 +++++++ .../lib/src/core/api/call_api.dart | 28 +++++++++++++++ .../lib/src/core/api/stream_chat_api.dart | 6 ++++ .../lib/src/core/models/agora_payload.dart | 13 +++++++ .../lib/src/core/models/agora_payload.g.dart | 16 +++++++++ .../lib/src/core/models/call_payload.dart | 22 ++++++++++++ .../lib/src/core/models/call_payload.g.dart | 35 +++++++++++++++++++ .../src/core/models/call_token_payload.dart | 20 +++++++++++ .../src/core/models/call_token_payload.g.dart | 30 ++++++++++++++++ .../src/core/models/create_call_payload.dart | 18 ++++++++++ .../core/models/create_call_payload.g.dart | 17 +++++++++ .../lib/src/core/models/hms_payload.dart | 17 +++++++++ .../lib/src/core/models/hms_payload.g.dart | 18 ++++++++++ 14 files changed, 255 insertions(+), 2 deletions(-) create mode 100644 packages/stream_chat/lib/src/core/api/call_api.dart create mode 100644 packages/stream_chat/lib/src/core/models/agora_payload.dart create mode 100644 packages/stream_chat/lib/src/core/models/agora_payload.g.dart create mode 100644 packages/stream_chat/lib/src/core/models/call_payload.dart create mode 100644 packages/stream_chat/lib/src/core/models/call_payload.g.dart create mode 100644 packages/stream_chat/lib/src/core/models/call_token_payload.dart create mode 100644 packages/stream_chat/lib/src/core/models/call_token_payload.g.dart create mode 100644 packages/stream_chat/lib/src/core/models/create_call_payload.dart create mode 100644 packages/stream_chat/lib/src/core/models/create_call_payload.g.dart create mode 100644 packages/stream_chat/lib/src/core/models/hms_payload.dart create mode 100644 packages/stream_chat/lib/src/core/models/hms_payload.g.dart diff --git a/melos.yaml b/melos.yaml index 10e7ca7ba..3291c18ef 100644 --- a/melos.yaml +++ b/melos.yaml @@ -54,11 +54,11 @@ scripts: description: Build all generated files for Dart & Flutter packages in this project. generate:dart: - run: melos exec -c 1 --depends-on="build_runner" --no-flutter -- "dart run build_runner build --delete-conflicting-outputs" + run: melos exec -c 1 --depends-on="build_runner" --no-flutter -- "dart pub run build_runner build --delete-conflicting-outputs --enable-experiment=super-parameters,enhanced-enums" description: Build all generated files for Dart packages in this project. generate:flutter: - run: melos exec -c 1 --depends-on="build_runner" --flutter -- "flutter pub run build_runner build --delete-conflicting-outputs" + run: melos exec -c 1 --depends-on="build_runner" --flutter -- "flutter pub run build_runner build --delete-conflicting-outputs --enable-experiment=super-parameters,enhanced-enums" description: Build all generated files for Flutter packages in this project. test:all: diff --git a/packages/stream_chat/lib/src/client/client.dart b/packages/stream_chat/lib/src/client/client.dart index c29503771..4b0482a35 100644 --- a/packages/stream_chat/lib/src/client/client.dart +++ b/packages/stream_chat/lib/src/client/client.dart @@ -17,8 +17,10 @@ import 'package:stream_chat/src/core/http/stream_http_client.dart'; import 'package:stream_chat/src/core/http/token.dart'; import 'package:stream_chat/src/core/http/token_manager.dart'; import 'package:stream_chat/src/core/models/attachment_file.dart'; +import 'package:stream_chat/src/core/models/call_token_payload.dart'; import 'package:stream_chat/src/core/models/channel_model.dart'; import 'package:stream_chat/src/core/models/channel_state.dart'; +import 'package:stream_chat/src/core/models/create_call_payload.dart'; import 'package:stream_chat/src/core/models/event.dart'; import 'package:stream_chat/src/core/models/filter.dart'; import 'package:stream_chat/src/core/models/member.dart'; @@ -585,6 +587,17 @@ class StreamChatClient { } } + Future getCallToken(String callId) async => + _chatApi.call.getCallToken(callId); + + Future createCall( + String callId, + String callType, + Map? options, + ) async { + return _chatApi.call.createCall(callId, callType, options); + } + /// Requests channels with a given query from the API. Future> queryChannelsOnline({ Filter? filter, diff --git a/packages/stream_chat/lib/src/core/api/call_api.dart b/packages/stream_chat/lib/src/core/api/call_api.dart new file mode 100644 index 000000000..e2f767f59 --- /dev/null +++ b/packages/stream_chat/lib/src/core/api/call_api.dart @@ -0,0 +1,28 @@ +import 'package:stream_chat/src/core/http/stream_http_client.dart'; +import 'package:stream_chat/src/core/models/call_token_payload.dart'; +import 'package:stream_chat/src/core/models/create_call_payload.dart'; + +class CallApi { + /// Initialize a new call api + CallApi(this._client); + + final StreamHttpClient _client; + + Future getCallToken(String callId) async { + final response = await _client.post( + '/calls/$callId', + ); + return CallTokenPayload.fromJson(response.data); + } + + Future createCall( + String callId, + String callType, + Map? options, + ) async { + final response = await _client.post( + '/channels/$callType/$callId/call', + ); + return CreateCallPayload.fromJson(response.data); + } +} diff --git a/packages/stream_chat/lib/src/core/api/stream_chat_api.dart b/packages/stream_chat/lib/src/core/api/stream_chat_api.dart index cf6c0badd..c19b81a90 100644 --- a/packages/stream_chat/lib/src/core/api/stream_chat_api.dart +++ b/packages/stream_chat/lib/src/core/api/stream_chat_api.dart @@ -1,5 +1,6 @@ import 'package:logging/logging.dart'; import 'package:stream_chat/src/core/api/attachment_file_uploader.dart'; +import 'package:stream_chat/src/core/api/call_api.dart'; import 'package:stream_chat/src/core/api/channel_api.dart'; import 'package:stream_chat/src/core/api/device_api.dart'; import 'package:stream_chat/src/core/api/general_api.dart'; @@ -53,6 +54,11 @@ class StreamChatApi { /// Api dedicated to message operations MessageApi get message => _message ??= MessageApi(_client); + CallApi? _call; + + /// Api dedicated to guest operations + CallApi get call => _call ??= CallApi(_client); + ChannelApi? _channel; /// Api dedicated to channel operations diff --git a/packages/stream_chat/lib/src/core/models/agora_payload.dart b/packages/stream_chat/lib/src/core/models/agora_payload.dart new file mode 100644 index 000000000..35bc93b70 --- /dev/null +++ b/packages/stream_chat/lib/src/core/models/agora_payload.dart @@ -0,0 +1,13 @@ +import 'package:equatable/equatable.dart'; +import 'package:json_annotation/json_annotation.dart'; + +part 'agora_payload.g.dart'; + +@JsonSerializable(includeIfNull: false) +class AgoraPayload { + final String channel; + const AgoraPayload({required this.channel}); + + factory AgoraPayload.fromJson(Map json) => + _$AgoraPayloadFromJson(json); +} diff --git a/packages/stream_chat/lib/src/core/models/agora_payload.g.dart b/packages/stream_chat/lib/src/core/models/agora_payload.g.dart new file mode 100644 index 000000000..ff4df8438 --- /dev/null +++ b/packages/stream_chat/lib/src/core/models/agora_payload.g.dart @@ -0,0 +1,16 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'agora_payload.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +AgoraPayload _$AgoraPayloadFromJson(Map json) => AgoraPayload( + channel: json['channel'] as String, + ); + +Map _$AgoraPayloadToJson(AgoraPayload instance) => + { + 'channel': instance.channel, + }; diff --git a/packages/stream_chat/lib/src/core/models/call_payload.dart b/packages/stream_chat/lib/src/core/models/call_payload.dart new file mode 100644 index 000000000..7754e5bea --- /dev/null +++ b/packages/stream_chat/lib/src/core/models/call_payload.dart @@ -0,0 +1,22 @@ +import 'package:stream_chat/src/core/models/agora_payload.dart'; +import 'package:stream_chat/src/core/models/hms_payload.dart'; +import 'package:equatable/equatable.dart'; +import 'package:json_annotation/json_annotation.dart'; + +part 'call_payload.g.dart'; + +@JsonSerializable(includeIfNull: false) +class CallPayload extends Equatable { + final String id; + final String provider; + final AgoraPayload? agora; + final HMSPayload? hms; + + const CallPayload({required this.id, required this.provider, this.agora, this.hms}); + + factory CallPayload.fromJson(Map json) => + _$CallPayloadFromJson(json); + + @override + List get props => [id, provider, agora, hms]; +} diff --git a/packages/stream_chat/lib/src/core/models/call_payload.g.dart b/packages/stream_chat/lib/src/core/models/call_payload.g.dart new file mode 100644 index 000000000..f23cfb45e --- /dev/null +++ b/packages/stream_chat/lib/src/core/models/call_payload.g.dart @@ -0,0 +1,35 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'call_payload.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +CallPayload _$CallPayloadFromJson(Map json) => CallPayload( + id: json['id'] as String, + provider: json['provider'] as String, + agora: json['agora'] == null + ? null + : AgoraPayload.fromJson(json['agora'] as Map), + hms: json['hms'] == null + ? null + : HMSPayload.fromJson(json['hms'] as Map), + ); + +Map _$CallPayloadToJson(CallPayload instance) { + final val = { + 'id': instance.id, + 'provider': instance.provider, + }; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('agora', instance.agora?.toJson()); + writeNotNull('hms', instance.hms?.toJson()); + return val; +} diff --git a/packages/stream_chat/lib/src/core/models/call_token_payload.dart b/packages/stream_chat/lib/src/core/models/call_token_payload.dart new file mode 100644 index 000000000..520572d16 --- /dev/null +++ b/packages/stream_chat/lib/src/core/models/call_token_payload.dart @@ -0,0 +1,20 @@ +import 'package:equatable/equatable.dart'; +import 'package:json_annotation/json_annotation.dart'; + + + +part 'call_token_payload.g.dart'; + +@JsonSerializable(includeIfNull: false) +class CallTokenPayload extends Equatable { + final String token; + final int? agoraUid; + final String? agoraAppId; + const CallTokenPayload({required this.token, this.agoraUid, this.agoraAppId}); + + factory CallTokenPayload.fromJson(Map json) => + _$CallTokenPayloadFromJson(json); + + @override + List get props => [token, agoraAppId, agoraUid]; +} diff --git a/packages/stream_chat/lib/src/core/models/call_token_payload.g.dart b/packages/stream_chat/lib/src/core/models/call_token_payload.g.dart new file mode 100644 index 000000000..df8229205 --- /dev/null +++ b/packages/stream_chat/lib/src/core/models/call_token_payload.g.dart @@ -0,0 +1,30 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'call_token_payload.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +CallTokenPayload _$CallTokenPayloadFromJson(Map json) => + CallTokenPayload( + token: json['token'] as String, + agoraUid: json['agora_uid'] as int?, + agoraAppId: json['agora_app_id'] as String?, + ); + +Map _$CallTokenPayloadToJson(CallTokenPayload instance) { + final val = { + 'token': instance.token, + }; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('agora_uid', instance.agoraUid); + writeNotNull('agora_app_id', instance.agoraAppId); + return val; +} diff --git a/packages/stream_chat/lib/src/core/models/create_call_payload.dart b/packages/stream_chat/lib/src/core/models/create_call_payload.dart new file mode 100644 index 000000000..47711e2d9 --- /dev/null +++ b/packages/stream_chat/lib/src/core/models/create_call_payload.dart @@ -0,0 +1,18 @@ +import 'package:equatable/equatable.dart'; +import 'package:stream_chat/src/core/models/call_payload.dart'; +import 'package:equatable/equatable.dart'; +import 'package:json_annotation/json_annotation.dart'; + + +part 'create_call_payload.g.dart'; +@JsonSerializable(includeIfNull: false) +class CreateCallPayload extends Equatable { + final CallPayload call; + const CreateCallPayload({required this.call}); + + factory CreateCallPayload.fromJson(Map json) => + _$CreateCallPayloadFromJson(json); + + @override + List get props => [call]; +} diff --git a/packages/stream_chat/lib/src/core/models/create_call_payload.g.dart b/packages/stream_chat/lib/src/core/models/create_call_payload.g.dart new file mode 100644 index 000000000..3c8497978 --- /dev/null +++ b/packages/stream_chat/lib/src/core/models/create_call_payload.g.dart @@ -0,0 +1,17 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'create_call_payload.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +CreateCallPayload _$CreateCallPayloadFromJson(Map json) => + CreateCallPayload( + call: CallPayload.fromJson(json['call'] as Map), + ); + +Map _$CreateCallPayloadToJson(CreateCallPayload instance) => + { + 'call': instance.call.toJson(), + }; diff --git a/packages/stream_chat/lib/src/core/models/hms_payload.dart b/packages/stream_chat/lib/src/core/models/hms_payload.dart new file mode 100644 index 000000000..5d5e3e968 --- /dev/null +++ b/packages/stream_chat/lib/src/core/models/hms_payload.dart @@ -0,0 +1,17 @@ +import 'package:equatable/equatable.dart'; +import 'package:json_annotation/json_annotation.dart'; + +part 'hms_payload.g.dart'; + +@JsonSerializable(includeIfNull: false) +class HMSPayload extends Equatable { + final String roomId; + final String roomName; + const HMSPayload({required this.roomId, required this.roomName}); + + factory HMSPayload.fromJson(Map json) => + _$HMSPayloadFromJson(json); + + @override + List get props => [roomId, roomName]; +} diff --git a/packages/stream_chat/lib/src/core/models/hms_payload.g.dart b/packages/stream_chat/lib/src/core/models/hms_payload.g.dart new file mode 100644 index 000000000..3c55f56f3 --- /dev/null +++ b/packages/stream_chat/lib/src/core/models/hms_payload.g.dart @@ -0,0 +1,18 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'hms_payload.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +HMSPayload _$HMSPayloadFromJson(Map json) => HMSPayload( + roomId: json['room_id'] as String, + roomName: json['room_name'] as String, + ); + +Map _$HMSPayloadToJson(HMSPayload instance) => + { + 'room_id': instance.roomId, + 'room_name': instance.roomName, + }; From 570e6e05cfc3cc768a797ef1ef4324fe22666ded Mon Sep 17 00:00:00 2001 From: Sacha Arbonel Date: Thu, 11 Aug 2022 11:33:52 -0400 Subject: [PATCH 02/10] fix llc --- melos.yaml | 4 +-- .../stream_chat/lib/src/client/client.dart | 18 ++++++++---- .../lib/src/core/api/call_api.dart | 28 +++++++++++++------ .../lib/src/core/models/agora_payload.dart | 4 ++- .../lib/src/core/models/call_payload.dart | 7 +++-- .../lib/src/core/models/call_payload.g.dart | 23 +++++---------- .../src/core/models/call_token_payload.dart | 5 +++- .../src/core/models/call_token_payload.g.dart | 21 ++++---------- .../src/core/models/create_call_payload.dart | 6 ++-- .../lib/src/core/models/hms_payload.dart | 4 ++- packages/stream_chat/lib/stream_chat.dart | 6 ++++ 11 files changed, 72 insertions(+), 54 deletions(-) diff --git a/melos.yaml b/melos.yaml index 3291c18ef..fbbfcb78e 100644 --- a/melos.yaml +++ b/melos.yaml @@ -54,11 +54,11 @@ scripts: description: Build all generated files for Dart & Flutter packages in this project. generate:dart: - run: melos exec -c 1 --depends-on="build_runner" --no-flutter -- "dart pub run build_runner build --delete-conflicting-outputs --enable-experiment=super-parameters,enhanced-enums" + run: melos exec -c 1 --depends-on="build_runner" --no-flutter -- "dart run build_runner build --delete-conflicting-outputs --enable-experiment=super-parameters,enhanced-enums" description: Build all generated files for Dart packages in this project. generate:flutter: - run: melos exec -c 1 --depends-on="build_runner" --flutter -- "flutter pub run build_runner build --delete-conflicting-outputs --enable-experiment=super-parameters,enhanced-enums" + run: melos exec -c 1 --depends-on="build_runner" --flutter -- "flutter run build_runner build --delete-conflicting-outputs --enable-experiment=super-parameters,enhanced-enums" description: Build all generated files for Flutter packages in this project. test:all: diff --git a/packages/stream_chat/lib/src/client/client.dart b/packages/stream_chat/lib/src/client/client.dart index 4b0482a35..ea221701f 100644 --- a/packages/stream_chat/lib/src/client/client.dart +++ b/packages/stream_chat/lib/src/client/client.dart @@ -590,12 +590,20 @@ class StreamChatClient { Future getCallToken(String callId) async => _chatApi.call.getCallToken(callId); - Future createCall( - String callId, - String callType, + Future createCall({ + required String callId, + required String callType, + required String channelType, + required String channelId, Map? options, - ) async { - return _chatApi.call.createCall(callId, callType, options); + }) async { + return _chatApi.call.createCall( + callId: callId, + callType: callType, + options: options, + channelType: channelType, + channelId: channelId, + ); } /// Requests channels with a given query from the API. diff --git a/packages/stream_chat/lib/src/core/api/call_api.dart b/packages/stream_chat/lib/src/core/api/call_api.dart index e2f767f59..6c5428487 100644 --- a/packages/stream_chat/lib/src/core/api/call_api.dart +++ b/packages/stream_chat/lib/src/core/api/call_api.dart @@ -11,18 +11,28 @@ class CallApi { Future getCallToken(String callId) async { final response = await _client.post( '/calls/$callId', + data: {}, ); - return CallTokenPayload.fromJson(response.data); + // return response.data; + return CallTokenPayload.fromJson(response.data); } - Future createCall( - String callId, - String callType, + Future createCall({ + required String callId, + required String callType, + required String channelType, + required String channelId, Map? options, - ) async { - final response = await _client.post( - '/channels/$callType/$callId/call', - ); - return CreateCallPayload.fromJson(response.data); + }) async { + final response = + await _client.post(_getChannelUrl(channelId, channelType), data: { + 'id': '$callId', + 'type': '$callType', + }); + // return response.data; + return CreateCallPayload.fromJson(response.data); } + + String _getChannelUrl(String channelId, String channelType) => + '/channels/$channelType/$channelId/call'; } diff --git a/packages/stream_chat/lib/src/core/models/agora_payload.dart b/packages/stream_chat/lib/src/core/models/agora_payload.dart index 35bc93b70..c70ffe0b4 100644 --- a/packages/stream_chat/lib/src/core/models/agora_payload.dart +++ b/packages/stream_chat/lib/src/core/models/agora_payload.dart @@ -3,11 +3,13 @@ import 'package:json_annotation/json_annotation.dart'; part 'agora_payload.g.dart'; -@JsonSerializable(includeIfNull: false) +@JsonSerializable() class AgoraPayload { final String channel; const AgoraPayload({required this.channel}); factory AgoraPayload.fromJson(Map json) => _$AgoraPayloadFromJson(json); + + Map toJson() => _$AgoraPayloadToJson(this); } diff --git a/packages/stream_chat/lib/src/core/models/call_payload.dart b/packages/stream_chat/lib/src/core/models/call_payload.dart index 7754e5bea..1da6e4158 100644 --- a/packages/stream_chat/lib/src/core/models/call_payload.dart +++ b/packages/stream_chat/lib/src/core/models/call_payload.dart @@ -5,18 +5,21 @@ import 'package:json_annotation/json_annotation.dart'; part 'call_payload.g.dart'; -@JsonSerializable(includeIfNull: false) +@JsonSerializable() class CallPayload extends Equatable { final String id; final String provider; final AgoraPayload? agora; final HMSPayload? hms; - const CallPayload({required this.id, required this.provider, this.agora, this.hms}); + const CallPayload( + {required this.id, required this.provider, this.agora, this.hms}); factory CallPayload.fromJson(Map json) => _$CallPayloadFromJson(json); + Map toJson() => _$CallPayloadToJson(this); + @override List get props => [id, provider, agora, hms]; } diff --git a/packages/stream_chat/lib/src/core/models/call_payload.g.dart b/packages/stream_chat/lib/src/core/models/call_payload.g.dart index f23cfb45e..239a68bff 100644 --- a/packages/stream_chat/lib/src/core/models/call_payload.g.dart +++ b/packages/stream_chat/lib/src/core/models/call_payload.g.dart @@ -17,19 +17,10 @@ CallPayload _$CallPayloadFromJson(Map json) => CallPayload( : HMSPayload.fromJson(json['hms'] as Map), ); -Map _$CallPayloadToJson(CallPayload instance) { - final val = { - 'id': instance.id, - 'provider': instance.provider, - }; - - void writeNotNull(String key, dynamic value) { - if (value != null) { - val[key] = value; - } - } - - writeNotNull('agora', instance.agora?.toJson()); - writeNotNull('hms', instance.hms?.toJson()); - return val; -} +Map _$CallPayloadToJson(CallPayload instance) => + { + 'id': instance.id, + 'provider': instance.provider, + 'agora': instance.agora?.toJson(), + 'hms': instance.hms?.toJson(), + }; diff --git a/packages/stream_chat/lib/src/core/models/call_token_payload.dart b/packages/stream_chat/lib/src/core/models/call_token_payload.dart index 520572d16..f944fd75c 100644 --- a/packages/stream_chat/lib/src/core/models/call_token_payload.dart +++ b/packages/stream_chat/lib/src/core/models/call_token_payload.dart @@ -5,7 +5,7 @@ import 'package:json_annotation/json_annotation.dart'; part 'call_token_payload.g.dart'; -@JsonSerializable(includeIfNull: false) +@JsonSerializable() class CallTokenPayload extends Equatable { final String token; final int? agoraUid; @@ -15,6 +15,9 @@ class CallTokenPayload extends Equatable { factory CallTokenPayload.fromJson(Map json) => _$CallTokenPayloadFromJson(json); + + Map toJson() => _$CallTokenPayloadToJson(this); + @override List get props => [token, agoraAppId, agoraUid]; } diff --git a/packages/stream_chat/lib/src/core/models/call_token_payload.g.dart b/packages/stream_chat/lib/src/core/models/call_token_payload.g.dart index df8229205..09ab714e3 100644 --- a/packages/stream_chat/lib/src/core/models/call_token_payload.g.dart +++ b/packages/stream_chat/lib/src/core/models/call_token_payload.g.dart @@ -13,18 +13,9 @@ CallTokenPayload _$CallTokenPayloadFromJson(Map json) => agoraAppId: json['agora_app_id'] as String?, ); -Map _$CallTokenPayloadToJson(CallTokenPayload instance) { - final val = { - 'token': instance.token, - }; - - void writeNotNull(String key, dynamic value) { - if (value != null) { - val[key] = value; - } - } - - writeNotNull('agora_uid', instance.agoraUid); - writeNotNull('agora_app_id', instance.agoraAppId); - return val; -} +Map _$CallTokenPayloadToJson(CallTokenPayload instance) => + { + 'token': instance.token, + 'agora_uid': instance.agoraUid, + 'agora_app_id': instance.agoraAppId, + }; diff --git a/packages/stream_chat/lib/src/core/models/create_call_payload.dart b/packages/stream_chat/lib/src/core/models/create_call_payload.dart index 47711e2d9..5c030015f 100644 --- a/packages/stream_chat/lib/src/core/models/create_call_payload.dart +++ b/packages/stream_chat/lib/src/core/models/create_call_payload.dart @@ -3,9 +3,9 @@ import 'package:stream_chat/src/core/models/call_payload.dart'; import 'package:equatable/equatable.dart'; import 'package:json_annotation/json_annotation.dart'; - part 'create_call_payload.g.dart'; -@JsonSerializable(includeIfNull: false) + +@JsonSerializable() class CreateCallPayload extends Equatable { final CallPayload call; const CreateCallPayload({required this.call}); @@ -13,6 +13,8 @@ class CreateCallPayload extends Equatable { factory CreateCallPayload.fromJson(Map json) => _$CreateCallPayloadFromJson(json); + Map toJson() => _$CreateCallPayloadToJson(this); + @override List get props => [call]; } diff --git a/packages/stream_chat/lib/src/core/models/hms_payload.dart b/packages/stream_chat/lib/src/core/models/hms_payload.dart index 5d5e3e968..1e77b475a 100644 --- a/packages/stream_chat/lib/src/core/models/hms_payload.dart +++ b/packages/stream_chat/lib/src/core/models/hms_payload.dart @@ -3,7 +3,7 @@ import 'package:json_annotation/json_annotation.dart'; part 'hms_payload.g.dart'; -@JsonSerializable(includeIfNull: false) +@JsonSerializable() class HMSPayload extends Equatable { final String roomId; final String roomName; @@ -12,6 +12,8 @@ class HMSPayload extends Equatable { factory HMSPayload.fromJson(Map json) => _$HMSPayloadFromJson(json); + Map toJson() => _$HMSPayloadToJson(this); + @override List get props => [roomId, roomName]; } diff --git a/packages/stream_chat/lib/stream_chat.dart b/packages/stream_chat/lib/stream_chat.dart index 7f4c22efc..621373529 100644 --- a/packages/stream_chat/lib/stream_chat.dart +++ b/packages/stream_chat/lib/stream_chat.dart @@ -15,15 +15,21 @@ export './src/core/api/responses.dart'; export './src/core/api/stream_chat_api.dart' show PushProvider; export './src/core/error/error.dart'; export './src/core/models/action.dart'; +export './src/core/models/agora_payload.dart'; export './src/core/models/attachment.dart'; export './src/core/models/attachment_file.dart'; +export './src/core/models/call_payload.dart'; +export './src/core/models/call_token_payload.dart'; export './src/core/models/channel_config.dart'; export './src/core/models/channel_model.dart'; export './src/core/models/channel_state.dart'; export './src/core/models/command.dart'; +export './src/core/models/create_call_payload.dart'; export './src/core/models/device.dart'; export './src/core/models/event.dart'; export './src/core/models/filter.dart' show Filter; +export './src/core/models/hms_payload.dart'; +export './src/core/models/hms_payload.dart'; export './src/core/models/member.dart'; export './src/core/models/message.dart'; export './src/core/models/mute.dart'; From a5d0c74fd644076437feff635bcfaba43751c8c0 Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Thu, 25 Aug 2022 12:30:50 +0200 Subject: [PATCH 03/10] refactor: clean up and add docs --- .../stream_chat/lib/src/client/client.dart | 4 +- .../lib/src/core/api/call_api.dart | 10 +- .../lib/src/core/api/responses.dart | 122 ++++++++++++++++++ .../lib/src/core/api/responses.g.dart | 63 +++++++++ .../lib/src/core/models/agora_payload.dart | 15 --- .../lib/src/core/models/agora_payload.g.dart | 16 --- .../lib/src/core/models/call_payload.dart | 25 ---- .../lib/src/core/models/call_payload.g.dart | 26 ---- .../src/core/models/call_token_payload.dart | 23 ---- .../src/core/models/call_token_payload.g.dart | 21 --- .../src/core/models/create_call_payload.dart | 20 --- .../core/models/create_call_payload.g.dart | 17 --- .../lib/src/core/models/hms_payload.dart | 19 --- .../lib/src/core/models/hms_payload.g.dart | 18 --- packages/stream_chat/lib/stream_chat.dart | 6 - 15 files changed, 193 insertions(+), 212 deletions(-) delete mode 100644 packages/stream_chat/lib/src/core/models/agora_payload.dart delete mode 100644 packages/stream_chat/lib/src/core/models/agora_payload.g.dart delete mode 100644 packages/stream_chat/lib/src/core/models/call_payload.dart delete mode 100644 packages/stream_chat/lib/src/core/models/call_payload.g.dart delete mode 100644 packages/stream_chat/lib/src/core/models/call_token_payload.dart delete mode 100644 packages/stream_chat/lib/src/core/models/call_token_payload.g.dart delete mode 100644 packages/stream_chat/lib/src/core/models/create_call_payload.dart delete mode 100644 packages/stream_chat/lib/src/core/models/create_call_payload.g.dart delete mode 100644 packages/stream_chat/lib/src/core/models/hms_payload.dart delete mode 100644 packages/stream_chat/lib/src/core/models/hms_payload.g.dart diff --git a/packages/stream_chat/lib/src/client/client.dart b/packages/stream_chat/lib/src/client/client.dart index ea221701f..0654f8377 100644 --- a/packages/stream_chat/lib/src/client/client.dart +++ b/packages/stream_chat/lib/src/client/client.dart @@ -17,10 +17,8 @@ import 'package:stream_chat/src/core/http/stream_http_client.dart'; import 'package:stream_chat/src/core/http/token.dart'; import 'package:stream_chat/src/core/http/token_manager.dart'; import 'package:stream_chat/src/core/models/attachment_file.dart'; -import 'package:stream_chat/src/core/models/call_token_payload.dart'; import 'package:stream_chat/src/core/models/channel_model.dart'; import 'package:stream_chat/src/core/models/channel_state.dart'; -import 'package:stream_chat/src/core/models/create_call_payload.dart'; import 'package:stream_chat/src/core/models/event.dart'; import 'package:stream_chat/src/core/models/filter.dart'; import 'package:stream_chat/src/core/models/member.dart'; @@ -587,9 +585,11 @@ class StreamChatClient { } } + /// Returns a token associated with the [callId]. Future getCallToken(String callId) async => _chatApi.call.getCallToken(callId); + /// Creates a new call. Future createCall({ required String callId, required String callType, diff --git a/packages/stream_chat/lib/src/core/api/call_api.dart b/packages/stream_chat/lib/src/core/api/call_api.dart index 6c5428487..d7deff1e2 100644 --- a/packages/stream_chat/lib/src/core/api/call_api.dart +++ b/packages/stream_chat/lib/src/core/api/call_api.dart @@ -1,13 +1,14 @@ +import 'package:stream_chat/src/core/api/responses.dart'; import 'package:stream_chat/src/core/http/stream_http_client.dart'; -import 'package:stream_chat/src/core/models/call_token_payload.dart'; -import 'package:stream_chat/src/core/models/create_call_payload.dart'; +/// Defines the api dedicated to video call operations class CallApi { /// Initialize a new call api CallApi(this._client); final StreamHttpClient _client; + /// Returns a token dedicated to the [callId] Future getCallToken(String callId) async { final response = await _client.post( '/calls/$callId', @@ -17,6 +18,7 @@ class CallApi { return CallTokenPayload.fromJson(response.data); } + /// Creates a new call Future createCall({ required String callId, required String callType, @@ -26,8 +28,8 @@ class CallApi { }) async { final response = await _client.post(_getChannelUrl(channelId, channelType), data: { - 'id': '$callId', - 'type': '$callType', + 'id': callId, + 'type': callType, }); // return response.data; return CreateCallPayload.fromJson(response.data); diff --git a/packages/stream_chat/lib/src/core/api/responses.dart b/packages/stream_chat/lib/src/core/api/responses.dart index d608c5aac..721427783 100644 --- a/packages/stream_chat/lib/src/core/api/responses.dart +++ b/packages/stream_chat/lib/src/core/api/responses.dart @@ -1,5 +1,7 @@ +import 'package:equatable/equatable.dart'; import 'package:json_annotation/json_annotation.dart'; import 'package:stream_chat/src/client/client.dart'; +import 'package:stream_chat/src/core/api/call_api.dart'; import 'package:stream_chat/src/core/error/error.dart'; import 'package:stream_chat/src/core/models/banned_user.dart'; import 'package:stream_chat/src/core/models/channel_model.dart'; @@ -495,3 +497,123 @@ class OGAttachmentResponse extends _BaseResponse { static OGAttachmentResponse fromJson(Map json) => _$OGAttachmentResponseFromJson(json); } + +/// Payload for Agora call. +@JsonSerializable() +class AgoraPayload { + /// Create a new instance. + const AgoraPayload({required this.channel}); + + /// Create a new instance from a [json]. + factory AgoraPayload.fromJson(Map json) => + _$AgoraPayloadFromJson(json); + + /// The Agora channel. + final String channel; + + /// Convert this object to a json. + Map toJson() => _$AgoraPayloadToJson(this); +} + +/// Model containing the information about a call. +@JsonSerializable() +class CallPayload extends Equatable { + /// Create a new instance. + const CallPayload({ + required this.id, + required this.provider, + this.agora, + this.hms, + }); + + /// Create a new instance from a [json]. + factory CallPayload.fromJson(Map json) => + _$CallPayloadFromJson(json); + + /// The call id. + final String id; + + /// The call provider. + final String provider; + + /// The payload specific to Agora. + final AgoraPayload? agora; + + /// The payload specific to 100ms. + final HMSPayload? hms; + + /// Convert this object to a json. + Map toJson() => _$CallPayloadToJson(this); + + @override + List get props => [id, provider, agora, hms]; +} + +/// The response to [CallApi.getCallToken] +@JsonSerializable() +class CallTokenPayload extends Equatable { + /// Create a new instance. + const CallTokenPayload({required this.token, this.agoraUid, this.agoraAppId}); + + /// Create a new instance from a [json]. + factory CallTokenPayload.fromJson(Map json) => + _$CallTokenPayloadFromJson(json); + + /// The token to use for the call. + final String token; + + /// The uid specific to Agora. + final int? agoraUid; + + /// The appId specific to 100ms. + final String? agoraAppId; + + /// Convert this object to a json. + Map toJson() => _$CallTokenPayloadToJson(this); + + @override + List get props => [token, agoraAppId, agoraUid]; +} + +/// The response to [CallApi.createCall] +@JsonSerializable() +class CreateCallPayload extends Equatable { + /// Creates a new instance. + const CreateCallPayload({required this.call}); + + /// Create a new instance from a [json]. + factory CreateCallPayload.fromJson(Map json) => + _$CreateCallPayloadFromJson(json); + + /// The call object. + final CallPayload call; + + /// Convert this object to a json. + Map toJson() => _$CreateCallPayloadToJson(this); + + @override + List get props => [call]; +} + +/// Payload for 100ms call. +@JsonSerializable() +class HMSPayload extends Equatable { + /// Create a new instance. + const HMSPayload({required this.roomId, required this.roomName}); + + /// Create a new instance from a [json]. + factory HMSPayload.fromJson(Map json) => + _$HMSPayloadFromJson(json); + + /// The id of the 100ms room. + final String roomId; + + /// The name of the 100ms room. + final String roomName; + + /// Convert this object to a json. + Map toJson() => _$HMSPayloadToJson(this); + + @override + List get props => [roomId, roomName]; +} diff --git a/packages/stream_chat/lib/src/core/api/responses.g.dart b/packages/stream_chat/lib/src/core/api/responses.g.dart index 991b39f6b..c82769c1d 100644 --- a/packages/stream_chat/lib/src/core/api/responses.g.dart +++ b/packages/stream_chat/lib/src/core/api/responses.g.dart @@ -297,3 +297,66 @@ OGAttachmentResponse _$OGAttachmentResponseFromJson( ..title = json['title'] as String? ..titleLink = json['title_link'] as String? ..type = json['type'] as String?; + +AgoraPayload _$AgoraPayloadFromJson(Map json) => AgoraPayload( + channel: json['channel'] as String, + ); + +Map _$AgoraPayloadToJson(AgoraPayload instance) => + { + 'channel': instance.channel, + }; + +CallPayload _$CallPayloadFromJson(Map json) => CallPayload( + id: json['id'] as String, + provider: json['provider'] as String, + agora: json['agora'] == null + ? null + : AgoraPayload.fromJson(json['agora'] as Map), + hms: json['hms'] == null + ? null + : HMSPayload.fromJson(json['hms'] as Map), + ); + +Map _$CallPayloadToJson(CallPayload instance) => + { + 'id': instance.id, + 'provider': instance.provider, + 'agora': instance.agora?.toJson(), + 'hms': instance.hms?.toJson(), + }; + +CallTokenPayload _$CallTokenPayloadFromJson(Map json) => + CallTokenPayload( + token: json['token'] as String, + agoraUid: json['agora_uid'] as int?, + agoraAppId: json['agora_app_id'] as String?, + ); + +Map _$CallTokenPayloadToJson(CallTokenPayload instance) => + { + 'token': instance.token, + 'agora_uid': instance.agoraUid, + 'agora_app_id': instance.agoraAppId, + }; + +CreateCallPayload _$CreateCallPayloadFromJson(Map json) => + CreateCallPayload( + call: CallPayload.fromJson(json['call'] as Map), + ); + +Map _$CreateCallPayloadToJson(CreateCallPayload instance) => + { + 'call': instance.call.toJson(), + }; + +HMSPayload _$HMSPayloadFromJson(Map json) => HMSPayload( + roomId: json['room_id'] as String, + roomName: json['room_name'] as String, + ); + +Map _$HMSPayloadToJson(HMSPayload instance) => + { + 'room_id': instance.roomId, + 'room_name': instance.roomName, + }; diff --git a/packages/stream_chat/lib/src/core/models/agora_payload.dart b/packages/stream_chat/lib/src/core/models/agora_payload.dart deleted file mode 100644 index c70ffe0b4..000000000 --- a/packages/stream_chat/lib/src/core/models/agora_payload.dart +++ /dev/null @@ -1,15 +0,0 @@ -import 'package:equatable/equatable.dart'; -import 'package:json_annotation/json_annotation.dart'; - -part 'agora_payload.g.dart'; - -@JsonSerializable() -class AgoraPayload { - final String channel; - const AgoraPayload({required this.channel}); - - factory AgoraPayload.fromJson(Map json) => - _$AgoraPayloadFromJson(json); - - Map toJson() => _$AgoraPayloadToJson(this); -} diff --git a/packages/stream_chat/lib/src/core/models/agora_payload.g.dart b/packages/stream_chat/lib/src/core/models/agora_payload.g.dart deleted file mode 100644 index ff4df8438..000000000 --- a/packages/stream_chat/lib/src/core/models/agora_payload.g.dart +++ /dev/null @@ -1,16 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'agora_payload.dart'; - -// ************************************************************************** -// JsonSerializableGenerator -// ************************************************************************** - -AgoraPayload _$AgoraPayloadFromJson(Map json) => AgoraPayload( - channel: json['channel'] as String, - ); - -Map _$AgoraPayloadToJson(AgoraPayload instance) => - { - 'channel': instance.channel, - }; diff --git a/packages/stream_chat/lib/src/core/models/call_payload.dart b/packages/stream_chat/lib/src/core/models/call_payload.dart deleted file mode 100644 index 1da6e4158..000000000 --- a/packages/stream_chat/lib/src/core/models/call_payload.dart +++ /dev/null @@ -1,25 +0,0 @@ -import 'package:stream_chat/src/core/models/agora_payload.dart'; -import 'package:stream_chat/src/core/models/hms_payload.dart'; -import 'package:equatable/equatable.dart'; -import 'package:json_annotation/json_annotation.dart'; - -part 'call_payload.g.dart'; - -@JsonSerializable() -class CallPayload extends Equatable { - final String id; - final String provider; - final AgoraPayload? agora; - final HMSPayload? hms; - - const CallPayload( - {required this.id, required this.provider, this.agora, this.hms}); - - factory CallPayload.fromJson(Map json) => - _$CallPayloadFromJson(json); - - Map toJson() => _$CallPayloadToJson(this); - - @override - List get props => [id, provider, agora, hms]; -} diff --git a/packages/stream_chat/lib/src/core/models/call_payload.g.dart b/packages/stream_chat/lib/src/core/models/call_payload.g.dart deleted file mode 100644 index 239a68bff..000000000 --- a/packages/stream_chat/lib/src/core/models/call_payload.g.dart +++ /dev/null @@ -1,26 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'call_payload.dart'; - -// ************************************************************************** -// JsonSerializableGenerator -// ************************************************************************** - -CallPayload _$CallPayloadFromJson(Map json) => CallPayload( - id: json['id'] as String, - provider: json['provider'] as String, - agora: json['agora'] == null - ? null - : AgoraPayload.fromJson(json['agora'] as Map), - hms: json['hms'] == null - ? null - : HMSPayload.fromJson(json['hms'] as Map), - ); - -Map _$CallPayloadToJson(CallPayload instance) => - { - 'id': instance.id, - 'provider': instance.provider, - 'agora': instance.agora?.toJson(), - 'hms': instance.hms?.toJson(), - }; diff --git a/packages/stream_chat/lib/src/core/models/call_token_payload.dart b/packages/stream_chat/lib/src/core/models/call_token_payload.dart deleted file mode 100644 index f944fd75c..000000000 --- a/packages/stream_chat/lib/src/core/models/call_token_payload.dart +++ /dev/null @@ -1,23 +0,0 @@ -import 'package:equatable/equatable.dart'; -import 'package:json_annotation/json_annotation.dart'; - - - -part 'call_token_payload.g.dart'; - -@JsonSerializable() -class CallTokenPayload extends Equatable { - final String token; - final int? agoraUid; - final String? agoraAppId; - const CallTokenPayload({required this.token, this.agoraUid, this.agoraAppId}); - - factory CallTokenPayload.fromJson(Map json) => - _$CallTokenPayloadFromJson(json); - - - Map toJson() => _$CallTokenPayloadToJson(this); - - @override - List get props => [token, agoraAppId, agoraUid]; -} diff --git a/packages/stream_chat/lib/src/core/models/call_token_payload.g.dart b/packages/stream_chat/lib/src/core/models/call_token_payload.g.dart deleted file mode 100644 index 09ab714e3..000000000 --- a/packages/stream_chat/lib/src/core/models/call_token_payload.g.dart +++ /dev/null @@ -1,21 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'call_token_payload.dart'; - -// ************************************************************************** -// JsonSerializableGenerator -// ************************************************************************** - -CallTokenPayload _$CallTokenPayloadFromJson(Map json) => - CallTokenPayload( - token: json['token'] as String, - agoraUid: json['agora_uid'] as int?, - agoraAppId: json['agora_app_id'] as String?, - ); - -Map _$CallTokenPayloadToJson(CallTokenPayload instance) => - { - 'token': instance.token, - 'agora_uid': instance.agoraUid, - 'agora_app_id': instance.agoraAppId, - }; diff --git a/packages/stream_chat/lib/src/core/models/create_call_payload.dart b/packages/stream_chat/lib/src/core/models/create_call_payload.dart deleted file mode 100644 index 5c030015f..000000000 --- a/packages/stream_chat/lib/src/core/models/create_call_payload.dart +++ /dev/null @@ -1,20 +0,0 @@ -import 'package:equatable/equatable.dart'; -import 'package:stream_chat/src/core/models/call_payload.dart'; -import 'package:equatable/equatable.dart'; -import 'package:json_annotation/json_annotation.dart'; - -part 'create_call_payload.g.dart'; - -@JsonSerializable() -class CreateCallPayload extends Equatable { - final CallPayload call; - const CreateCallPayload({required this.call}); - - factory CreateCallPayload.fromJson(Map json) => - _$CreateCallPayloadFromJson(json); - - Map toJson() => _$CreateCallPayloadToJson(this); - - @override - List get props => [call]; -} diff --git a/packages/stream_chat/lib/src/core/models/create_call_payload.g.dart b/packages/stream_chat/lib/src/core/models/create_call_payload.g.dart deleted file mode 100644 index 3c8497978..000000000 --- a/packages/stream_chat/lib/src/core/models/create_call_payload.g.dart +++ /dev/null @@ -1,17 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'create_call_payload.dart'; - -// ************************************************************************** -// JsonSerializableGenerator -// ************************************************************************** - -CreateCallPayload _$CreateCallPayloadFromJson(Map json) => - CreateCallPayload( - call: CallPayload.fromJson(json['call'] as Map), - ); - -Map _$CreateCallPayloadToJson(CreateCallPayload instance) => - { - 'call': instance.call.toJson(), - }; diff --git a/packages/stream_chat/lib/src/core/models/hms_payload.dart b/packages/stream_chat/lib/src/core/models/hms_payload.dart deleted file mode 100644 index 1e77b475a..000000000 --- a/packages/stream_chat/lib/src/core/models/hms_payload.dart +++ /dev/null @@ -1,19 +0,0 @@ -import 'package:equatable/equatable.dart'; -import 'package:json_annotation/json_annotation.dart'; - -part 'hms_payload.g.dart'; - -@JsonSerializable() -class HMSPayload extends Equatable { - final String roomId; - final String roomName; - const HMSPayload({required this.roomId, required this.roomName}); - - factory HMSPayload.fromJson(Map json) => - _$HMSPayloadFromJson(json); - - Map toJson() => _$HMSPayloadToJson(this); - - @override - List get props => [roomId, roomName]; -} diff --git a/packages/stream_chat/lib/src/core/models/hms_payload.g.dart b/packages/stream_chat/lib/src/core/models/hms_payload.g.dart deleted file mode 100644 index 3c55f56f3..000000000 --- a/packages/stream_chat/lib/src/core/models/hms_payload.g.dart +++ /dev/null @@ -1,18 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'hms_payload.dart'; - -// ************************************************************************** -// JsonSerializableGenerator -// ************************************************************************** - -HMSPayload _$HMSPayloadFromJson(Map json) => HMSPayload( - roomId: json['room_id'] as String, - roomName: json['room_name'] as String, - ); - -Map _$HMSPayloadToJson(HMSPayload instance) => - { - 'room_id': instance.roomId, - 'room_name': instance.roomName, - }; diff --git a/packages/stream_chat/lib/stream_chat.dart b/packages/stream_chat/lib/stream_chat.dart index 621373529..7f4c22efc 100644 --- a/packages/stream_chat/lib/stream_chat.dart +++ b/packages/stream_chat/lib/stream_chat.dart @@ -15,21 +15,15 @@ export './src/core/api/responses.dart'; export './src/core/api/stream_chat_api.dart' show PushProvider; export './src/core/error/error.dart'; export './src/core/models/action.dart'; -export './src/core/models/agora_payload.dart'; export './src/core/models/attachment.dart'; export './src/core/models/attachment_file.dart'; -export './src/core/models/call_payload.dart'; -export './src/core/models/call_token_payload.dart'; export './src/core/models/channel_config.dart'; export './src/core/models/channel_model.dart'; export './src/core/models/channel_state.dart'; export './src/core/models/command.dart'; -export './src/core/models/create_call_payload.dart'; export './src/core/models/device.dart'; export './src/core/models/event.dart'; export './src/core/models/filter.dart' show Filter; -export './src/core/models/hms_payload.dart'; -export './src/core/models/hms_payload.dart'; export './src/core/models/member.dart'; export './src/core/models/message.dart'; export './src/core/models/mute.dart'; From ba13c9b02f59ca99635d1e43564e8652291ee0a5 Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Thu, 25 Aug 2022 12:39:41 +0200 Subject: [PATCH 04/10] chore(llc): update changelog --- packages/stream_chat/CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/stream_chat/CHANGELOG.md b/packages/stream_chat/CHANGELOG.md index 6b73d0abc..de35d0a63 100644 --- a/packages/stream_chat/CHANGELOG.md +++ b/packages/stream_chat/CHANGELOG.md @@ -1,3 +1,9 @@ +## Upcoming + +✅ Added + +- Added `StreamChatClient.getCallToken` and `StreamChatClient.createCall` methods. + ## 4.5.0 🐞 Fixed From af055e367b4028de30178095fd6eeac53fb2f53a Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Thu, 25 Aug 2022 14:10:22 +0200 Subject: [PATCH 05/10] chore(llc): add tests --- .../lib/src/core/api/responses.dart | 57 +++++------------- .../lib/src/core/api/responses.g.dart | 49 ++++------------ .../test/src/core/api/responses_test.dart | 58 +++++++++++++++++++ 3 files changed, 83 insertions(+), 81 deletions(-) diff --git a/packages/stream_chat/lib/src/core/api/responses.dart b/packages/stream_chat/lib/src/core/api/responses.dart index 721427783..ddeb4b0f0 100644 --- a/packages/stream_chat/lib/src/core/api/responses.dart +++ b/packages/stream_chat/lib/src/core/api/responses.dart @@ -499,7 +499,7 @@ class OGAttachmentResponse extends _BaseResponse { } /// Payload for Agora call. -@JsonSerializable() +@JsonSerializable(createToJson: false) class AgoraPayload { /// Create a new instance. const AgoraPayload({required this.channel}); @@ -510,13 +510,10 @@ class AgoraPayload { /// The Agora channel. final String channel; - - /// Convert this object to a json. - Map toJson() => _$AgoraPayloadToJson(this); } /// Model containing the information about a call. -@JsonSerializable() +@JsonSerializable(createToJson: false) class CallPayload extends Equatable { /// Create a new instance. const CallPayload({ @@ -542,61 +539,40 @@ class CallPayload extends Equatable { /// The payload specific to 100ms. final HMSPayload? hms; - /// Convert this object to a json. - Map toJson() => _$CallPayloadToJson(this); - @override List get props => [id, provider, agora, hms]; } /// The response to [CallApi.getCallToken] -@JsonSerializable() -class CallTokenPayload extends Equatable { - /// Create a new instance. - const CallTokenPayload({required this.token, this.agoraUid, this.agoraAppId}); - +@JsonSerializable(createToJson: false) +class CallTokenPayload extends _BaseResponse { /// Create a new instance from a [json]. - factory CallTokenPayload.fromJson(Map json) => + static CallTokenPayload fromJson(Map json) => _$CallTokenPayloadFromJson(json); /// The token to use for the call. - final String token; - - /// The uid specific to Agora. - final int? agoraUid; + String? token; - /// The appId specific to 100ms. - final String? agoraAppId; + /// The user id specific to Agora. + int? agoraUid; - /// Convert this object to a json. - Map toJson() => _$CallTokenPayloadToJson(this); - - @override - List get props => [token, agoraAppId, agoraUid]; + /// The appId specific to Agora. + String? agoraAppId; } /// The response to [CallApi.createCall] -@JsonSerializable() -class CreateCallPayload extends Equatable { - /// Creates a new instance. - const CreateCallPayload({required this.call}); - +@JsonSerializable(createToJson: false) +class CreateCallPayload extends _BaseResponse { /// Create a new instance from a [json]. - factory CreateCallPayload.fromJson(Map json) => + static CreateCallPayload fromJson(Map json) => _$CreateCallPayloadFromJson(json); /// The call object. - final CallPayload call; - - /// Convert this object to a json. - Map toJson() => _$CreateCallPayloadToJson(this); - - @override - List get props => [call]; + CallPayload? call; } /// Payload for 100ms call. -@JsonSerializable() +@JsonSerializable(createToJson: false) class HMSPayload extends Equatable { /// Create a new instance. const HMSPayload({required this.roomId, required this.roomName}); @@ -611,9 +587,6 @@ class HMSPayload extends Equatable { /// The name of the 100ms room. final String roomName; - /// Convert this object to a json. - Map toJson() => _$HMSPayloadToJson(this); - @override List get props => [roomId, roomName]; } diff --git a/packages/stream_chat/lib/src/core/api/responses.g.dart b/packages/stream_chat/lib/src/core/api/responses.g.dart index c82769c1d..6cc2158ed 100644 --- a/packages/stream_chat/lib/src/core/api/responses.g.dart +++ b/packages/stream_chat/lib/src/core/api/responses.g.dart @@ -302,11 +302,6 @@ AgoraPayload _$AgoraPayloadFromJson(Map json) => AgoraPayload( channel: json['channel'] as String, ); -Map _$AgoraPayloadToJson(AgoraPayload instance) => - { - 'channel': instance.channel, - }; - CallPayload _$CallPayloadFromJson(Map json) => CallPayload( id: json['id'] as String, provider: json['provider'] as String, @@ -318,45 +313,21 @@ CallPayload _$CallPayloadFromJson(Map json) => CallPayload( : HMSPayload.fromJson(json['hms'] as Map), ); -Map _$CallPayloadToJson(CallPayload instance) => - { - 'id': instance.id, - 'provider': instance.provider, - 'agora': instance.agora?.toJson(), - 'hms': instance.hms?.toJson(), - }; - CallTokenPayload _$CallTokenPayloadFromJson(Map json) => - CallTokenPayload( - token: json['token'] as String, - agoraUid: json['agora_uid'] as int?, - agoraAppId: json['agora_app_id'] as String?, - ); - -Map _$CallTokenPayloadToJson(CallTokenPayload instance) => - { - 'token': instance.token, - 'agora_uid': instance.agoraUid, - 'agora_app_id': instance.agoraAppId, - }; + CallTokenPayload() + ..duration = json['duration'] as String? + ..token = json['token'] as String? + ..agoraUid = json['agora_uid'] as int? + ..agoraAppId = json['agora_app_id'] as String?; CreateCallPayload _$CreateCallPayloadFromJson(Map json) => - CreateCallPayload( - call: CallPayload.fromJson(json['call'] as Map), - ); - -Map _$CreateCallPayloadToJson(CreateCallPayload instance) => - { - 'call': instance.call.toJson(), - }; + CreateCallPayload() + ..duration = json['duration'] as String? + ..call = json['call'] == null + ? null + : CallPayload.fromJson(json['call'] as Map); HMSPayload _$HMSPayloadFromJson(Map json) => HMSPayload( roomId: json['room_id'] as String, roomName: json['room_name'] as String, ); - -Map _$HMSPayloadToJson(HMSPayload instance) => - { - 'room_id': instance.roomId, - 'room_name': instance.roomName, - }; diff --git a/packages/stream_chat/test/src/core/api/responses_test.dart b/packages/stream_chat/test/src/core/api/responses_test.dart index 8a73fccd0..75a374fb2 100644 --- a/packages/stream_chat/test/src/core/api/responses_test.dart +++ b/packages/stream_chat/test/src/core/api/responses_test.dart @@ -4340,5 +4340,63 @@ void main() { expect(response.members, isA>()); expect(response.message, isA()); }); + + test('AgoraPayload', () { + const jsonExample = ''' + {"channel":"test"} + '''; + final response = AgoraPayload.fromJson(json.decode(jsonExample)); + expect(response.channel, isA()); + }); + + test('CallPayload', () { + const jsonExample = ''' + {"id":"test", + "provider": "test", + "agora": {"channel":"test"}, + "hms":{"room_id":"test", "room_name":"test"} + } + '''; + final response = CallPayload.fromJson(json.decode(jsonExample)); + expect(response.agora, isA()); + expect(response.hms, isA()); + expect(response.id, isA()); + expect(response.provider, isA()); + }); + }); + + test('CallTokenPayload', () { + const jsonExample = ''' + {"duration": "3ms", + "agora_app_id":"test", + "agora_uid": 12, + "token": "token"} + '''; + final response = CallTokenPayload.fromJson(json.decode(jsonExample)); + expect(response.agoraAppId, isA()); + expect(response.agoraUid, isA()); + expect(response.token, isA()); + }); + + test('CreateCallPayload', () { + const jsonExample = ''' + {"call": + {"id":"test", + "provider": "test", + "agora": {"channel":"test"}, + "hms":{"room_id":"test", "room_name":"test"} + }} + '''; + final response = CreateCallPayload.fromJson(json.decode(jsonExample)); + expect(response.call, isA()); + }); + + test('HMSPayload', () { + const jsonExample = ''' + {"room_id":"test", "room_name":"test"} + '''; + final response = HMSPayload.fromJson(json.decode(jsonExample)); + expect(response.roomId, isA()); + expect(response.roomName, isA()); }); } From b924337d249d848b99caee4dfac13fd19d47fb62 Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Thu, 25 Aug 2022 18:17:54 +0200 Subject: [PATCH 06/10] chore(llc): add more tests --- .../stream_chat/lib/src/client/client.dart | 2 - .../lib/src/core/api/call_api.dart | 1 - .../test/src/core/api/call_api_test.dart | 72 +++++++++++++++++++ 3 files changed, 72 insertions(+), 3 deletions(-) create mode 100644 packages/stream_chat/test/src/core/api/call_api_test.dart diff --git a/packages/stream_chat/lib/src/client/client.dart b/packages/stream_chat/lib/src/client/client.dart index 0654f8377..73f0f95e8 100644 --- a/packages/stream_chat/lib/src/client/client.dart +++ b/packages/stream_chat/lib/src/client/client.dart @@ -595,12 +595,10 @@ class StreamChatClient { required String callType, required String channelType, required String channelId, - Map? options, }) async { return _chatApi.call.createCall( callId: callId, callType: callType, - options: options, channelType: channelType, channelId: channelId, ); diff --git a/packages/stream_chat/lib/src/core/api/call_api.dart b/packages/stream_chat/lib/src/core/api/call_api.dart index d7deff1e2..60fc6f886 100644 --- a/packages/stream_chat/lib/src/core/api/call_api.dart +++ b/packages/stream_chat/lib/src/core/api/call_api.dart @@ -24,7 +24,6 @@ class CallApi { required String callType, required String channelType, required String channelId, - Map? options, }) async { final response = await _client.post(_getChannelUrl(channelId, channelType), data: { diff --git a/packages/stream_chat/test/src/core/api/call_api_test.dart b/packages/stream_chat/test/src/core/api/call_api_test.dart new file mode 100644 index 000000000..36b173f96 --- /dev/null +++ b/packages/stream_chat/test/src/core/api/call_api_test.dart @@ -0,0 +1,72 @@ +import 'package:dio/dio.dart'; +import 'package:mocktail/mocktail.dart'; +import 'package:stream_chat/src/core/api/call_api.dart'; +import 'package:stream_chat/src/core/api/device_api.dart'; +import 'package:stream_chat/stream_chat.dart'; +import 'package:test/test.dart'; + +import '../../mocks.dart'; + +void main() { + Response successResponse(String path, {Object? data}) => Response( + data: data, + requestOptions: RequestOptions(path: path), + statusCode: 200, + ); + + late final client = MockHttpClient(); + late CallApi callApi; + + setUp(() { + callApi = CallApi(client); + }); + + test('getCallToken should work', () async { + const callId = 'test-call-id'; + const path = '/calls/$callId'; + + when(() => client.post( + path, + data: {}, + )) + .thenAnswer( + (_) async => successResponse(path, data: {})); + + final res = await callApi.getCallToken(callId); + + expect(res, isNotNull); + + verify(() => client.post(path, data: any(named: 'data'))).called(1); + verifyNoMoreInteractions(client); + }); + + test('createCall should work', () async { + const callId = 'test-call-id'; + const callType = 'test-call-type'; + const channelType = 'test-channel-type'; + const channelId = 'test-channel-id'; + const path = '/channels/$channelType/$channelId/call'; + + when(() => client.post( + path, + data: { + 'id': callId, + 'type': callType, + }, + )) + .thenAnswer( + (_) async => successResponse(path, data: {})); + + final res = await callApi.createCall( + callId: callId, + callType: callType, + channelType: channelType, + channelId: channelId, + ); + + expect(res, isNotNull); + + verify(() => client.post(path, data: any(named: 'data'))).called(1); + verifyNoMoreInteractions(client); + }); +} From 24b1a8087bef07b015363cd558503add6efc569e Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Fri, 26 Aug 2022 09:18:31 +0200 Subject: [PATCH 07/10] fix analysis --- packages/stream_chat/test/src/core/api/call_api_test.dart | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/stream_chat/test/src/core/api/call_api_test.dart b/packages/stream_chat/test/src/core/api/call_api_test.dart index 36b173f96..662f84b03 100644 --- a/packages/stream_chat/test/src/core/api/call_api_test.dart +++ b/packages/stream_chat/test/src/core/api/call_api_test.dart @@ -1,8 +1,6 @@ import 'package:dio/dio.dart'; import 'package:mocktail/mocktail.dart'; import 'package:stream_chat/src/core/api/call_api.dart'; -import 'package:stream_chat/src/core/api/device_api.dart'; -import 'package:stream_chat/stream_chat.dart'; import 'package:test/test.dart'; import '../../mocks.dart'; From c414150bc883ff4fec081555d276d45e09027bd1 Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Fri, 26 Aug 2022 09:42:03 +0200 Subject: [PATCH 08/10] chore(llc): add more tests --- .../test/src/core/api/requests_test.dart | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/packages/stream_chat/test/src/core/api/requests_test.dart b/packages/stream_chat/test/src/core/api/requests_test.dart index 876a3f61d..72f97c7b2 100644 --- a/packages/stream_chat/test/src/core/api/requests_test.dart +++ b/packages/stream_chat/test/src/core/api/requests_test.dart @@ -26,6 +26,53 @@ void main() { } }, ); + + test('copyWith', () { + final params = PaginationParams( + offset: 10, + limit: 20, + createdAtAfter: DateTime.now(), + createdAtAfterOrEqual: DateTime.now(), + createdAtAround: DateTime.now(), + createdAtBefore: DateTime.now(), + createdAtBeforeOrEqual: DateTime.now(), + greaterThan: 'greater-than', + greaterThanOrEqual: 'greater-than-or-equal', + lessThan: 'less-than', + lessThanOrEqual: 'less-than-or-equal', + idAround: 'id-around', + ); + + final newDateTime = DateTime.now().add(const Duration(days: 2)); + const newTestString = 'test'; + final newParams = params.copyWith( + limit: 2, + offset: 2, + createdAtAfter: newDateTime, + createdAtAfterOrEqual: newDateTime, + createdAtAround: newDateTime, + createdAtBefore: newDateTime, + createdAtBeforeOrEqual: newDateTime, + greaterThan: newTestString, + greaterThanOrEqual: newTestString, + lessThan: newTestString, + lessThanOrEqual: newTestString, + idAround: newTestString, + ); + + expect(newParams.limit, 2); + expect(newParams.offset, 2); + expect(newParams.createdAtAfter, newDateTime); + expect(newParams.createdAtAfterOrEqual, newDateTime); + expect(newParams.createdAtAround, newDateTime); + expect(newParams.createdAtBefore, newDateTime); + expect(newParams.createdAtBeforeOrEqual, newDateTime); + expect(newParams.greaterThan, newTestString); + expect(newParams.greaterThanOrEqual, newTestString); + expect(newParams.lessThan, newTestString); + expect(newParams.lessThanOrEqual, newTestString); + expect(newParams.idAround, newTestString); + }); }); }); } From 846d94d058dd9dd984849cabe7d98b6dba3668d0 Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Fri, 26 Aug 2022 09:49:28 +0200 Subject: [PATCH 09/10] chore(llc): add more tests --- packages/stream_chat/test/src/core/api/requests_test.dart | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/stream_chat/test/src/core/api/requests_test.dart b/packages/stream_chat/test/src/core/api/requests_test.dart index 72f97c7b2..0bfdca7e8 100644 --- a/packages/stream_chat/test/src/core/api/requests_test.dart +++ b/packages/stream_chat/test/src/core/api/requests_test.dart @@ -43,6 +43,9 @@ void main() { idAround: 'id-around', ); + final sameOld = params.copyWith(); + expect(sameOld, equals(params)); + final newDateTime = DateTime.now().add(const Duration(days: 2)); const newTestString = 'test'; final newParams = params.copyWith( From 5b179febd6e70e5b9e42d5b7eea2440031dda60a Mon Sep 17 00:00:00 2001 From: Sahil Kumar Date: Wed, 10 Aug 2022 18:06:39 +0530 Subject: [PATCH 10/10] chore(llc): move files to correct folders. Signed-off-by: xsahil03x --- .../stream_chat/lib/src/client/client.dart | 2 +- .../lib/src/core/api/call_api.dart | 14 ++-- .../lib/src/core/api/responses.dart | 67 +---------------- .../lib/src/core/api/responses.g.dart | 20 ------ .../lib/src/core/api/stream_chat_api.dart | 2 +- .../lib/src/core/models/call_payload.dart | 72 +++++++++++++++++++ .../lib/src/core/models/call_payload.g.dart | 27 +++++++ .../test/src/core/api/call_api_test.dart | 8 +-- .../test/src/core/api/responses_test.dart | 55 ++++---------- .../src/core/models/call_payload_test.dart | 38 ++++++++++ 10 files changed, 162 insertions(+), 143 deletions(-) create mode 100644 packages/stream_chat/lib/src/core/models/call_payload.dart create mode 100644 packages/stream_chat/lib/src/core/models/call_payload.g.dart create mode 100644 packages/stream_chat/test/src/core/models/call_payload_test.dart diff --git a/packages/stream_chat/lib/src/client/client.dart b/packages/stream_chat/lib/src/client/client.dart index 73f0f95e8..07e6ed3e3 100644 --- a/packages/stream_chat/lib/src/client/client.dart +++ b/packages/stream_chat/lib/src/client/client.dart @@ -595,7 +595,7 @@ class StreamChatClient { required String callType, required String channelType, required String channelId, - }) async { + }) { return _chatApi.call.createCall( callId: callId, callType: callType, diff --git a/packages/stream_chat/lib/src/core/api/call_api.dart b/packages/stream_chat/lib/src/core/api/call_api.dart index 60fc6f886..2e40fc637 100644 --- a/packages/stream_chat/lib/src/core/api/call_api.dart +++ b/packages/stream_chat/lib/src/core/api/call_api.dart @@ -1,7 +1,7 @@ import 'package:stream_chat/src/core/api/responses.dart'; import 'package:stream_chat/src/core/http/stream_http_client.dart'; -/// Defines the api dedicated to video call operations +/// Defines the api dedicated to call operations. class CallApi { /// Initialize a new call api CallApi(this._client); @@ -25,11 +25,13 @@ class CallApi { required String channelType, required String channelId, }) async { - final response = - await _client.post(_getChannelUrl(channelId, channelType), data: { - 'id': callId, - 'type': callType, - }); + final response = await _client.post( + _getChannelUrl(channelId, channelType), + data: { + 'id': callId, + 'type': callType, + }, + ); // return response.data; return CreateCallPayload.fromJson(response.data); } diff --git a/packages/stream_chat/lib/src/core/api/responses.dart b/packages/stream_chat/lib/src/core/api/responses.dart index ddeb4b0f0..54b885f45 100644 --- a/packages/stream_chat/lib/src/core/api/responses.dart +++ b/packages/stream_chat/lib/src/core/api/responses.dart @@ -1,9 +1,9 @@ -import 'package:equatable/equatable.dart'; import 'package:json_annotation/json_annotation.dart'; import 'package:stream_chat/src/client/client.dart'; import 'package:stream_chat/src/core/api/call_api.dart'; import 'package:stream_chat/src/core/error/error.dart'; import 'package:stream_chat/src/core/models/banned_user.dart'; +import 'package:stream_chat/src/core/models/call_payload.dart'; import 'package:stream_chat/src/core/models/channel_model.dart'; import 'package:stream_chat/src/core/models/channel_state.dart'; import 'package:stream_chat/src/core/models/device.dart'; @@ -498,51 +498,6 @@ class OGAttachmentResponse extends _BaseResponse { _$OGAttachmentResponseFromJson(json); } -/// Payload for Agora call. -@JsonSerializable(createToJson: false) -class AgoraPayload { - /// Create a new instance. - const AgoraPayload({required this.channel}); - - /// Create a new instance from a [json]. - factory AgoraPayload.fromJson(Map json) => - _$AgoraPayloadFromJson(json); - - /// The Agora channel. - final String channel; -} - -/// Model containing the information about a call. -@JsonSerializable(createToJson: false) -class CallPayload extends Equatable { - /// Create a new instance. - const CallPayload({ - required this.id, - required this.provider, - this.agora, - this.hms, - }); - - /// Create a new instance from a [json]. - factory CallPayload.fromJson(Map json) => - _$CallPayloadFromJson(json); - - /// The call id. - final String id; - - /// The call provider. - final String provider; - - /// The payload specific to Agora. - final AgoraPayload? agora; - - /// The payload specific to 100ms. - final HMSPayload? hms; - - @override - List get props => [id, provider, agora, hms]; -} - /// The response to [CallApi.getCallToken] @JsonSerializable(createToJson: false) class CallTokenPayload extends _BaseResponse { @@ -570,23 +525,3 @@ class CreateCallPayload extends _BaseResponse { /// The call object. CallPayload? call; } - -/// Payload for 100ms call. -@JsonSerializable(createToJson: false) -class HMSPayload extends Equatable { - /// Create a new instance. - const HMSPayload({required this.roomId, required this.roomName}); - - /// Create a new instance from a [json]. - factory HMSPayload.fromJson(Map json) => - _$HMSPayloadFromJson(json); - - /// The id of the 100ms room. - final String roomId; - - /// The name of the 100ms room. - final String roomName; - - @override - List get props => [roomId, roomName]; -} diff --git a/packages/stream_chat/lib/src/core/api/responses.g.dart b/packages/stream_chat/lib/src/core/api/responses.g.dart index 6cc2158ed..24f5c4595 100644 --- a/packages/stream_chat/lib/src/core/api/responses.g.dart +++ b/packages/stream_chat/lib/src/core/api/responses.g.dart @@ -298,21 +298,6 @@ OGAttachmentResponse _$OGAttachmentResponseFromJson( ..titleLink = json['title_link'] as String? ..type = json['type'] as String?; -AgoraPayload _$AgoraPayloadFromJson(Map json) => AgoraPayload( - channel: json['channel'] as String, - ); - -CallPayload _$CallPayloadFromJson(Map json) => CallPayload( - id: json['id'] as String, - provider: json['provider'] as String, - agora: json['agora'] == null - ? null - : AgoraPayload.fromJson(json['agora'] as Map), - hms: json['hms'] == null - ? null - : HMSPayload.fromJson(json['hms'] as Map), - ); - CallTokenPayload _$CallTokenPayloadFromJson(Map json) => CallTokenPayload() ..duration = json['duration'] as String? @@ -326,8 +311,3 @@ CreateCallPayload _$CreateCallPayloadFromJson(Map json) => ..call = json['call'] == null ? null : CallPayload.fromJson(json['call'] as Map); - -HMSPayload _$HMSPayloadFromJson(Map json) => HMSPayload( - roomId: json['room_id'] as String, - roomName: json['room_name'] as String, - ); diff --git a/packages/stream_chat/lib/src/core/api/stream_chat_api.dart b/packages/stream_chat/lib/src/core/api/stream_chat_api.dart index c19b81a90..b3f292105 100644 --- a/packages/stream_chat/lib/src/core/api/stream_chat_api.dart +++ b/packages/stream_chat/lib/src/core/api/stream_chat_api.dart @@ -56,7 +56,7 @@ class StreamChatApi { CallApi? _call; - /// Api dedicated to guest operations + /// Api dedicated to call operations CallApi get call => _call ??= CallApi(_client); ChannelApi? _channel; diff --git a/packages/stream_chat/lib/src/core/models/call_payload.dart b/packages/stream_chat/lib/src/core/models/call_payload.dart new file mode 100644 index 000000000..e11ae788d --- /dev/null +++ b/packages/stream_chat/lib/src/core/models/call_payload.dart @@ -0,0 +1,72 @@ +import 'package:equatable/equatable.dart'; +import 'package:json_annotation/json_annotation.dart'; + +part 'call_payload.g.dart'; + +/// Model containing the information about a call. +@JsonSerializable(createToJson: false) +class CallPayload extends Equatable { + /// Create a new instance. + const CallPayload({ + required this.id, + required this.provider, + this.agora, + this.hms, + }); + + /// Create a new instance from a [json]. + factory CallPayload.fromJson(Map json) => + _$CallPayloadFromJson(json); + + /// The call id. + final String id; + + /// The call provider. + final String provider; + + /// The payload specific to Agora. + final AgoraPayload? agora; + + /// The payload specific to 100ms. + final HMSPayload? hms; + + @override + List get props => [id, provider, agora, hms]; +} + +/// Payload for Agora call. +@JsonSerializable(createToJson: false) +class AgoraPayload extends Equatable { + /// Create a new instance. + const AgoraPayload({required this.channel}); + + /// Create a new instance from a [json]. + factory AgoraPayload.fromJson(Map json) => + _$AgoraPayloadFromJson(json); + + /// The Agora channel. + final String channel; + + @override + List get props => [channel]; +} + +/// Payload for 100ms call. +@JsonSerializable(createToJson: false) +class HMSPayload extends Equatable { + /// Create a new instance. + const HMSPayload({required this.roomId, required this.roomName}); + + /// Create a new instance from a [json]. + factory HMSPayload.fromJson(Map json) => + _$HMSPayloadFromJson(json); + + /// The id of the 100ms room. + final String roomId; + + /// The name of the 100ms room. + final String roomName; + + @override + List get props => [roomId, roomName]; +} diff --git a/packages/stream_chat/lib/src/core/models/call_payload.g.dart b/packages/stream_chat/lib/src/core/models/call_payload.g.dart new file mode 100644 index 000000000..bc786cc5d --- /dev/null +++ b/packages/stream_chat/lib/src/core/models/call_payload.g.dart @@ -0,0 +1,27 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'call_payload.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +CallPayload _$CallPayloadFromJson(Map json) => CallPayload( + id: json['id'] as String, + provider: json['provider'] as String, + agora: json['agora'] == null + ? null + : AgoraPayload.fromJson(json['agora'] as Map), + hms: json['hms'] == null + ? null + : HMSPayload.fromJson(json['hms'] as Map), + ); + +AgoraPayload _$AgoraPayloadFromJson(Map json) => AgoraPayload( + channel: json['channel'] as String, + ); + +HMSPayload _$HMSPayloadFromJson(Map json) => HMSPayload( + roomId: json['room_id'] as String, + roomName: json['room_name'] as String, + ); diff --git a/packages/stream_chat/test/src/core/api/call_api_test.dart b/packages/stream_chat/test/src/core/api/call_api_test.dart index 662f84b03..f9e2265f2 100644 --- a/packages/stream_chat/test/src/core/api/call_api_test.dart +++ b/packages/stream_chat/test/src/core/api/call_api_test.dart @@ -23,12 +23,8 @@ void main() { const callId = 'test-call-id'; const path = '/calls/$callId'; - when(() => client.post( - path, - data: {}, - )) - .thenAnswer( - (_) async => successResponse(path, data: {})); + when(() => client.post(path, data: {})).thenAnswer( + (_) async => successResponse(path, data: {})); final res = await callApi.getCallToken(callId); diff --git a/packages/stream_chat/test/src/core/api/responses_test.dart b/packages/stream_chat/test/src/core/api/responses_test.dart index 75a374fb2..073d2b404 100644 --- a/packages/stream_chat/test/src/core/api/responses_test.dart +++ b/packages/stream_chat/test/src/core/api/responses_test.dart @@ -1,5 +1,6 @@ import 'dart:convert'; +import 'package:stream_chat/src/core/models/call_payload.dart'; import 'package:stream_chat/stream_chat.dart'; import 'package:test/test.dart'; @@ -4341,45 +4342,21 @@ void main() { expect(response.message, isA()); }); - test('AgoraPayload', () { + test('CallTokenPayload', () { const jsonExample = ''' - {"channel":"test"} - '''; - final response = AgoraPayload.fromJson(json.decode(jsonExample)); - expect(response.channel, isA()); - }); - - test('CallPayload', () { - const jsonExample = ''' - {"id":"test", - "provider": "test", - "agora": {"channel":"test"}, - "hms":{"room_id":"test", "room_name":"test"} - } - '''; - final response = CallPayload.fromJson(json.decode(jsonExample)); - expect(response.agora, isA()); - expect(response.hms, isA()); - expect(response.id, isA()); - expect(response.provider, isA()); - }); - }); - - test('CallTokenPayload', () { - const jsonExample = ''' {"duration": "3ms", "agora_app_id":"test", "agora_uid": 12, "token": "token"} '''; - final response = CallTokenPayload.fromJson(json.decode(jsonExample)); - expect(response.agoraAppId, isA()); - expect(response.agoraUid, isA()); - expect(response.token, isA()); - }); + final response = CallTokenPayload.fromJson(json.decode(jsonExample)); + expect(response.agoraAppId, isA()); + expect(response.agoraUid, isA()); + expect(response.token, isA()); + }); - test('CreateCallPayload', () { - const jsonExample = ''' + test('CreateCallPayload', () { + const jsonExample = ''' {"call": {"id":"test", "provider": "test", @@ -4387,16 +4364,8 @@ void main() { "hms":{"room_id":"test", "room_name":"test"} }} '''; - final response = CreateCallPayload.fromJson(json.decode(jsonExample)); - expect(response.call, isA()); - }); - - test('HMSPayload', () { - const jsonExample = ''' - {"room_id":"test", "room_name":"test"} - '''; - final response = HMSPayload.fromJson(json.decode(jsonExample)); - expect(response.roomId, isA()); - expect(response.roomName, isA()); + final response = CreateCallPayload.fromJson(json.decode(jsonExample)); + expect(response.call, isA()); + }); }); } diff --git a/packages/stream_chat/test/src/core/models/call_payload_test.dart b/packages/stream_chat/test/src/core/models/call_payload_test.dart new file mode 100644 index 000000000..a67e3beea --- /dev/null +++ b/packages/stream_chat/test/src/core/models/call_payload_test.dart @@ -0,0 +1,38 @@ +import 'dart:convert'; + +import 'package:stream_chat/src/core/models/call_payload.dart'; +import 'package:test/test.dart'; + +void main() { + test('CallPayload', () { + const jsonExample = ''' + {"id":"test", + "provider": "test", + "agora": {"channel":"test"}, + "hms":{"room_id":"test", "room_name":"test"} + } + '''; + final response = CallPayload.fromJson(json.decode(jsonExample)); + expect(response.agora, isA()); + expect(response.hms, isA()); + expect(response.id, isA()); + expect(response.provider, isA()); + }); + + test('AgoraPayload', () { + const jsonExample = ''' + {"channel":"test"} + '''; + final response = AgoraPayload.fromJson(json.decode(jsonExample)); + expect(response.channel, isA()); + }); + + test('HMSPayload', () { + const jsonExample = ''' + {"room_id":"test", "room_name":"test"} + '''; + final response = HMSPayload.fromJson(json.decode(jsonExample)); + expect(response.roomId, isA()); + expect(response.roomName, isA()); + }); +}