Giter Site home page Giter Site logo

easy_example_ios's Introduction

ZEGOCLOUD easy example

Platform ZEGOCLOUD

Click the search button below to search documentation or error code

image

ZEGOCLOUD's easy example is a simple wrapper around our RTC product. You can refer to the sample code for quick integration.

Getting started

Prerequisites

Install Pods

  1. Clone the easy example Github repository.
  2. Open Terminal, navigate to the ZegoEasyExample folder where the Podfile is located, and run the pod repo update command.
  3. Run the pod install command to install all dependencies that are needed.

Modify the project configurations

You need to modify appID and serverSecret to your own account, which can be obtained in the ZEGO Admin Console.

Run the sample code

  1. Connect the iOS device to your computer.

  2. Open Xcode, click the Any iOS Device in the upper left corner, select the iOS device you are using.

  3. Click the Build button in the upper left corner to run the sample code and experience the Live Audio Room service.

Integrate the SDK into your own project

Introduce SDK

1 add ZegoExpressEngine and ZegoToken SDK in your project 2 Run the pod install command to install all dependencies that are needed.

target 'Your_Project_Name' do
  # Comment the next line if you don't want to use dynamic frameworks
  use_frameworks!

  # Pods for ZegoEasyExample
  pod 'ZegoExpressEngine'
  pod ‘ZegoToken’

end

Copy the source code

Copy the AppCenter.swift and ZegoExpressManager.swift files to your project

Method call

The calling sequence of the SDK interface is as follows: createEngine --> joinRoom --> setLocalVideoView/setRemoteVideoView --> leaveRoom

Create engine

Before using the SDK function, you need to create the SDK first. We recommend creating it when the application starts. The sample code is as follows:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // create engine
        ZegoExpressManager.shared.createEngine(appID: AppCenter.appID)
        return true
    }

Join room

When you want to communicate with audio and video, you need to call the join room interface first. According to your business scenario, you can set different audio and video controls through options, such as:

  1. call scene:[.autoPlayVideo, .autoPlayAudio, .publishLocalAudio, .publishLocalVideo]
  2. Live scene - host: [.autoPlayVideo, .autoPlayAudio, .publishLocalAudio, .publishLocalVideo]
  3. Live scene - audience:[.autoPlayVideo, .autoPlayAudio]
  4. Chat room - host:[.autoPlayAudio, .publishLocalAudio]
  5. Chat room - audience:[.autoPlayAudio]

The following sample code is an example of a call scenario:

    @IBAction func pressJoinRoom(_ sender: UIButton) {
        
        // join room
        let roomID = "111"
        let user = ZegoUser(userID: "id\(Int(arc4random()))", userName: "Tim")
        let token = generateToken(userID: user.userID)
        let option: ZegoMediaOptions = [.autoPlayVideo, .autoPlayAudio, .publishLocalAudio, .publishLocalVideo]
        ZegoExpressManager.shared.joinRoom(roomID: roomID, user: user, token: token, options: option)
        presentVideoVC()
    }

set video view

If your project needs to use the video communication function, you need to set the View for displaying the video, call setLocalVideoView for the local video, and call setRemoteVideoView for the remote video.

setLocalVideoView:

    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = UIColor.white
        // set video view
        ZegoExpressManager.shared.setLocalVideoView(renderView: localVideoView)
        
    }

setRemoteVideoView:

   func onRoomUserUpdate(udpateType: ZegoUpdateType, userList: [String], roomID: String) {
        for userID in userList {
            // set video view
            ZegoExpressManager.shared.setRemoteVideoView(userID:userID, renderView: remoteVideoView)
        }
    }

leave room

When you want to leave the room, you can call the leaveroom interface.

@IBAction func pressLeaveRoomButton(_ sender: Any) {
    ZegoExpressManager.shared.leaveRoom()
    self.dismiss(animated: true, completion: nil)
}

easy_example_ios's People

Contributors

larryluo1 avatar match-yang avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.