twilio / video-quickstart-ios

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

Reuse exisiting room and refresh containerview with remoteparticipants #490

Closed jayeshkv closed 4 years ago

jayeshkv commented 4 years ago

I have followed this version of Multiparty example

https://github.com/twilio/video-quickstart-ios/tree/9fffebbef4f2d3cb2a5cf78bcb76949939c810f8/MultiPartyExample

Description

I have integrated the Multiparty example in our application, The room name gets passed in dynamically via the token as well as in the code to connect to the room.

I have created static class variables that would help keep the room connection open even if the party tries to switch between view controllers and made sure deinit doesn't get called when you have the connection open (I am trying to keep the video feed open so that the party would be able to go back and check any specific info).


class videoutil {
    static var room: Room?
    static var camera: CameraSource?
    static var localVideoTrack: LocalVideoTrack?
    static var localAudioTrack: LocalAudioTrack?
}

I am trying to reuse the existing remoteparticipants present in the videoutil.room and add those remoteparticipants to the containerView instead of connecting to the same room again with a token and updating the containerView

I have tried to check if the room has participants via

videoutil.remoteParticipantViews.isEmpty (returned false)
videoutil.room?.remoteParticipants (looped through this to make sure the identity matches the other person)

How would i refresh the view to use the existing connection instead of calling

TwilioVideoSDK.connect

If I directly call the delegate method roomDidConnect(videoutil.room) in viewdidload() It isn't setting up the remoteparticipant views and the remoteparticipant shows up as blank

paynerc commented 4 years ago

@jayeshkv,

First, I want to make sure I understand your setup correctly. You are using the MultiPartyExampleApp as a basis for adding TwilioVideo into your application and as such:

  1. You have brought the MultiPartyViewController.swift file into your application and have added a way to bring it up in your application.
  2. You have attracted the TwilioVideo specific objects from MultiPartyViewController.swift and created a model object, videoutil to contain them so they don't go out of scope when you navigate away from the MultiPartyViewController view controller.
  3. You have updated the logic in MultiPartyViewController.swift to access the objects in videoutil.

Does that sound right so far? I am assuming the idea here is that users join a multiparty call.. Then if they want to go back to the general idea of your application, but staying in the room, they would leave the MultiPartyViewController and navigate around your app. Being that the model object is still alive, things should still exist. The problem then is when you want to display MultiPartyViewController again, nothing is wired up and working. Does that sound about right?

I think the idea of having a model object that encapsulates the TwilioVideo logic is a sound idea. Things to keep in mind, however, are when setting delegates to the Twilio objects. For instance, when calling TwilioVideoSDK.connect, you provide the room delegate. We maintain a weak reference to that object to avoid a retain cycle. If you then destroy the MultiPartyViewController, the delegate on the Room object will no longer exist, and you will not receive call backs.

I think if I were going with this approach, I would make VideoUtil a fully featured model object that implements all of the delegate callbacks you will need to receive in your application. I would imagine that that object would have it's own delegate object (the view controller displaying the video UI) and when that delegate is set and the UI exists, modifications to the UI would be propagated thought. As far as how to get a new view controller displayed with the contents of the current state of the UI, you would need to inspect the objects in your VideoUtil class and rebuild the UI with the current state. The MultiPartyViewController is a good start, but it is not currently designed to operate as you are trying. The idea behind that view controller is that it is alive for the duration of the video communication. When the video communication is complete, it cleans up and goes away.

I think that may be the intent of your question. If I am completely off base, please let me know.

Ryan

jayeshkv commented 4 years ago

Hi @paynerc

Whatever you explained is how the current application works and is what I am trying to achieve. Thanks for the clarification.

paynerc commented 4 years ago

Does the explanation I provided unblock you so you can continue development?

I am going to close this issue but feel free to reopen it or create a new issue if you run into any further issues.

Ryan

jayeshkv commented 4 years ago

Hi @paynerc

whatever you mentioned makes sense, thanks.