twilio / video-quickstart-ios

Twilio Video Quickstart for iOS
https://www.twilio.com/docs/api/video
MIT License
457 stars 177 forks source link

App will Terminate brodcast still running #641

Closed ArifJezir closed 2 years ago

ArifJezir commented 2 years ago

If I force close my app, the broadcast still running and streaming my room. How to kill my broadcast extension. I am using ReplayKit Example App.

timrozum commented 2 years ago

Hi @ArifJezir this is an interesting situation. Does your main app have a participant connected to the video room? If so the video room will detect that the main app participant has disconnected 30 seconds after the app is force quit. The broadcast extension could listen for remote participant disconnect events on the video room. When the main app participant disconnects the broadcast extension could detect it and handle the case. Does that make sense?

ArifJezir commented 2 years ago

Hi @timrozum
I send the different tokens to the broadcast extension. if I leave room in my app, the extension still running and the room is not disconnected after 30 secs. I found the solution. if I leave room in my app, the extension class "SampleHandler" room delegate function - participantDidDisconnect called. so if my current identifier is disconnected, I will disconnect room and screen sharing.

 func participantDidDisconnect(room: Room, participant: RemoteParticipant) {
    if let testUserId = userDefaults?.object(forKey: "userId") as? Int {
        if testUserId.description  == participant.identity.components(separatedBy: "<>")[2] {
            self.room?.disconnect()
            self.audioTrack = nil
            self.videoSource = nil
            self.screenTrack = nil
            let userInfo = [NSLocalizedFailureReasonErrorKey: "You have Stopped Screen Sharing"]
            finishBroadcastWithError(NSError(domain: "ScreenShare", code: -1, userInfo: userInfo))
        }
    }

}