1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-12-02 01:36:27 +00:00
comunicmobile/lib/helpers/calls_helper.dart

55 lines
1.7 KiB
Dart
Raw Normal View History

2020-04-20 15:29:36 +00:00
import 'dart:convert';
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 15:29:36 +00:00
import 'package:flutter_webrtc/rtc_session_description.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 15:29:36 +00:00
/// Send a Session Description message to the server
static Future<void> sendSessionDescription(
int callID, int peerID, RTCSessionDescription sdp) async =>
await ws("calls/signal", {
"callID": callID,
"peerID": peerID,
"type": "SDP",
"data": jsonEncode(sdp.toMap())
});
2020-04-20 11:24:40 +00:00
}