1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-26 14:59:22 +00:00
comunicmobile/lib/helpers/calls_helper.dart

38 lines
1.1 KiB
Dart

import 'package:comunic/helpers/websocket_helper.dart';
import 'package:comunic/lists/call_members_list.dart';
import 'package:comunic/models/call_config.dart';
import 'package:comunic/models/call_member.dart';
/// Calls helper
///
/// @author Pierre Hubert
class CallsHelper {
/// Join a call
static Future<void> join(int convID) async =>
await ws("calls/join", {"convID": convID});
/// Leave a call
static Future<void> leave(int convID) async =>
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>(),
);
}
/// Get current call members
static Future<CallMembersList> getMembers(int callID) async =>
CallMembersList()
..addAll((await ws("calls/members", {"callID": callID}))
.map((f) => CallMember(
id: f["userID"],
status: f["ready"] ? MemberStatus.READY : MemberStatus.JOINED,
))
.toList()
.cast<CallMember>());
}