@@ -51,12 +51,17 @@ class VideoChatViewController: NSViewController {
5151 localVideo. layer? . backgroundColor = NSColor . clear. cgColor
5252 }
5353
54+ /// Create the agora instance.
5455 func initializeAgoraEngine( ) {
5556 AgoraKit = AgoraRtcEngineKit . sharedEngine ( withAppId: AppID, delegate: self )
5657 }
5758
5859 func setupVideo( ) {
5960 AgoraKit . enableVideo ( ) // Default mode is disableVideo
61+
62+ // Set video configuration
63+ // Please go to this page for detailed explanation
64+ // https://docs.agora.io/en/Video/video_profile_apple?platform=macOS
6065 let configuration = AgoraVideoEncoderConfiguration ( size: AgoraVideoDimension960x720,
6166 frameRate: . fps15,
6267 bitrate: AgoraVideoBitrateStandard,
@@ -65,6 +70,13 @@ class VideoChatViewController: NSViewController {
6570 }
6671
6772 func setupLocalVideo( ) {
73+ // This is used to set a local preview.
74+ // The steps setting local and remote view are very similar.
75+ // But note that if the local user do not have a uid or do
76+ // not care what the uid is, he can set his uid as ZERO.
77+ // Our server will assign one and return the uid via the block
78+ // callback (joinSuccessBlock) after
79+ // joining the channel successfully.
6880 let videoCanvas = AgoraRtcVideoCanvas ( )
6981 videoCanvas. uid = 0
7082 videoCanvas. view = localVideo
@@ -73,6 +85,10 @@ class VideoChatViewController: NSViewController {
7385 }
7486
7587 func joinChannel( ) {
88+ // 1. Users can only see each other after they join the
89+ // same channel successfully using the same app id.
90+ // 2. One token is only valid for the channel name that
91+ // you use to generate this token.
7692 AgoraKit . joinChannel ( byToken: Token, channelId: " demoChannel1 " , info: nil , uid: 0 ) { ( sid, uid, elapsed) -> Void in
7793 // did join channel "demoChannel1"
7894 }
@@ -83,6 +99,7 @@ class VideoChatViewController: NSViewController {
8399 }
84100
85101 func leaveChannel( ) {
102+ // leave channel and end chat
86103 AgoraKit . leaveChannel ( nil )
87104 AgoraKit . setupLocalVideo ( nil )
88105 remoteVideo. removeFromSuperview ( )
@@ -129,6 +146,7 @@ class VideoChatViewController: NSViewController {
129146
130147 @IBAction func didClickMuteButton( _ sender: NSButton ) {
131148 muteAudio = !muteAudio
149+ // mute local audio
132150 AgoraKit . muteLocalAudioStream ( muteAudio)
133151
134152 if ( muteAudio) {
@@ -140,6 +158,7 @@ class VideoChatViewController: NSViewController {
140158
141159 @IBAction func didClickVideoMuteButton( _ sender: NSButton ) {
142160 muteVideo = !muteVideo
161+ // mute local video
143162 AgoraKit . muteLocalVideoStream ( muteVideo)
144163
145164 if ( muteVideo) {
@@ -171,17 +190,26 @@ class VideoChatViewController: NSViewController {
171190 screenShare = !screenShare
172191 if ( screenShare) {
173192 sender. image = NSImage ( named: " screenShareButtonSelected " )
193+ // Start the screen capture with default parameters
174194 AgoraKit . startScreenCapture ( byDisplayId: UInt ( CGMainDisplayID ( ) ) ,
175195 rectangle: CGRect . zero,
176196 parameters: AgoraScreenCaptureParameters ( ) )
177197 } else {
178198 sender. image = NSImage ( named: " screenShareButton " )
199+ // Stop the screen capture
179200 AgoraKit . stopScreenCapture ( )
180201 }
181202 }
182203}
183204
184205extension VideoChatViewController : AgoraRtcEngineDelegate {
206+
207+ /// Callback to handle the event when the first frame of a remote video stream is decoded on the device.
208+ /// - Parameters:
209+ /// - engine: RTC engine instance
210+ /// - uid: user id
211+ /// - size: the height and width of the video frame
212+ /// - elapsed: Time elapsed (ms) from the local user calling JoinChannel method until the SDK triggers this callback.
185213 func rtcEngine( _ engine: AgoraRtcEngineKit , firstRemoteVideoDecodedOfUid uid: UInt , size: CGSize , elapsed: Int ) {
186214 if ( remoteVideo. isHidden) {
187215 remoteVideo. isHidden = false
@@ -193,10 +221,20 @@ extension VideoChatViewController: AgoraRtcEngineDelegate {
193221 AgoraKit . setupRemoteVideo ( videoCanvas)
194222 }
195223
224+ /// Occurs when a remote user (Communication)/host (Live Broadcast) leaves a channel.
225+ /// - Parameters:
226+ /// - engine: RTC engine instance
227+ /// - uid: ID of the user or host who leaves a channel or goes offline.
228+ /// - reason: Reason why the user goes offline
196229 func rtcEngine( _ engine: AgoraRtcEngineKit , didOfflineOfUid uid: UInt , reason: AgoraUserOfflineReason ) {
197230 self . remoteVideo. isHidden = true
198231 }
199232
233+ /// Occurs when a remote user’s video stream playback pauses/resumes.
234+ /// - Parameters:
235+ /// - engine: RTC engine instance
236+ /// - muted: YES for paused, NO for resumed.
237+ /// - byUid: User ID of the remote user.
200238 func rtcEngine( _ engine: AgoraRtcEngineKit , didVideoMuted muted: Bool , byUid: UInt ) {
201239 remoteVideo. isHidden = muted
202240 remoteVideoMutedIndicator. isHidden = !muted
0 commit comments