Skip to content

Instantly share code, notes, and snippets.

@michaelloistl
Created September 21, 2018 13:06
Show Gist options
  • Save michaelloistl/af3fb1869771afb0a5e89c6a6ac674ef to your computer and use it in GitHub Desktop.
Save michaelloistl/af3fb1869771afb0a5e89c6a6ac674ef to your computer and use it in GitHub Desktop.
// 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