How to sent streaming data to UIView

by da1lbi3   Last Updated July 12, 2019 14:26 PM - source

I have two classes, WebRTCParent what handles all the video stuff. And parentUnitViewController that gets the final result.

class WebRTCParent: NSObject {}

class ParentUnitViewController: UIViewController {
    @IBOutlet weak var remoteView: UIView!
    let webRTCParent = WebRTCParent()

When a video is received from the other party, this function is called:

func peerConnection(_ peerConnection: RTCPeerConnection, didAdd stream: RTCMediaStream) {
        print("peerConnection did add stream")

        if (stream.audioTracks.count > 1) {
            print("Weird-looking stream: " + stream.description)

        let audioSession = AVAudioSession.sharedInstance()

        do {

            try audioSession.overrideOutputAudioPort(AVAudioSession.PortOverride.speaker)
        } catch let error as NSError {
            print("audioSession error: \(error.localizedDescription)")

        if (stream.videoTracks.count == 1) {
            print("media stream ontvangen met video")

            self.remoteVideoTrack = stream.videoTracks[0]
            self.remoteVideoTrack?.isEnabled = true

            self.delegate?.webRTCParent(self, remoteVideo: self.remoteVideoTrack!)



So far so good, but how do I add the RTCMediaStream to the view? I have tried it with the delegate, but it seems to close the stream within a few seconds.

Is it possible with a delegate? Or how should I do this?

Tags : swift webrtc

Related Questions

GoogleWebRTC Audio Video Calling iOS

Updated August 02, 2019 10:26 AM

iOS WebRTC Handle Packet Loss

Updated August 06, 2017 05:26 AM

How can I use an .a static library in swift?

Updated May 05, 2019 21:26 PM

iOS WebRTC P2P Connection with ICE Server

Updated June 29, 2017 11:26 AM

Open iOS app from background

Updated October 06, 2016 08:11 AM