Before joining the channel, ensure that you prepared the development environment. See Integrate the SDK.

Implementation

You need to set the channel profile before the app joins a channel.

Set the channel profile as Live Broadcast

After initializing AgoraRtcEngine, call the setChannelProfile method to set the channel profile. AgoraRtcEngine applies optimization according to the channel profile.

In the setChannelProfile method, set the channel profile as Live Broadcast. This profile applies to an interactive broadcast scenario. Each channel includes two roles:

  • The host (broadcaster) sends and receives audio and video streams.
  • The audience receives audio and video streams.
  • Call the setChannelProfile method before joining a channel.
  • One engine uses one profile only. If you want to switch to another profile, destroy the current engine using the destroy method and create a new engine before calling the setChannelProfile method to set the new channel profile.
//Objective-C
- (void)setChannelProfile() {
  [self.agoraKit setChannelProfile:AgoraChannelProfileLiveBroadcasting]
}
//Swift
func setChannelProfile() {
  agoraKit.setChannelProfile(.liveBroadcasting)
}

Join a live broadcast channel

Call the joinChannelByToken method to join a channel.

In the joinChannelByToken method:

  • Pass a token that identifies the role and privilege of the user.
    • For the testing environment, we recommend usign a Temp Token generated on Dashboard. See Get a Temp Token.
    • For the production environment, we recommend using a Token generated at your server. For how to generate a token, see Token Security.
  • Pass a channel ID that identifies the channel. Users with the same channel ID enter into the same channel.
  • Pass a uid that identifies the user. Each user in a channel requires a unique uid. If you want to join the same channel on different devices, ensure that different uids are used for each device.

Once in a call, a user must call the leaveChannel method to exit the current call before entering another channel.

//Objective-C
- (void)joinChannel {
  [self.agoraKit joinChannelByToken:"token" channelId:@"demoChannel1" info:nil uid:0 joinSuccess:^(NSString *channel, NSUInteger uid, NSInteger elapsed) {
    // Join channel "demoChannel1"
  }];
}
//Swift
func joinChannel() {
  agoraKit.joinChannel(by Token: "token", channelId: "demoChannel1", info:nil, uid:0){[weak self] (sid, uid, elapsed) -> Void in
      // Join channel "demoChannel1"
  }
}

Next Steps

You are in the channel and can start a live broadcast with the following steps:

For more functions, you can refer to the following sections: