1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-10-23 15:03:22 +00:00
comunicmobile/lib/helpers/calls_helper.dart

42 lines
1.3 KiB
Dart
Raw Normal View History

2020-04-20 11:24:40 +00:00
import 'package:comunic/helpers/websocket_helper.dart';
2020-04-20 12:02:32 +00:00
import 'package:comunic/lists/call_members_list.dart';
2020-04-20 11:43:17 +00:00
import 'package:comunic/models/call_config.dart';
2020-04-20 12:02:32 +00:00
import 'package:comunic/models/call_member.dart';
2020-04-20 11:24:40 +00:00
/// Calls helper
///
/// @author Pierre Hubert
class CallsHelper {
/// Join a call
static Future<void> join(int convID) async =>
2020-04-20 11:43:17 +00:00
await ws("calls/join", {"convID": convID});
2020-04-20 11:24:40 +00:00
/// Leave a call
static Future<void> leave(int convID) async =>
2020-04-20 11:43:17 +00:00
await ws("calls/leave", {"convID": convID});
/// Get calls configuration
static Future<CallConfig> getConfig() async {
final response = await ws("calls/config", {});
return CallConfig(
iceServers: response["iceServers"].cast<String>(),
);
}
2020-04-20 12:02:32 +00:00
/// Get current call members
static Future<CallMembersList> getMembers(int callID) async =>
CallMembersList()
..addAll((await ws("calls/members", {"callID": callID}))
.map((f) => CallMember(
2020-04-20 13:02:49 +00:00
userID: f["userID"],
2020-04-20 12:02:32 +00:00
status: f["ready"] ? MemberStatus.READY : MemberStatus.JOINED,
))
.toList()
.cast<CallMember>());
2020-04-20 13:50:01 +00:00
/// Request an offer to access another peer's stream
static Future<void> requestOffer(int callID, int peerID) async =>
await ws("calls/request_offer", {"callID": callID, "peerID": peerID});
2020-04-20 11:24:40 +00:00
}