AgoraIO / Advanced-Video

MIT License
261 stars 336 forks source link

Not able to stream via newly created channel in .liveBroadcasting #226

Closed iosfitness closed 3 years ago

iosfitness commented 4 years ago

Describe the bug A clear and concise description of what the bug is.

To Reproduce Steps to reproduce the behavior:

  1. Start the App with a broadcaster role
  2. Create a new via createRtcChannel and then join rtcChannel.join(byToken: nil, info: nil, uid: 0, options: options)
  3. Now in second device, login via audience role. The remote video never loads

Below is the code snippet :


func setUpVideo() {
        getAgoraEngine().enableVideo()
        getAgoraEngine().enableAudio()

        getAgoraEngine().setChannelProfile(.liveBroadcasting)

        //Warning: only enable dual stream mode if there will be more than one broadcaster in the channel
        //getAgoraEngine().enableDualStreamMode(true)

        if isBroadcaster{

            let videoCanvas = AgoraRtcVideoCanvas()
            videoCanvas.uid = userID
            videoCanvas.view = localVideoView
            videoCanvas.renderMode = .fit

            getAgoraEngine().startPreview()
            getAgoraEngine().muteLocalAudioStream(false)
            getAgoraEngine().muteLocalVideoStream(false)

            getAgoraEngine().setClientRole(.broadcaster)
            getAgoraEngine().setupLocalVideo(videoCanvas)

        }
        else{
            getAgoraEngine().setClientRole(.audience)
            getAgoraEngine().muteLocalAudioStream(true)
            getAgoraEngine().muteLocalVideoStream(true)

        }

        //Configuration
        getAgoraEngine().setVideoEncoderConfiguration(
                             AgoraVideoEncoderConfiguration(
                                size: AgoraVideoDimension640x480,
                                     frameRate: .fps30,
                                     bitrate: AgoraVideoBitrateStandard,
                                     orientationMode: .adaptative
                             )
                     )

    }

    func joinChannel() {

                let options = AgoraRtcChannelMediaOptions()
                        options.autoSubscribeAudio = true
                        options.autoSubscribeVideo = true
                        if (rtcChannel != nil) {
                                rtcChannel.destroy()
                        }
                        rtcChannel = getAgoraEngine().createRtcChannel("Test123213")
                        rtcChannel.setRtcChannelDelegate(self)
                rtcChannel.publish()
                        let success = rtcChannel.join(byToken: nil, info: nil, uid: 0, options: options)

                print(success)

            //APPROACH FROM https://docs.agora.io/en/Interactive%20Broadcast/start_live_ios?platform=iOS
        /*if let name = userName {
            let channelCode =   getAgoraEngine().joinChannel(byUserAccount: name, token: tempToken, channelId: channelName) { [weak self] (sid, uid, elapsed) in
                //TODO: Hardik : Call API HERE for join
                self?.userID = uid
            }
            print("RTC---",channelCode)
        } else {
            let channelCode =   getAgoraEngine().joinChannel(byToken: tempToken, channelId:channelName, info: nil, uid: userID) { [weak self] (sid, uid, elapsed) in
                //TODO: Hardik : Call API HERE for join
                self?.userID = uid

            }
            print("RTC---",channelCode)
        }*/

    }
extension AgoraVideoViewController: AgoraRtcChannelDelegate {
    func rtcChannelDidJoin(_ rtcChannel: AgoraRtcChannel, withUid uid: UInt, elapsed: Int) {

            if !isBroadcaster{
                let videoCanvas = AgoraRtcVideoCanvas()
                videoCanvas.uid = uid
                videoCanvas.view = localVideoView
                videoCanvas.renderMode = .fit
                getAgoraEngine().setupRemoteVideo(videoCanvas)
            }
    }

    func rtcChannel(_ rtcChannel: AgoraRtcChannel, didJoinedOfUid uid: UInt, elapsed: Int) {

    }

    func rtcChannel(_ rtcChannel: AgoraRtcChannel, didOfflineOfUid uid: UInt, reason: AgoraUserOfflineReason) {

    }

    func rtcChannelDidLeave(_ rtcChannel: AgoraRtcChannel, with stats: AgoraChannelStats) {

    }

    func rtcChannel(_ rtcChannel: AgoraRtcChannel, didOccurWarning warningCode: AgoraWarningCode) {

    }

    func rtcChannel(_ rtcChannel: AgoraRtcChannel, didOccurError errorCode: AgoraErrorCode) {

    }

}

The callback comes to rtcChannelDidJoin but the audience role is not able to see remote video. However, both roles are able to join the channel. **createRtcChannel** returns  **0: Success**  for both roles

**Expected behavior**
The remote video should load in audience's role.

**Smartphone (please complete the following information):**
 - OS: iOS

Any input will be appreciated. Thanks in advance
plutoless commented 3 years ago

if you use createChannel, you will need to call channel.publish() to stream out video for broadcaster.

iosfitness commented 3 years ago

@plutoless Thanks for the response. However, if you see the implementation inside func joinChannel(), I am already calling rtcChannel.publish()

I do receive a callback in rtcChannelDidJoin but it fails to load remote video from host.

Any additional settings I need to have for rtcChannel

plutoless commented 3 years ago

try calling setClientRole on channel object to make yourself a broadcaster in this channel.

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.