paint-brush
How to Build a Live App in 10 Minutes with ZEGOCLOUD's ZEGOLiveby@zegoclouddev
1,348 reads
1,348 reads

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

by ZEGOCLOUDJune 17th, 2022
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

Live streaming is already worth billions of dollars and it’s only expected to grow. ZEGOLive SDK provides all features that required by a live streaming app, such as creating and joining a live stream room, co-hosting, face beautification, audio effects, virtual gifting, sending bullet-screen messages, and more. The live streaming industry is expected to climb from `$70' billion in 2021 to almost `$224` billion in 2028. Here I will introduce how to quickly build your own live streaming apps by using ZEGOCLOUD's ZEGolive SDK.

Company Mentioned

Mention Thumbnail
featured image - How to Build a Live App in 10 Minutes with ZEGOCLOUD's ZEGOLive
ZEGOCLOUD HackerNoon profile picture


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:

Features

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.

  1. Click the Add button (+) to add camera and microphone permissions.
  • Privacy-Camera Usage Description
  • Privacy-Microphone Usage 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. 

};

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

step 7. Log in

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

<div class="mk-warning">

  • 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. </div>
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. 

}

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)

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.

<div class="mk-warning">

  • 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. </div>

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. 
           
}

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. 

}

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. 

}

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)

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. 
}

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

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

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)
        
}

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. 
}

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. 
}

step 13. Log out

To finish the ZEGOLive service, call the logout method.

RoomManager.shared.userService.logout()

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

You can follow me or send me email

Email:[email protected]


Also published here.