-
Notifications
You must be signed in to change notification settings - Fork 346
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1295 from GetStream/3rd-party-video-integration
- Loading branch information
Showing
13 changed files
with
396 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
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 call operations. | ||
class CallApi { | ||
/// Initialize a new call api | ||
CallApi(this._client); | ||
|
||
final StreamHttpClient _client; | ||
|
||
/// Returns a token dedicated to the [callId] | ||
Future<CallTokenPayload> getCallToken(String callId) async { | ||
final response = await _client.post( | ||
'/calls/$callId', | ||
data: {}, | ||
); | ||
// return response.data; | ||
return CallTokenPayload.fromJson(response.data); | ||
} | ||
|
||
/// Creates a new call | ||
Future<CreateCallPayload> createCall({ | ||
required String callId, | ||
required String callType, | ||
required String channelType, | ||
required String channelId, | ||
}) 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'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
packages/stream_chat/lib/src/core/models/call_payload.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String, dynamic> 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<Object?> 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<String, dynamic> json) => | ||
_$AgoraPayloadFromJson(json); | ||
|
||
/// The Agora channel. | ||
final String channel; | ||
|
||
@override | ||
List<Object?> 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<String, dynamic> json) => | ||
_$HMSPayloadFromJson(json); | ||
|
||
/// The id of the 100ms room. | ||
final String roomId; | ||
|
||
/// The name of the 100ms room. | ||
final String roomName; | ||
|
||
@override | ||
List<Object?> get props => [roomId, roomName]; | ||
} |
27 changes: 27 additions & 0 deletions
27
packages/stream_chat/lib/src/core/models/call_payload.g.dart
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import 'package:dio/dio.dart'; | ||
import 'package:mocktail/mocktail.dart'; | ||
import 'package:stream_chat/src/core/api/call_api.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: <String, dynamic>{})); | ||
|
||
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: <String, dynamic>{})); | ||
|
||
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); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.