mirror of
https://github.com/vector-im/element-ios.git
synced 2024-09-29 07:42:40 +00:00
ece07c4446
* Cancel automatically a Voice Broadcast from a room after an app crash * We limit for the moment the uncompleted voice broadcast cleaning to the breadcrumbs rooms list By considering potential performance issues, we decided to limit the uncompleted VB cleaning in the recents list service: - we run the process only once when the application is resumed - we run the process only on the breadcrumbs rooms list This prevent us from checking several times in parallel the same room (because a room may be listed in several recents sections) This prevent us from checking several times the same room (each room should be checked only once after the app resume) If a room is not checked from the recents list, a sanity check is still done in RoomViewController (to clean the room when the user opens it)
54 lines
2.4 KiB
Swift
54 lines
2.4 KiB
Swift
//
|
|
// Copyright 2022 New Vector Ltd
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
//
|
|
|
|
import MatrixSDK
|
|
|
|
extension MXRoom {
|
|
|
|
func stopUncompletedVoiceBroadcastIfNeeded() {
|
|
// Detection of a potential uncompleted VoiceBroadcast
|
|
// Check whether a VoiceBroadcast is in progress on the current session for this room whereas no VoiceBroadcast Service is available.
|
|
self.lastVoiceBroadcastStateEvent { event in
|
|
guard let event = event,
|
|
event.stateKey == self.mxSession.myUserId,
|
|
let eventDeviceId = event.content[VoiceBroadcastSettings.voiceBroadcastContentKeyDeviceId] as? String,
|
|
eventDeviceId == self.mxSession.myDeviceId,
|
|
let voiceBroadcastInfo = VoiceBroadcastInfo(fromJSON: event.content),
|
|
voiceBroadcastInfo.state != VoiceBroadcastInfoState.stopped.rawValue,
|
|
self.mxSession.voiceBroadcastService == nil else {
|
|
return
|
|
}
|
|
|
|
self.mxSession.getOrCreateVoiceBroadcastService(for: self) { service in
|
|
guard let service = service else {
|
|
return
|
|
}
|
|
|
|
service.stopVoiceBroadcast(lastChunkSequence: 0,
|
|
voiceBroadcastId: voiceBroadcastInfo.voiceBroadcastId ?? event.eventId) { response in
|
|
MXLog.debug("[MXRoom] stopUncompletedVoiceBroadcastIfNeeded stopVoiceBroadcast with response : \(response)")
|
|
self.mxSession.tearDownVoiceBroadcastService()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
func lastVoiceBroadcastStateEvent(completion: @escaping (MXEvent?) -> Void) {
|
|
self.state { roomState in
|
|
completion(roomState?.stateEvents(with: .custom(VoiceBroadcastSettings.voiceBroadcastInfoContentKeyType))?.last)
|
|
}
|
|
}
|
|
}
|