1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-25 22:39:22 +00:00

Handles new signal events

This commit is contained in:
Pierre HUBERT 2020-04-20 16:23:33 +02:00
parent 80f05cb008
commit 473402149a
3 changed files with 46 additions and 0 deletions

View File

@ -3,6 +3,8 @@ import 'dart:async';
import 'package:comunic/models/comment.dart';
import 'package:comunic/models/conversation_message.dart';
import 'package:event_bus/event_bus.dart';
import 'package:flutter_webrtc/rtc_ice_candidate.dart';
import 'package:flutter_webrtc/rtc_session_description.dart';
/// Events helper
///
@ -86,6 +88,23 @@ class UserLeftCallEvent {
UserLeftCallEvent(this.callID, this.userID);
}
/// New call signal event
class NewCallSignalEvent {
final int callID;
final int peerID;
final RTCSessionDescription sessionDescription;
final RTCIceCandidate candidate;
const NewCallSignalEvent({
this.callID,
this.peerID,
this.sessionDescription,
this.candidate,
}) : assert(callID != null),
assert(peerID != null),
assert(sessionDescription != null || candidate != null);
}
/// Call peer ready event
class CallPeerReadyEvent {
final int callID;

View File

@ -7,6 +7,8 @@ import 'package:comunic/helpers/events_helper.dart';
import 'package:comunic/models/api_request.dart';
import 'package:comunic/models/config.dart';
import 'package:comunic/models/ws_message.dart';
import 'package:flutter_webrtc/rtc_ice_candidate.dart';
import 'package:flutter_webrtc/rtc_session_description.dart';
import 'package:web_socket_channel/web_socket_channel.dart';
/// User web socket helper
@ -172,6 +174,21 @@ class WebSocketHelper {
UserLeftCallEvent(msg.data["callID"], msg.data["userID"]));
break;
// Got new call signal
case "new_call_signal":
Map<String, dynamic> signalData = msg.data["data"];
EventsHelper.emit(NewCallSignalEvent(
callID: msg.data["callID"],
peerID: msg.data["peerID"],
candidate: signalData.containsKey("candidate")
? RTCIceCandidate(
signalData["candidate"], null, signalData["sdpMLineIndex"])
: null,
sessionDescription: signalData.containsKey("type")
? RTCSessionDescription(signalData["sdp"], signalData["type"])
: null));
break;
// Call peer ready event
case "call_peer_ready":
EventsHelper.emit(

View File

@ -90,6 +90,10 @@ class _CallScreenState extends SafeState<CallScreen> {
if (e.callID == convID) _removeMember(e.userID);
});
this.listen<NewCallSignalEvent>((e) {
if (e.callID == convID) _newSignal(e);
});
this.listen<CallPeerReadyEvent>((e) {
if (e.callID == convID) _memberReady(e.peerID);
});
@ -145,6 +149,12 @@ class _CallScreenState extends SafeState<CallScreen> {
}
}
/// Call this method each time we get a new signal
void _newSignal(NewCallSignalEvent ev) {
print(
"${ev.peerID} - ${ev.sessionDescription != null ? ev.sessionDescription.toMap() : ev.candidate.toMap()}");
}
/// Call this when a user has interrupted streaming
void _removeRemotePeerConnection(int memberID) {
_membersList.getUser(memberID).status = MemberStatus.JOINED;