Kotlin

Provide Containers for Video Views

The Vonage SDK returns View objects for publisher and subscriber. The sample hosts them in FrameLayout containers created from Compose via AndroidView:

Pass the containers to your activity so it can add publisher and subscriber views when the session connects:

Attach the View When Ready

In onConnected, publish and attach the publisher view:

override fun onConnected(session: Session) {
    if (publisher == null) {
        publisher = Publisher.Builder(applicationContext).build()
        session.publish(publisher)
        publisherViewContainer.addView(publisher?.view)
        if (publisher?.view is GLSurfaceView) {
            (publisher?.view as GLSurfaceView).setZOrderOnTop(true)
        }
    }
}

Subscribe when a remote stream arrives: