Merge branch 'td/cacheserverprofile' into 'main'
cache option to fetchOwnProfileFromServer and missing awaits in group call enter/leave See merge request famedly/company/frontend/famedlysdk!1243
This commit is contained in:
commit
c5aa899038
|
|
@ -1,3 +1,7 @@
|
||||||
|
## [0.17.1] - 20th Feb 2023
|
||||||
|
- chore: add missing awaits in group call enter and leave funcs (td)
|
||||||
|
- chore: add useServerCache option to fetchOwnProfileFromServer and fix missing awaits (td)
|
||||||
|
|
||||||
## [0.17.0] - 17th Feb 2023
|
## [0.17.0] - 17th Feb 2023
|
||||||
- fix: ability to upgrade audio calls to video calls (td)
|
- fix: ability to upgrade audio calls to video calls (td)
|
||||||
- chore: add a fetchOwnProfileFromServer method which tries to get ownProfile from server first, disk then (td)
|
- chore: add a fetchOwnProfileFromServer method which tries to get ownProfile from server first, disk then (td)
|
||||||
|
|
|
||||||
|
|
@ -757,21 +757,23 @@ class Client extends MatrixApi {
|
||||||
/// Returns the user's own displayname and avatar url. In Matrix it is possible that
|
/// Returns the user's own displayname and avatar url. In Matrix it is possible that
|
||||||
/// one user can have different displaynames and avatar urls in different rooms.
|
/// one user can have different displaynames and avatar urls in different rooms.
|
||||||
/// Tries to get the profile from homeserver first, if failed, falls back to a profile
|
/// Tries to get the profile from homeserver first, if failed, falls back to a profile
|
||||||
/// from a room where the user exists.
|
/// from a room where the user exists. Set `useServerCache` to true to get any
|
||||||
Future<Profile> fetchOwnProfileFromServer() async {
|
/// prior value from this function
|
||||||
|
Future<Profile> fetchOwnProfileFromServer(
|
||||||
|
{bool useServerCache = false}) async {
|
||||||
try {
|
try {
|
||||||
return getProfileFromUserId(
|
return await getProfileFromUserId(
|
||||||
userID!,
|
userID!,
|
||||||
getFromRooms: false,
|
getFromRooms: false,
|
||||||
cache: false,
|
cache: useServerCache,
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
Logs().w(
|
Logs().w(
|
||||||
'[Matrix] getting profile from homeserver failed, falling back to first room with required profile');
|
'[Matrix] getting profile from homeserver failed, falling back to first room with required profile');
|
||||||
return getProfileFromUserId(
|
return await getProfileFromUserId(
|
||||||
userID!,
|
userID!,
|
||||||
getFromRooms: true,
|
getFromRooms: true,
|
||||||
cache: false,
|
cache: true,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -790,7 +792,8 @@ class Client extends MatrixApi {
|
||||||
cache: cache,
|
cache: cache,
|
||||||
);
|
);
|
||||||
|
|
||||||
final Map<String, ProfileInformation> _profileCache = {};
|
final Map<String, ProfileInformation> _profileRoomsCache = {};
|
||||||
|
final Map<String, ProfileInformation> _profileServerCache = {};
|
||||||
|
|
||||||
/// Get the combined profile information for this user.
|
/// Get the combined profile information for this user.
|
||||||
/// If [getFromRooms] is true then the profile will first be searched from the
|
/// If [getFromRooms] is true then the profile will first be searched from the
|
||||||
|
|
@ -801,12 +804,14 @@ class Client extends MatrixApi {
|
||||||
/// become outdated if the user changes the displayname or avatar in this session.
|
/// become outdated if the user changes the displayname or avatar in this session.
|
||||||
Future<Profile> getProfileFromUserId(String userId,
|
Future<Profile> getProfileFromUserId(String userId,
|
||||||
{bool cache = true, bool getFromRooms = true}) async {
|
{bool cache = true, bool getFromRooms = true}) async {
|
||||||
var profile = _profileCache[userId];
|
var profile =
|
||||||
|
getFromRooms ? _profileRoomsCache[userId] : _profileServerCache[userId];
|
||||||
if (cache && profile != null) {
|
if (cache && profile != null) {
|
||||||
return Profile(
|
return Profile(
|
||||||
userId: userId,
|
userId: userId,
|
||||||
displayName: profile.displayname,
|
displayName: profile.displayname,
|
||||||
avatarUrl: profile.avatarUrl);
|
avatarUrl: profile.avatarUrl,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (getFromRooms) {
|
if (getFromRooms) {
|
||||||
|
|
@ -816,20 +821,27 @@ class Client extends MatrixApi {
|
||||||
if (room != null) {
|
if (room != null) {
|
||||||
final user =
|
final user =
|
||||||
room.getParticipants().firstWhere((User user) => user.id == userId);
|
room.getParticipants().firstWhere((User user) => user.id == userId);
|
||||||
return Profile(
|
final profileFromRooms = Profile(
|
||||||
userId: userId,
|
userId: userId,
|
||||||
displayName: user.displayName,
|
displayName: user.displayName,
|
||||||
avatarUrl: user.avatarUrl);
|
avatarUrl: user.avatarUrl,
|
||||||
|
);
|
||||||
|
_profileRoomsCache[userId] = ProfileInformation(
|
||||||
|
avatarUrl: profileFromRooms.avatarUrl,
|
||||||
|
displayname: profileFromRooms.displayName,
|
||||||
|
);
|
||||||
|
return profileFromRooms;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
profile = await getUserProfile(userId);
|
profile = await getUserProfile(userId);
|
||||||
if (cache || _profileCache.containsKey(userId)) {
|
if (cache || _profileServerCache.containsKey(userId)) {
|
||||||
_profileCache[userId] = profile;
|
_profileServerCache[userId] = profile;
|
||||||
}
|
}
|
||||||
return Profile(
|
return Profile(
|
||||||
userId: userId,
|
userId: userId,
|
||||||
displayName: profile.displayname,
|
displayName: profile.displayname,
|
||||||
avatarUrl: profile.avatarUrl);
|
avatarUrl: profile.avatarUrl,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
final List<ArchivedRoom> _archivedRooms = [];
|
final List<ArchivedRoom> _archivedRooms = [];
|
||||||
|
|
|
||||||
|
|
@ -406,7 +406,7 @@ class GroupCall {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// enter the group call.
|
/// enter the group call.
|
||||||
void enter() async {
|
Future<void> enter() async {
|
||||||
if (!(state == GroupCallState.LocalCallFeedUninitialized ||
|
if (!(state == GroupCallState.LocalCallFeedUninitialized ||
|
||||||
state == GroupCallState.LocalCallFeedInitialized)) {
|
state == GroupCallState.LocalCallFeedInitialized)) {
|
||||||
throw Exception('Cannot enter call in the $state state');
|
throw Exception('Cannot enter call in the $state state');
|
||||||
|
|
@ -449,14 +449,14 @@ class GroupCall {
|
||||||
voip.delegate.handleNewGroupCall(this);
|
voip.delegate.handleNewGroupCall(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void dispose() {
|
Future<void> dispose() async {
|
||||||
if (localUserMediaStream != null) {
|
if (localUserMediaStream != null) {
|
||||||
removeUserMediaStream(localUserMediaStream!);
|
removeUserMediaStream(localUserMediaStream!);
|
||||||
localUserMediaStream = null;
|
localUserMediaStream = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (localScreenshareStream != null) {
|
if (localScreenshareStream != null) {
|
||||||
stopMediaStream(localScreenshareStream!.stream);
|
await stopMediaStream(localScreenshareStream!.stream);
|
||||||
removeScreenshareStream(localScreenshareStream!);
|
removeScreenshareStream(localScreenshareStream!);
|
||||||
localScreenshareStream = null;
|
localScreenshareStream = null;
|
||||||
localDesktopCapturerSourceId = null;
|
localDesktopCapturerSourceId = null;
|
||||||
|
|
@ -464,7 +464,7 @@ class GroupCall {
|
||||||
|
|
||||||
_removeParticipant(client.userID!);
|
_removeParticipant(client.userID!);
|
||||||
|
|
||||||
removeMemberStateEvent();
|
await removeMemberStateEvent();
|
||||||
|
|
||||||
final callsCopy = calls.toList();
|
final callsCopy = calls.toList();
|
||||||
callsCopy.forEach((element) {
|
callsCopy.forEach((element) {
|
||||||
|
|
@ -473,11 +473,11 @@ class GroupCall {
|
||||||
|
|
||||||
activeSpeaker = null;
|
activeSpeaker = null;
|
||||||
activeSpeakerLoopTimeout?.cancel();
|
activeSpeakerLoopTimeout?.cancel();
|
||||||
_callSubscription?.cancel();
|
await _callSubscription?.cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
void leave() {
|
Future<void> leave() async {
|
||||||
dispose();
|
await dispose();
|
||||||
setState(GroupCallState.LocalCallFeedUninitialized);
|
setState(GroupCallState.LocalCallFeedUninitialized);
|
||||||
voip.currentGroupCID = null;
|
voip.currentGroupCID = null;
|
||||||
voip.delegate.handleGroupCallEnded(this);
|
voip.delegate.handleGroupCallEnded(this);
|
||||||
|
|
@ -487,7 +487,7 @@ class GroupCall {
|
||||||
justLeftGroupCall.intent != 'm.room' &&
|
justLeftGroupCall.intent != 'm.room' &&
|
||||||
justLeftGroupCall.participants.isEmpty &&
|
justLeftGroupCall.participants.isEmpty &&
|
||||||
room.canCreateGroupCall) {
|
room.canCreateGroupCall) {
|
||||||
terminate();
|
await terminate();
|
||||||
} else {
|
} else {
|
||||||
Logs().d(
|
Logs().d(
|
||||||
'[VOIP] left group call but cannot terminate. participants: ${participants.length}, pl: ${room.canCreateGroupCall}');
|
'[VOIP] left group call but cannot terminate. participants: ${participants.length}, pl: ${room.canCreateGroupCall}');
|
||||||
|
|
@ -495,10 +495,10 @@ class GroupCall {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// terminate group call.
|
/// terminate group call.
|
||||||
void terminate({bool emitStateEvent = true}) async {
|
Future<void> terminate({bool emitStateEvent = true}) async {
|
||||||
final existingStateEvent =
|
final existingStateEvent =
|
||||||
room.getState(EventTypes.GroupCallPrefix, groupCallId);
|
room.getState(EventTypes.GroupCallPrefix, groupCallId);
|
||||||
dispose();
|
await dispose();
|
||||||
participants = [];
|
participants = [];
|
||||||
voip.groupCalls.remove(room.id);
|
voip.groupCalls.remove(room.id);
|
||||||
voip.groupCalls.remove(groupCallId);
|
voip.groupCalls.remove(groupCallId);
|
||||||
|
|
@ -1116,8 +1116,8 @@ class GroupCall {
|
||||||
onGroupCallEvent.add(GroupCallEvent.UserMediaStreamsChanged);
|
onGroupCallEvent.add(GroupCallEvent.UserMediaStreamsChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
void replaceUserMediaStream(
|
Future<void> replaceUserMediaStream(WrappedMediaStream existingStream,
|
||||||
WrappedMediaStream existingStream, WrappedMediaStream replacementStream) {
|
WrappedMediaStream replacementStream) async {
|
||||||
final streamIndex = userMediaStreams
|
final streamIndex = userMediaStreams
|
||||||
.indexWhere((stream) => stream.userId == existingStream.userId);
|
.indexWhere((stream) => stream.userId == existingStream.userId);
|
||||||
|
|
||||||
|
|
@ -1127,7 +1127,7 @@ class GroupCall {
|
||||||
|
|
||||||
userMediaStreams.replaceRange(streamIndex, 1, [replacementStream]);
|
userMediaStreams.replaceRange(streamIndex, 1, [replacementStream]);
|
||||||
|
|
||||||
existingStream.dispose();
|
await existingStream.dispose();
|
||||||
//replacementStream.measureVolumeActivity(true);
|
//replacementStream.measureVolumeActivity(true);
|
||||||
onGroupCallEvent.add(GroupCallEvent.UserMediaStreamsChanged);
|
onGroupCallEvent.add(GroupCallEvent.UserMediaStreamsChanged);
|
||||||
}
|
}
|
||||||
|
|
@ -1225,8 +1225,8 @@ class GroupCall {
|
||||||
onGroupCallEvent.add(GroupCallEvent.ScreenshareStreamsChanged);
|
onGroupCallEvent.add(GroupCallEvent.ScreenshareStreamsChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
void replaceScreenshareStream(
|
Future<void> replaceScreenshareStream(WrappedMediaStream existingStream,
|
||||||
WrappedMediaStream existingStream, WrappedMediaStream replacementStream) {
|
WrappedMediaStream replacementStream) async {
|
||||||
final streamIndex = screenshareStreams
|
final streamIndex = screenshareStreams
|
||||||
.indexWhere((stream) => stream.userId == existingStream.userId);
|
.indexWhere((stream) => stream.userId == existingStream.userId);
|
||||||
|
|
||||||
|
|
@ -1236,7 +1236,7 @@ class GroupCall {
|
||||||
|
|
||||||
screenshareStreams.replaceRange(streamIndex, 1, [replacementStream]);
|
screenshareStreams.replaceRange(streamIndex, 1, [replacementStream]);
|
||||||
|
|
||||||
existingStream.dispose();
|
await existingStream.dispose();
|
||||||
onGroupCallEvent.add(GroupCallEvent.ScreenshareStreamsChanged);
|
onGroupCallEvent.add(GroupCallEvent.ScreenshareStreamsChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -660,15 +660,15 @@ class VoIP {
|
||||||
|
|
||||||
Future<void> startGroupCalls() async {
|
Future<void> startGroupCalls() async {
|
||||||
final rooms = client.rooms;
|
final rooms = client.rooms;
|
||||||
rooms.forEach((element) {
|
for (final room in rooms) {
|
||||||
createGroupCallForRoom(element);
|
await createGroupCallForRoom(room);
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void stopGroupCalls() {
|
Future<void> stopGroupCalls() async {
|
||||||
groupCalls.forEach((_, groupCall) {
|
for (final groupCall in groupCalls.values) {
|
||||||
groupCall.terminate();
|
await groupCall.terminate();
|
||||||
});
|
}
|
||||||
groupCalls.clear();
|
groupCalls.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
name: matrix
|
name: matrix
|
||||||
description: Matrix Dart SDK
|
description: Matrix Dart SDK
|
||||||
version: 0.17.0
|
version: 0.17.1
|
||||||
homepage: https://famedly.com
|
homepage: https://famedly.com
|
||||||
repository: https://gitlab.com/famedly/company/frontend/famedlysdk.git
|
repository: https://gitlab.com/famedly/company/frontend/famedlysdk.git
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue