mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-22 21:09:21 +00:00
Handles peer ready & peer destroyed streams events
This commit is contained in:
parent
0f99e807f8
commit
99ecc399ee
@ -86,6 +86,22 @@ class UserLeftCallEvent {
|
|||||||
UserLeftCallEvent(this.callID, this.userID);
|
UserLeftCallEvent(this.callID, this.userID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Call peer ready event
|
||||||
|
class CallPeerReadyEvent {
|
||||||
|
final int callID;
|
||||||
|
final int peerID;
|
||||||
|
|
||||||
|
CallPeerReadyEvent(this.callID, this.peerID);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Call peer interrupted streaming event
|
||||||
|
class CallPeerInterruptedStreamingEvent {
|
||||||
|
final int callID;
|
||||||
|
final int peerID;
|
||||||
|
|
||||||
|
CallPeerInterruptedStreamingEvent(this.callID, this.peerID);
|
||||||
|
}
|
||||||
|
|
||||||
/// Call closed event
|
/// Call closed event
|
||||||
class CallClosedEvent {
|
class CallClosedEvent {
|
||||||
final int callID;
|
final int callID;
|
||||||
|
@ -26,7 +26,6 @@ class WebSocketHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Get WebSocket access token
|
/// Get WebSocket access token
|
||||||
//TODO : Handles the case user tokens were destroyed (auto sign-out user)
|
|
||||||
static Future<String> _getWsToken() async =>
|
static Future<String> _getWsToken() async =>
|
||||||
(await APIRequest(uri: "ws/token", needLogin: true).exec())
|
(await APIRequest(uri: "ws/token", needLogin: true).exec())
|
||||||
.assertOk()
|
.assertOk()
|
||||||
@ -173,7 +172,19 @@ class WebSocketHelper {
|
|||||||
UserLeftCallEvent(msg.data["callID"], msg.data["userID"]));
|
UserLeftCallEvent(msg.data["callID"], msg.data["userID"]));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// The call has been close
|
// Call peer ready event
|
||||||
|
case "call_peer_ready":
|
||||||
|
EventsHelper.emit(
|
||||||
|
CallPeerReadyEvent(msg.data["callID"], msg.data["peerID"]));
|
||||||
|
break;
|
||||||
|
|
||||||
|
// Call peer interrupted streaming event
|
||||||
|
case "call_peer_interrupted_streaming":
|
||||||
|
EventsHelper.emit(CallPeerInterruptedStreamingEvent(
|
||||||
|
msg.data["callID"], msg.data["peerID"]));
|
||||||
|
break;
|
||||||
|
|
||||||
|
// The call has been closed
|
||||||
case "call_closed":
|
case "call_closed":
|
||||||
EventsHelper.emit(CallClosedEvent(msg.data));
|
EventsHelper.emit(CallClosedEvent(msg.data));
|
||||||
break;
|
break;
|
||||||
|
@ -11,4 +11,7 @@ class CallMembersList extends AbstractList<CallMember> {
|
|||||||
|
|
||||||
/// Remove a specific member from this list
|
/// Remove a specific member from this list
|
||||||
void removeUser(int userID) => this.removeWhere((f) => f.id == userID);
|
void removeUser(int userID) => this.removeWhere((f) => f.id == userID);
|
||||||
|
|
||||||
|
/// Get the connection of a specific user
|
||||||
|
CallMember getUser(int userID) => this.firstWhere((f) => f.id == userID);
|
||||||
}
|
}
|
||||||
|
@ -8,9 +8,9 @@ enum MemberStatus { JOINED, READY }
|
|||||||
|
|
||||||
class CallMember {
|
class CallMember {
|
||||||
final int id;
|
final int id;
|
||||||
final MemberStatus status;
|
MemberStatus status;
|
||||||
|
|
||||||
const CallMember({
|
CallMember({
|
||||||
@required this.id,
|
@required this.id,
|
||||||
this.status = MemberStatus.JOINED,
|
this.status = MemberStatus.JOINED,
|
||||||
}) : assert(id != null),
|
}) : assert(id != null),
|
||||||
|
@ -82,6 +82,7 @@ class _CallScreenState extends SafeState<CallScreen> {
|
|||||||
|
|
||||||
// Register to events
|
// Register to events
|
||||||
this.listenChangeState<UserJoinedCallEvent>((e) {
|
this.listenChangeState<UserJoinedCallEvent>((e) {
|
||||||
|
// TODO : get user information if required
|
||||||
if (e.callID == convID) _membersList.add(CallMember(id: e.userID));
|
if (e.callID == convID) _membersList.add(CallMember(id: e.userID));
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -89,6 +90,14 @@ class _CallScreenState extends SafeState<CallScreen> {
|
|||||||
if (e.callID == convID) _removeMember(e.userID);
|
if (e.callID == convID) _removeMember(e.userID);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.listen<CallPeerReadyEvent>((e) {
|
||||||
|
if (e.callID == convID) _memberReady(e.peerID);
|
||||||
|
});
|
||||||
|
|
||||||
|
this.listen<CallPeerInterruptedStreamingEvent>((e) {
|
||||||
|
if (e.callID == convID) _removeRemotePeerConnection(e.peerID);
|
||||||
|
});
|
||||||
|
|
||||||
this.listen<CallClosedEvent>((e) {
|
this.listen<CallClosedEvent>((e) {
|
||||||
if (e.callID == convID) _leaveCall(needConfirm: false);
|
if (e.callID == convID) _leaveCall(needConfirm: false);
|
||||||
});
|
});
|
||||||
@ -98,7 +107,7 @@ class _CallScreenState extends SafeState<CallScreen> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Do clean up operations when call screen is destroyed
|
/// Do clean up operations when call screen is destroyed
|
||||||
void _endCall() async {
|
void _endCall() async {
|
||||||
try {
|
try {
|
||||||
// Leave the call
|
// Leave the call
|
||||||
@ -108,7 +117,7 @@ class _CallScreenState extends SafeState<CallScreen> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make us leave the call
|
/// Make us leave the call
|
||||||
void _leaveCall({bool needConfirm = true}) async {
|
void _leaveCall({bool needConfirm = true}) async {
|
||||||
if (needConfirm &&
|
if (needConfirm &&
|
||||||
!await showConfirmDialog(
|
!await showConfirmDialog(
|
||||||
@ -118,7 +127,23 @@ class _CallScreenState extends SafeState<CallScreen> {
|
|||||||
MainController.of(context).popPage();
|
MainController.of(context).popPage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Call this when a user started to stream media
|
||||||
|
void _memberReady(int memberID) {
|
||||||
|
_membersList.getUser(memberID).status = MemberStatus.READY;
|
||||||
|
|
||||||
|
setState((){});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Call this when a user has interrupted streaming
|
||||||
|
void _removeRemotePeerConnection(int memberID) {
|
||||||
|
_membersList.getUser(memberID).status = MemberStatus.JOINED;
|
||||||
|
setState((){});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Call this when a members has completely left the call
|
||||||
void _removeMember(int memberID) {
|
void _removeMember(int memberID) {
|
||||||
|
_removeRemotePeerConnection(memberID);
|
||||||
|
|
||||||
_membersList.removeUser(memberID);
|
_membersList.removeUser(memberID);
|
||||||
setState(() {});
|
setState(() {});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user