Merge branch 'feat/room-state-event-listener' into 'main'
Add room state listener See merge request famedly/company/frontend/famedlysdk!1095
This commit is contained in:
commit
543875e8cf
|
|
@ -1098,6 +1098,8 @@ class Client extends MatrixApi {
|
||||||
|
|
||||||
final CachedStreamController<Event> onGroupMember = CachedStreamController();
|
final CachedStreamController<Event> onGroupMember = CachedStreamController();
|
||||||
|
|
||||||
|
final CachedStreamController<Event> onRoomState = CachedStreamController();
|
||||||
|
|
||||||
/// How long should the app wait until it retrys the synchronisation after
|
/// How long should the app wait until it retrys the synchronisation after
|
||||||
/// an error?
|
/// an error?
|
||||||
int syncErrorTimeoutSec = 3;
|
int syncErrorTimeoutSec = 3;
|
||||||
|
|
|
||||||
|
|
@ -197,6 +197,8 @@ class Room {
|
||||||
}
|
}
|
||||||
|
|
||||||
(states[state.type] ??= {})[stateKey] = state;
|
(states[state.type] ??= {})[stateKey] = state;
|
||||||
|
|
||||||
|
client.onRoomState.add(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// ID of the fully read marker event.
|
/// ID of the fully read marker event.
|
||||||
|
|
|
||||||
|
|
@ -197,9 +197,6 @@ class GroupCall {
|
||||||
|
|
||||||
Timer? activeSpeakerLoopTimeout;
|
Timer? activeSpeakerLoopTimeout;
|
||||||
|
|
||||||
Timer? retryCallLoopTimeout;
|
|
||||||
Map<String, num> retryCallCounts = {};
|
|
||||||
|
|
||||||
final CachedStreamController<GroupCall> onGroupCallFeedsChanged =
|
final CachedStreamController<GroupCall> onGroupCallFeedsChanged =
|
||||||
CachedStreamController();
|
CachedStreamController();
|
||||||
|
|
||||||
|
|
@ -430,8 +427,6 @@ class GroupCall {
|
||||||
onMemberStateChanged(stateEvent);
|
onMemberStateChanged(stateEvent);
|
||||||
});
|
});
|
||||||
|
|
||||||
retryCallLoopTimeout = Timer.periodic(
|
|
||||||
Duration(milliseconds: retryCallInterval), onRetryCallLoop);
|
|
||||||
onActiveSpeakerLoop();
|
onActiveSpeakerLoop();
|
||||||
|
|
||||||
voip.currentGroupCID = groupCallId;
|
voip.currentGroupCID = groupCallId;
|
||||||
|
|
@ -467,8 +462,6 @@ class GroupCall {
|
||||||
|
|
||||||
activeSpeaker = null;
|
activeSpeaker = null;
|
||||||
activeSpeakerLoopTimeout?.cancel();
|
activeSpeakerLoopTimeout?.cancel();
|
||||||
retryCallCounts.clear();
|
|
||||||
retryCallLoopTimeout?.cancel();
|
|
||||||
_callSubscription?.cancel();
|
_callSubscription?.cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -876,24 +869,6 @@ class GroupCall {
|
||||||
return memberDevices[0];
|
return memberDevices[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Monitor member status and respond to mesh calls by regularly updating
|
|
||||||
/// the state event in the room
|
|
||||||
void onRetryCallLoop(Timer _) async {
|
|
||||||
final memberStateEvents =
|
|
||||||
await getStateEventsList(EventTypes.GroupCallMemberPrefix);
|
|
||||||
|
|
||||||
memberStateEvents.forEach((event) {
|
|
||||||
final memberId = event.senderId;
|
|
||||||
final existingCall =
|
|
||||||
calls.indexWhere((call) => call.remoteUser!.id == memberId) != -1;
|
|
||||||
final retryCallCount = retryCallCounts[memberId] ?? 0;
|
|
||||||
if (!existingCall && retryCallCount < 3) {
|
|
||||||
retryCallCounts[memberId] = retryCallCount + 1;
|
|
||||||
onMemberStateChanged(event);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
CallSession? getCallByUserId(String userId) {
|
CallSession? getCallByUserId(String userId) {
|
||||||
final value = calls.where((item) => item.remoteUser!.id == userId);
|
final value = calls.where((item) => item.remoteUser!.id == userId);
|
||||||
if (value.isNotEmpty) {
|
if (value.isNotEmpty) {
|
||||||
|
|
@ -1064,10 +1039,6 @@ class GroupCall {
|
||||||
call.isLocalVideoMuted != videoMuted) {
|
call.isLocalVideoMuted != videoMuted) {
|
||||||
call.setLocalVideoMuted(videoMuted);
|
call.setLocalVideoMuted(videoMuted);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state == CallState.kConnected) {
|
|
||||||
retryCallCounts.remove(call.remoteUser!.id);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void onCallHangup(CallSession call) {
|
void onCallHangup(CallSession call) {
|
||||||
|
|
|
||||||
|
|
@ -68,9 +68,14 @@ class VoIP {
|
||||||
client.onAssertedIdentityReceived.stream
|
client.onAssertedIdentityReceived.stream
|
||||||
.listen((event) => _handleEvent(event, onAssertedIdentityReceived));
|
.listen((event) => _handleEvent(event, onAssertedIdentityReceived));
|
||||||
|
|
||||||
client.onGroupCallRequest.stream.listen((event) {
|
client.onRoomState.stream.listen((event) {
|
||||||
Logs().v('[VOIP] onGroupCallRequest: type ${event.toJson()}.');
|
if ([
|
||||||
onRoomStateChanged(event);
|
EventTypes.GroupCallPrefix,
|
||||||
|
EventTypes.GroupCallMemberPrefix,
|
||||||
|
].contains(event.type)) {
|
||||||
|
Logs().v('[VOIP] onRoomState: type ${event.toJson()}.');
|
||||||
|
onRoomStateChanged(event);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
client.onToDeviceEvent.stream.listen((event) {
|
client.onToDeviceEvent.stream.listen((event) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue