Created
September 21, 2018 13:06
-
-
Save michaelloistl/af3fb1869771afb0a5e89c6a6ac674ef to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Shared to setup engine: | |
func setupRtcEngine(from clientRole: AgoraClientRole) { | |
rtcEngine.setChannelProfile(.liveBroadcasting) | |
rtcEngine.setClientRole(clientRole) | |
rtcEngine.enableVideo() | |
let config = AgoraVideoEncoderConfiguration(size: AgoraVideoDimension640x360, frameRate: .fps15, bitrate: 400, orientationMode: .fixedPortrait) | |
rtcEngine.setVideoEncoderConfiguration(config) | |
rtcEngine.setLogFilter(4) | |
guard let path = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first else { return } | |
rtcEngine.setLogFile(path + "/agorasdk.log") | |
} | |
// Broadcast - AgoraRtcEngineDelegate | |
func rtcEngine(_ engine: AgoraRtcEngineKit, didJoinChannel channel: String, withUid uid: UInt, elapsed: Int) { | |
if let liveStream = liveStream { | |
let result = rtcEngine.createDataStream(&dataStreamId, reliable: true, ordered: true) | |
setupCommentsViewController(with: liveStream.id) | |
updateSyncedAt() | |
} | |
startTimer() | |
isStreaming = true | |
} | |
// Audience - AgoraRtcEngineDelegate | |
func rtcEngine(_ engine: AgoraRtcEngineKit, didJoinChannel channel: String, withUid uid: UInt, elapsed: Int) { | |
guard let liveStream = liveStream else { return } | |
guard let userId = Int(liveStream.userId) else { return } | |
rtcEngine.setEnableSpeakerphone(true) | |
setupRemoteVideo(from: UInt(userId)) | |
let result = rtcEngine.createDataStream(&dataStreamId, reliable: true, ordered: true) | |
commentsVC.liveStreamId = liveStream.id | |
commentsVC.view.isHidden = false | |
commentsVC.messageInputBar.isHidden = false | |
viewersButton.isHidden = false | |
App.sendEvent("live_stream_watch_started") | |
startWatchTime = Date() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment