DEV Community

ZEGOCLOUDDev
ZEGOCLOUDDev

Posted on

Build a Live App in 10 Minutes with ZEGOCLOUD's ZEGOLive

ZEGOCLOUD

The live streaming market is booming

As an industry, live streaming is already worth billions of dollars and it’s only expected to grow.

According to various projections, including one by Grand View Research, the live streaming industry is expected to climb from $70 billion in 2021 to almost $224 billion in 2028. That’s a projected three-fold increase over seven years!

live streaming market

How to get involved in the live streaming market?

With the rapid development of the live streaming industry, many technology companies have been derived to serve the live streaming industry by providing mature technologies to help users quickly build their own live streaming apps.
Here I will introduce how to quickly build your own live streaming app by using ZEGOCLOUD's ZEGOLive SDK.

What features does ZEGOLive SDK provide?

Demo

The ZEGOLive SDK provides all features that required by a live streaming app, such as creating and join a live stream room, co-hosting, face beautification, audio effects, virtual gifting, sending bullet-screen messages, and more. And all these features can be tried out by simply experiencing and integrating ZEGOCLOUD's Demo App for Live Streaming.

The following table shows ZEGOLive SDK's features:

Feature Description
Real-time audio and video You can use to build smooth live streaming experiences with ultra-low latency.
Room list Room list shows the current ongoing live streaming. Users can enter the live room on the list to watch live streaming as wanted.
Create a live room You can create a live room and start your live stream after becoming the host of a room.
Log in to a live room Users need to log in to a live room first to play streams and join co-hosting.
Request to co-host Participants can request to take a co-host seat to be a co-host, and participants can speak and join the live streaming once the host accepts the request.
Make co-hosts The host can invite any participants in the room to co-host, and participants can decline or accept the invitation.
Manage co-host seats The host of a room can remove the co-hosts from the co-host seat, disable or enable the text chat for all participants, and more. 。
Real-time quality analysis
  • Before the live starts, automatically conduct the microphone, camera, and speaker tests.
  • During the live, the streaming quality data and network data are updated in real time.
  • After the live ends, ZEGOCLOUD provides you with the quality analysis platform Prism and quality report for you to review and check the streaming quality.
Instant messaging With the ZEGOCLOUD IM service, participants can send, receive real-time messages, get notified when new participants join the room or existing participants leave the room, and also can see the interactive notifications in the room.
Audio effects Support setting up the music accompaniments with genuine music, and provide rich audio effects, including reverb, voice changing, and more.
Face beautify Provide Face beautification feature to make you look more presentable: skin tone enhancement, skin smoothing, image sharping, cheek blusher, and more.

How to use ZEGOLive SDK

step 1. Create a ZEGOCLOUD account

create an account

step 2. Create a new project

creata a project

step 3. Understand the process

The following diagram shows the basic process of creating a live room and a participant (user B) playing a stream published by the host (user A).
live process

step 4. Integrate the ZEGOLive SDK

To integrate the SDK, do the following:

  1. Download the Sample codes, and copy the ZEGOLive folder to your project directory (create a new project if you don't have an existing project).
  2. Add the Podfile file to your project directory.

    pod 'ZIM'
    pod 'ZegoExpressEngine'
    

podfile

  1. Open Terminal, run the install command.

    pod install
    

step 5. Add permissions

Permissions can be set as needed.

  1. Open Xcode, select the target object, and then click Info > Custom iOS Target Properties.

permissions

  1. Click the Add button (+) to add camera and microphone permissions.
  • Privacy-Camera Usage Description

  • Privacy-Microphone Usage Description

Device Description

step 6. Initialize the ZEGOLive SDK

To initialize the ZEGOLive SDK, get the RoomManager instance, pass the AppID of your project.

// Initialize the SDK. We recommend you call this method when the application starts.
// YOUR_APP_ID is the AppID you get from ZEGOCLOUD Admin Console. 
RoomManager.shared.initWithAppID(appID: YOUR_APP_ID) { result in
    // Callback for the result of init. 

};
Enter fullscreen mode Exit fullscreen mode

To receive callbacks, set the corresponding delegate to self, or call the addUserServiceDelegate method to listen for and handle event callbacks as needed.

RoomManager.shared.roomService.delegate = self
RoomManager.shared.userService.addUserServiceDelegate(self)
RoomManager.shared.messageService.delegate = self
Enter fullscreen mode Exit fullscreen mode

step 7. Log in

To access the ZEGOLive service, you must log in first.

  • For business security, you will need to provide a token for the ZIM SDK to validate the login privilege. For details, see Authentication.
  • For debugging, you can refer to our Sample code to generate tokens on your app client.
let userInfo = UserInfo("YOUR_USER_ID", "YOUR_USER_NAME", .participant)
let token: String = "YOUR_TOKEN"
RoomManager.shared.userService.login(userInfo, token) { result in  
     // Callback for the login result. 

}
Enter fullscreen mode Exit fullscreen mode

step 8. Start the local video preview

Before creating a live room to start live streaming, you can call the playVideoStream method to start the local video preview.

// The [userID] can be used to specify which user's view you want to view. 
// To preview your own local video view, pass in your userID.
// streamView view is a view for the local video preview.
RoomManager.shared.deviceService.playVideoStream(userID, view: streamView)
Enter fullscreen mode Exit fullscreen mode

step 9. Create/Join a live room

  • You become a Host after creating a live room, and you can take a seat and start live streaming upon creating.
  • You become a Participants after joining a live room, and you can watch the live streaming and be a co-host to interact.
  • To prevent the participants from speaking directly without co-hosting, you will need to provide a Token for the RTC SDK to validate whether you have the privileges to create or join a room. For details, see Use Tokens for authentication.
  • This Token can be the same as the Token you provided for login.

To create a live room, call the createRoom method.

RoomManager.shared.roomService.createRoom("YOUR_ROOM_ID", "YOUR_ROOM_NAME", token) { result in
    // Callback for the result of create a live room. 

}
Enter fullscreen mode Exit fullscreen mode

After a live room is created, to start live streaming, the host will need to call the takeSeat method to speak. And the SDK automatically publishes the streams when the host takes a seat successfully.

RoomManager.shared.userService.takeSeat { result in
   // Callback for the result of take a seat. 

}
Enter fullscreen mode Exit fullscreen mode

To join a live room, call the joinRoom method.

RoomManager.shared.roomService.joinRoom("YOUR_ROOM_ID", token) { result in
   // Callback for the result of join a live room. 

}
Enter fullscreen mode Exit fullscreen mode

After joining a live room, for a participant to watch the live streaming, he will need to call the playVideoStream method to play the host's published streams.

// The [userID] can be used to specify which user's view you want to view. 
// You can get the userID of the host in room info. 
// streamView is the view to be displayed.
RoomManager.shared.deviceService.playVideoStream(userID, view: streamView)
Enter fullscreen mode Exit fullscreen mode

step 10. Send/Receive text messages

To send text messages in the room, call the sendTextMessage method.

RoomManager.shared.messageService.sendTextMessage("MESSAGE_CONTENT") { result in
    // The result of send messages. 
}
Enter fullscreen mode Exit fullscreen mode

To receive the text messages, listen for the callback receiveTextMessage.

func receiveTextMessage(_ message: TextMessage) {
    // Implement the handling logic when receiving the text messages.
}
Enter fullscreen mode Exit fullscreen mode

step 11. Renew a Token

30 seconds before a Token expires, the SDK sends out a notification through the onRoomTokenWillExpire callback.

Upon receiving this callback, you need to get a new Token from your app server first, and then pass the new token to the renewToken method.

func onRoomTokenWillExpire(_ remainTimeInSecond: Int32, roomID: String?) {
   let token: String = xxxxx ///new token
   RoomManager.shared.roomService.renewToken(token, roomID: roomID)

}
Enter fullscreen mode Exit fullscreen mode

step 12. Leave a live room

Before the host leaves the live room, he will need to call the leaveSeat to leave the seat first. And the SDK automatically stops publishing streams when the host leaves the seat successfully.

RoomManager.shared.userService.leaveSeat { Result in
     // Callback for the result of leave a seat. 
}
Enter fullscreen mode Exit fullscreen mode

To leave the live room, call the leaveRoom method. And the SDK stops all the stream publishing and playing operations simultaneously.

RoomManager.shared.roomService.leaveRoom { Result in
     // Callback for the result of leave a live room. 
}
Enter fullscreen mode Exit fullscreen mode

step 13. Log out

To finish the ZEGOLive service, call the logout method.

RoomManager.shared.userService.logout()
Enter fullscreen mode Exit fullscreen mode

If you want to learn more about live broadcast-related technologies.

You can follow me or send me email

Email:zegoclouddev@gmail.com

Top comments (0)