Skip to content

Commit d02f373

Browse files
committed
NEW: joinChannel2 api for mac
1 parent 81956da commit d02f373

14 files changed

Lines changed: 209 additions & 106 deletions

File tree

macOS/APIExample/Examples/Advanced/AudioMixing/AudioMixing.swift

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -383,13 +383,8 @@ class AudioMixing: BaseViewController {
383383
// when joining channel. The channel name and uid used to calculate
384384
// the token has to match the ones used for channel join
385385
isProcessing = true
386-
let result = agoraKit.joinChannel(byToken: KeyCenter.Token, channelId: channelField.stringValue, info: nil, uid: 0) {
387-
[unowned self] (channel, uid, elapsed) -> Void in
388-
self.isProcessing = false
389-
self.isJoined = true
390-
self.videos[0].uid = uid
391-
LogUtils.log(message: "Join \(channel) with uid \(uid) elapsed \(elapsed)ms", level: .info)
392-
}
386+
let option = AgoraRtcChannelMediaOptions()
387+
let result = agoraKit.joinChannel(byToken: KeyCenter.Token, channelId: channel, info: nil, uid: 0, options: option)
393388
if result != 0 {
394389
isProcessing = false
395390
// Usually happens with invalid parameters
@@ -533,6 +528,18 @@ extension AudioMixing: AgoraRtcEngineDelegate {
533528
self.showAlert(title: "Error", message: "Error \(errorCode.rawValue) occur")
534529
}
535530

531+
/// callback when the local user joins a specified channel.
532+
/// @param channel
533+
/// @param uid uid of local user
534+
/// @param elapsed time elapse since current sdk instance join the channel in ms
535+
func rtcEngine(_ engine: AgoraRtcEngineKit, didJoinChannel channel: String, withUid uid: UInt, elapsed: Int) {
536+
isProcessing = false
537+
isJoined = true
538+
let localVideo = videos[0]
539+
localVideo.uid = uid
540+
LogUtils.log(message: "Join \(channel) with uid \(uid) elapsed \(elapsed)ms", level: .info)
541+
}
542+
536543
/// callback when a remote user is joinning the channel, note audience in live broadcast mode will NOT trigger this event
537544
/// @param uid uid of remote joined user
538545
/// @param elapsed time elapse since current sdk instance join the channel in ms

macOS/APIExample/Examples/Advanced/ChannelMediaRelay/ChannelMediaRelay.swift

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -158,13 +158,8 @@ class ChannelMediaRelay: BaseViewController {
158158
// when joining channel. The channel name and uid used to calculate
159159
// the token has to match the ones used for channel join
160160
isProcessing = true
161-
let result = agoraKit.joinChannel(byToken: KeyCenter.Token, channelId: channelField.stringValue, info: nil, uid: 0) {
162-
[unowned self] (channel, uid, elapsed) -> Void in
163-
self.isProcessing = false
164-
self.isJoined = true
165-
localVideo.uid = uid
166-
LogUtils.log(message: "Join \(channel) with uid \(uid) elapsed \(elapsed)ms", level: .info)
167-
}
161+
let option = AgoraRtcChannelMediaOptions()
162+
let result = agoraKit.joinChannel(byToken: KeyCenter.Token, channelId: channel, info: nil, uid: 0, options: option)
168163
if result != 0 {
169164
isProcessing = false
170165
// Usually happens with invalid parameters
@@ -230,6 +225,18 @@ extension ChannelMediaRelay: AgoraRtcEngineDelegate {
230225
self.showAlert(title: "Error", message: "Error \(errorCode.rawValue) occur")
231226
}
232227

228+
/// callback when the local user joins a specified channel.
229+
/// @param channel
230+
/// @param uid uid of local user
231+
/// @param elapsed time elapse since current sdk instance join the channel in ms
232+
func rtcEngine(_ engine: AgoraRtcEngineKit, didJoinChannel channel: String, withUid uid: UInt, elapsed: Int) {
233+
isProcessing = false
234+
isJoined = true
235+
let localVideo = videos[0]
236+
localVideo.uid = uid
237+
LogUtils.log(message: "Join \(channel) with uid \(uid) elapsed \(elapsed)ms", level: .info)
238+
}
239+
233240
/// callback when a remote user is joinning the channel, note audience in live broadcast mode will NOT trigger this event
234241
/// @param uid uid of remote joined user
235242
/// @param elapsed time elapse since current sdk instance join the channel in ms

macOS/APIExample/Examples/Advanced/CustomAudioRender/CustomAudioRender.swift

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -173,14 +173,8 @@ class CustomAudioRender: BaseViewController {
173173
// when joining channel. The channel name and uid used to calculate
174174
// the token has to match the ones used for channel join
175175
isProcessing = true
176-
let result = agoraKit.joinChannel(byToken: KeyCenter.Token, channelId: channel, info: nil, uid: 0) {
177-
[unowned self] (channel, uid, elapsed) -> Void in
178-
self.isProcessing = false
179-
self.isJoined = true
180-
self.videos[0].uid = uid
181-
LogUtils.log(message: "Join \(channel) with uid \(uid) elapsed \(elapsed)ms", level: .info)
182-
self.exAudio.startWork()
183-
}
176+
let option = AgoraRtcChannelMediaOptions()
177+
let result = agoraKit.joinChannel(byToken: KeyCenter.Token, channelId: channel, info: nil, uid: 0, options: option)
184178
if result != 0 {
185179
self.isProcessing = false
186180
// Usually happens with invalid parameters
@@ -243,6 +237,19 @@ extension CustomAudioRender: AgoraRtcEngineDelegate {
243237
self.showAlert(title: "Error", message: "Error \(errorCode.rawValue) occur")
244238
}
245239

240+
/// callback when the local user joins a specified channel.
241+
/// @param channel
242+
/// @param uid uid of local user
243+
/// @param elapsed time elapse since current sdk instance join the channel in ms
244+
func rtcEngine(_ engine: AgoraRtcEngineKit, didJoinChannel channel: String, withUid uid: UInt, elapsed: Int) {
245+
isProcessing = false
246+
isJoined = true
247+
let localVideo = videos[0]
248+
localVideo.uid = uid
249+
LogUtils.log(message: "Join \(channel) with uid \(uid) elapsed \(elapsed)ms", level: .info)
250+
exAudio.startWork()
251+
}
252+
246253
/// callback when a remote user is joinning the channel, note audience in live broadcast mode will NOT trigger this event
247254
/// @param uid uid of remote joined user
248255
/// @param elapsed time elapse since current sdk instance join the channel in ms

macOS/APIExample/Examples/Advanced/CustomAudioSource/CustomAudioSource.swift

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -170,14 +170,8 @@ class CustomAudioSource: BaseViewController {
170170
// when joining channel. The channel name and uid used to calculate
171171
// the token has to match the ones used for channel join
172172
isProcessing = true
173-
let result = agoraKit.joinChannel(byToken: KeyCenter.Token, channelId: channel, info: nil, uid: 0) {
174-
[unowned self] (channel, uid, elapsed) -> Void in
175-
self.isProcessing = false
176-
self.isJoined = true
177-
self.videos[0].uid = uid
178-
LogUtils.log(message: "Join \(channel) with uid \(uid) elapsed \(elapsed)ms", level: .info)
179-
self.exAudio.startWork()
180-
}
173+
let option = AgoraRtcChannelMediaOptions()
174+
let result = agoraKit.joinChannel(byToken: KeyCenter.Token, channelId: channel, info: nil, uid: 0, options: option)
181175
if result != 0 {
182176
self.isProcessing = false
183177
// Usually happens with invalid parameters
@@ -240,6 +234,19 @@ extension CustomAudioSource: AgoraRtcEngineDelegate {
240234
self.showAlert(title: "Error", message: "Error \(errorCode.rawValue) occur")
241235
}
242236

237+
/// callback when the local user joins a specified channel.
238+
/// @param channel
239+
/// @param uid uid of local user
240+
/// @param elapsed time elapse since current sdk instance join the channel in ms
241+
func rtcEngine(_ engine: AgoraRtcEngineKit, didJoinChannel channel: String, withUid uid: UInt, elapsed: Int) {
242+
isProcessing = false
243+
isJoined = true
244+
let localVideo = videos[0]
245+
localVideo.uid = uid
246+
LogUtils.log(message: "Join \(channel) with uid \(uid) elapsed \(elapsed)ms", level: .info)
247+
exAudio.startWork()
248+
}
249+
243250
/// callback when a remote user is joinning the channel, note audience in live broadcast mode will NOT trigger this event
244251
/// @param uid uid of remote joined user
245252
/// @param elapsed time elapse since current sdk instance join the channel in ms

macOS/APIExample/Examples/Advanced/CustomVideoRender/CustomVideoRender.swift

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -214,13 +214,8 @@ class CustomVideoRender: BaseViewController {
214214
// when joining channel. The channel name and uid used to calculate
215215
// the token has to match the ones used for channel join
216216
isProcessing = true
217-
let result = agoraKit.joinChannel(byToken: KeyCenter.Token, channelId: channelField.stringValue, info: nil, uid: 0) {
218-
[unowned self] (channel, uid, elapsed) -> Void in
219-
self.isProcessing = false
220-
self.isJoined = true
221-
self.videos[0].uid = uid
222-
LogUtils.log(message: "Join \(channel) with uid \(uid) elapsed \(elapsed)ms", level: .info)
223-
}
217+
let option = AgoraRtcChannelMediaOptions()
218+
let result = agoraKit.joinChannel(byToken: KeyCenter.Token, channelId: channel, info: nil, uid: 0, options: option)
224219
if result != 0 {
225220
isProcessing = false
226221
// Usually happens with invalid parameters
@@ -282,6 +277,18 @@ extension CustomVideoRender: AgoraRtcEngineDelegate {
282277
self.showAlert(title: "Error", message: "Error \(errorCode.rawValue) occur")
283278
}
284279

280+
/// callback when the local user joins a specified channel.
281+
/// @param channel
282+
/// @param uid uid of local user
283+
/// @param elapsed time elapse since current sdk instance join the channel in ms
284+
func rtcEngine(_ engine: AgoraRtcEngineKit, didJoinChannel channel: String, withUid uid: UInt, elapsed: Int) {
285+
isProcessing = false
286+
isJoined = true
287+
let localVideo = videos[0]
288+
localVideo.uid = uid
289+
LogUtils.log(message: "Join \(channel) with uid \(uid) elapsed \(elapsed)ms", level: .info)
290+
}
291+
285292
/// callback when a remote user is joinning the channel, note audience in live broadcast mode will NOT trigger this event
286293
/// @param uid uid of remote joined user
287294
/// @param elapsed time elapse since current sdk instance join the channel in ms

macOS/APIExample/Examples/Advanced/CustomVideoSourceMediaIO/CustomVideoSourceMediaIO.swift

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -216,13 +216,8 @@ class CustomVideoSourceMediaIO: BaseViewController {
216216
// when joining channel. The channel name and uid used to calculate
217217
// the token has to match the ones used for channel join
218218
isProcessing = true
219-
let result = agoraKit.joinChannel(byToken: KeyCenter.Token, channelId: channelField.stringValue, info: nil, uid: 0) {
220-
[unowned self] (channel, uid, elapsed) -> Void in
221-
self.isProcessing = false
222-
self.isJoined = true
223-
localVideo.uid = uid
224-
LogUtils.log(message: "Join \(channel) with uid \(uid) elapsed \(elapsed)ms", level: .info)
225-
}
219+
let option = AgoraRtcChannelMediaOptions()
220+
let result = agoraKit.joinChannel(byToken: KeyCenter.Token, channelId: channel, info: nil, uid: 0, options: option)
226221
if result != 0 {
227222
isProcessing = false
228223
// Usually happens with invalid parameters
@@ -283,9 +278,24 @@ extension CustomVideoSourceMediaIO: AgoraRtcEngineDelegate {
283278
/// @param errorCode error code of the problem
284279
func rtcEngine(_ engine: AgoraRtcEngineKit, didOccurError errorCode: AgoraErrorCode) {
285280
LogUtils.log(message: "error: \(errorCode)", level: .error)
281+
if isProcessing {
282+
isProcessing = false
283+
}
286284
self.showAlert(title: "Error", message: "Error \(errorCode.rawValue) occur")
287285
}
288286

287+
/// callback when the local user joins a specified channel.
288+
/// @param channel
289+
/// @param uid uid of local user
290+
/// @param elapsed time elapse since current sdk instance join the channel in ms
291+
func rtcEngine(_ engine: AgoraRtcEngineKit, didJoinChannel channel: String, withUid uid: UInt, elapsed: Int) {
292+
isProcessing = false
293+
isJoined = true
294+
let localVideo = videos[0]
295+
localVideo.uid = uid
296+
LogUtils.log(message: "Join \(channel) with uid \(uid) elapsed \(elapsed)ms", level: .info)
297+
}
298+
289299
/// callback when a remote user is joinning the channel, note audience in live broadcast mode will NOT trigger this event
290300
/// @param uid uid of remote joined user
291301
/// @param elapsed time elapse since current sdk instance join the channel in ms

macOS/APIExample/Examples/Advanced/CustomVideoSourcePush/CustomVideoSourcePush.swift

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -218,12 +218,8 @@ class CustomVideoSourcePush: BaseViewController {
218218
// when joining channel. The channel name and uid used to calculate
219219
// the token has to match the ones used for channel join
220220
isProcessing = true
221-
let result = agoraKit.joinChannel(byToken: KeyCenter.Token, channelId: channelField.stringValue, info: nil, uid: 0) {
222-
[unowned self] (channel, uid, elapsed) -> Void in
223-
self.isProcessing = false
224-
self.isJoined = true
225-
LogUtils.log(message: "Join \(channel) with uid \(uid) elapsed \(elapsed)ms", level: .info)
226-
}
221+
let option = AgoraRtcChannelMediaOptions()
222+
let result = agoraKit.joinChannel(byToken: KeyCenter.Token, channelId: channel, info: nil, uid: 0, options: option)
227223
if result != 0 {
228224
isProcessing = false
229225
// Usually happens with invalid parameters
@@ -289,6 +285,16 @@ extension CustomVideoSourcePush: AgoraRtcEngineDelegate {
289285
self.showAlert(title: "Error", message: "Error \(errorCode.rawValue) occur")
290286
}
291287

288+
/// callback when the local user joins a specified channel.
289+
/// @param channel
290+
/// @param uid uid of local user
291+
/// @param elapsed time elapse since current sdk instance join the channel in ms
292+
func rtcEngine(_ engine: AgoraRtcEngineKit, didJoinChannel channel: String, withUid uid: UInt, elapsed: Int) {
293+
isProcessing = false
294+
isJoined = true
295+
LogUtils.log(message: "Join \(channel) with uid \(uid) elapsed \(elapsed)ms", level: .info)
296+
}
297+
292298
/// callback when a remote user is joinning the channel, note audience in live broadcast mode will NOT trigger this event
293299
/// @param uid uid of remote joined user
294300
/// @param elapsed time elapse since current sdk instance join the channel in ms

macOS/APIExample/Examples/Advanced/RTMPStreaming/RTMPStreaming.swift

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -187,20 +187,8 @@ class RTMPStreaming: BaseViewController {
187187
// when joining channel. The channel name and uid used to calculate
188188
// the token has to match the ones used for channel join
189189
isProcessing = true
190-
let result = agoraKit.joinChannel(byToken: KeyCenter.Token, channelId: channelField.stringValue, info: nil, uid: 0) {
191-
[unowned self] (channel, uid, elapsed) -> Void in
192-
self.isProcessing = false
193-
self.isJoined = true
194-
localVideo.uid = uid
195-
LogUtils.log(message: "Join \(channel) with uid \(uid) elapsed \(elapsed)ms", level: .info)
196-
197-
// add transcoding user so the video stream will be involved
198-
// in future RTMP Stream
199-
let user = AgoraLiveTranscodingUser()
200-
user.rect = CGRect(x: 0, y: 0, width: CANVAS_WIDTH / 2, height: CANVAS_HEIGHT)
201-
user.uid = uid
202-
self.transcoding.add(user)
203-
}
190+
let option = AgoraRtcChannelMediaOptions()
191+
let result = agoraKit.joinChannel(byToken: KeyCenter.Token, channelId: channel, info: nil, uid: 0, options: option)
204192
if result != 0 {
205193
isProcessing = false
206194
// Usually happens with invalid parameters
@@ -266,6 +254,25 @@ extension RTMPStreaming: AgoraRtcEngineDelegate {
266254
self.showAlert(title: "Error", message: "Error \(errorCode.rawValue) occur")
267255
}
268256

257+
/// callback when the local user joins a specified channel.
258+
/// @param channel
259+
/// @param uid uid of local user
260+
/// @param elapsed time elapse since current sdk instance join the channel in ms
261+
func rtcEngine(_ engine: AgoraRtcEngineKit, didJoinChannel channel: String, withUid uid: UInt, elapsed: Int) {
262+
isProcessing = false
263+
isJoined = true
264+
let localVideo = videos[0]
265+
localVideo.uid = uid
266+
LogUtils.log(message: "Join \(channel) with uid \(uid) elapsed \(elapsed)ms", level: .info)
267+
268+
// add transcoding user so the video stream will be involved
269+
// in future RTMP Stream
270+
let user = AgoraLiveTranscodingUser()
271+
user.rect = CGRect(x: 0, y: 0, width: CANVAS_WIDTH / 2, height: CANVAS_HEIGHT)
272+
user.uid = uid
273+
transcoding.add(user)
274+
}
275+
269276
/// callback when a remote user is joinning the channel, note audience in live broadcast mode will NOT trigger this event
270277
/// @param uid uid of remote joined user
271278
/// @param elapsed time elapse since current sdk instance join the channel in ms

macOS/APIExample/Examples/Advanced/RawMediaData/RawMediaData.swift

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -248,12 +248,8 @@ class RawMediaData: BaseViewController {
248248
// when joining channel. The channel name and uid used to calculate
249249
// the token has to match the ones used for channel join
250250
isProcessing = true
251-
let result = agoraKit.joinChannel(byToken: KeyCenter.Token, channelId: channelField.stringValue, info: nil, uid: 0) {[unowned self] (channel, uid, elapsed) -> Void in
252-
self.isProcessing = false
253-
self.isJoined = true
254-
localVideo.uid = uid
255-
LogUtils.log(message: "Join \(channel) with uid \(uid) elapsed \(elapsed)ms", level: .info)
256-
}
251+
let option = AgoraRtcChannelMediaOptions()
252+
let result = agoraKit.joinChannel(byToken: KeyCenter.Token, channelId: channel, info: nil, uid: 0, options: option)
257253
if result != 0 {
258254
isProcessing = false
259255
// Usually happens with invalid parameters
@@ -319,6 +315,18 @@ extension RawMediaData: AgoraRtcEngineDelegate {
319315
self.showAlert(title: "Error", message: "Error \(errorCode.rawValue) occur")
320316
}
321317

318+
/// callback when the local user joins a specified channel.
319+
/// @param channel
320+
/// @param uid uid of local user
321+
/// @param elapsed time elapse since current sdk instance join the channel in ms
322+
func rtcEngine(_ engine: AgoraRtcEngineKit, didJoinChannel channel: String, withUid uid: UInt, elapsed: Int) {
323+
isProcessing = false
324+
isJoined = true
325+
let localVideo = videos[0]
326+
localVideo.uid = uid
327+
LogUtils.log(message: "Join \(channel) with uid \(uid) elapsed \(elapsed)ms", level: .info)
328+
}
329+
322330
/// callback when a remote user is joinning the channel, note audience in live broadcast mode will NOT trigger this event
323331
/// @param uid uid of remote joined user
324332
/// @param elapsed time elapse since current sdk instance join the channel in ms

0 commit comments

Comments
 (0)