Skip to content

videosdk-live/videosdk-rtc-ios-sdk-example

Repository files navigation

Video SDK for iOS

Documentation Firebase TestFlight Discord Register

At Video SDK, we’re building tools to help companies create world-class collaborative products with capabilities of live audio/videos, compose cloud recordings/rtmp/hls and interaction APIs

Demo App

πŸ“² Download the Sample iOS app here: https://testflight.apple.com/join/26EBZkcX


Meeting Features

  • Real-time video and audio conferencing
  • Enable/disable camera
  • Mute/unmute mic
  • Chat
  • Raise hand
  • Recording

Setup Guide


Prerequisites

Run the Sample App

Step 1: Clone the sample project

git clone https://github.com/videosdk-live/videosdk-rtc-ios-sdk-example.git

Step 2. Install Pods

Run pod install in terminal from the Example project directory.

Step 3. update AUTH_TOKEN in the Constants.swift file.

Generate temporary token from Video SDK Account.

public let AUTH_TOKEN = "#YOUR_GENERATED_TOKEN"

Step 4. Run the project.

Run App from Xcode. Please run the app in real device for better experience because audio and video is not supported in simulator.


Key Concepts

  • Meeting - A Meeting represents Real time audio and video communication.

    Note : Don't confuse with Room and Meeting keyword, both are same thing πŸ˜ƒ

  • Sessions - A particular duration you spend in a given meeting is a referred as session, you can have multiple session of a particular meetingId.

  • Participant - Participant represents someone who is attending the meeting's session, local partcipant represents self (You), for this self, other participants are remote participants.

  • Stream - Stream means video or audio media content that is either published by local participant or remote participants.


Permissions

  • Your app needs to add permissions to use microphone and camera. Add below code your app's info.plist.
<key>NSCameraUsageDescription</key>
<string>Allow camera access to start video.</string>

<key>NSMicrophoneUsageDescription</key>
<string>Allow microphone access to start audio.</string>

Token Generation

Token is used to create and validate a meeting using API and also initialise a meeting.

πŸ› οΈ Development Environment:

  • You may use a temporary token for development. To create a temporary token, go to VideoSDK dashboard .

🌐 Production Environment:

  • You must set up an authentication server to authorise users for production. To set up an authentication server, refer to our official example repositories. videosdk-rtc-api-server-examples

API: Create and Validate meeting

  • create meeting - Please refer this documentation to create meeting.
  • validate meeting- Please refer this documentation to validate the meetingId.

  • You can initialize the meeting using VideoSDK.initMeeting method. this method configures meeting with given meeting-id.
    VideoSDK.config(token: "server-token")

    meeting = VideoSDK.initMeeting(
        meetingId: "meeting-id",
        participantId: "participant-id"
        participantName: "participant-name",
        micEnabled: true,
        webcamEnabled: true,
      )

    buttonControlsView.onVideoTapped = { on in
        
        if !on {
            self.meeting?.enableWebcam()
        } else {
            self.meeting?.disableWebcam()
        }
    }

    buttonControlsView.onMicTapped = { on in
        if !on {
            self.meeting?.unmuteMic()
        } else {
            self.meeting?.muteMic()
        }
    }

    AVAudioSession.sharedInstance().changeAudioOutput(presenterViewController: self)

  • The chat feature allows participants to send and receive messages about specific topics to which they have subscribed.
    // listen/subscribe for chat topic
    meeting?.pubsub.subscribe(topic: CHAT_TOPIC, forListener: self)
    
    //write this block on click event
    meeting.pubSub.publish(topic: "CHAT", message: message, options: { persist: true })
    
    //unsubscribing messages on topic CHAT
    meeting.pubSub.unsubscribe("CHAT");

Raise Hand

  • This feature allows participants to raise hand during the meeting.
    // listen/subscribe for raise-hand topic
    meeting?.pubsub.subscribe(topic: RAISE_HAND_TOPIC, forListener: self);
    
    // raise hand on click event
    self.meeting?.pubsub.publish(topic: RAISE_HAND_TOPIC, message: "Raise Hand by Me", options: [:])

  • Record meeting allows participants to record video & audio during the meeting. The recording files are available in developer dashboard. Any participant can start / stop recording any time during the meeting.
    let webhookUrl = "https://webhook.your-api-server.com"
    
    // start recording
    meeting.startRecording(webhookUrl: webhookUrl)
    
    // stop recording
    stopRecording()

  • Interactive Live Streaming allows participants to to broadcast live streaming to other participants. Host can start / stop HLS any time during the meeting.
    // start live streaming
    startLivestream(outputs: outputs)
    
    // stop live streaming
    stopLivestream()

  // Only one participant will leave/exit the meeting; the rest of the participants will remain.
  meeting?.leave();

  // The meeting will come to an end for each and every participant. So, use this function in accordance with your requirements.
  meeting?.end();

By registering callback handlers, VideoSDK sends callbacks to the client app whenever there is a change or update in the meeting after a user joins.

func onMeetingJoined() {
  // This event will be emitted when a localParticipant(you) successfully joined the meeting.
  print("onMeetingJoined");
}
func onMeetingLeft() {
  // This event will be emitted when a localParticipant(you) left the meeting.
  print("onMeetingLeft");
}
func onParticipantJoined(participant) {
  // This event will be emitted when a new participant joined the meeting.
  // [participant]: new participant who joined the meeting
  print(" onParticipantJoined", participant);
}
func onParticipantLeft(participant) {
  // This event will be emitted when a joined participant left the meeting.
  // [participantId]: id of participant who left the meeting
  print(" onParticipantLeft", participant);
}
func onSpeakerChanged = (activeSpeakerId) => {
  // This event will be emitted when any participant starts or stops screen sharing.
  // [activeSpeakerId]: Id of participant who shares the screen.
  print(" onSpeakerChanged", activeSpeakerId);
};
func onRecordingStarted() {
  // This event will be emitted when recording of the meeting is started.
  print(" onRecordingStarted");
}
func onRecordingStopped() {
  // This event will be emitted when recording of the meeting is stopped.
  print(" onRecordingStopped");
}

By registering callback handlers, VideoSDK sends callbacks to the client app whenever a participant's video, audio, or screen share stream is enabled or disabled.

  func onStreamEnabled(stream, participant) {
    // This event will be triggered whenever a participant's video, audio or screen share stream is enabled.
    print("onStreamEnabled");
  }
  func onStreamDisabled(stream, participant) {
    // This event will be triggered whenever a participant's video, audio or screen share stream is disabled.
    print(" onStreamDisabled");
  }

If you want to learn more about the SDK, read the Complete Documentation of iOS VideoSDK


Project Description


Note :

  • main branch: Better UI with One-to-One and Conference call experience.
  • v1-sample-code branch: Simple UI with Group call experience.

Project Structure

We have separated conrtroller and components in following folder structure:

VideoSDK
└── view
    └── ButtonControlsView.swift
    └── ParticipantCellView.swift
└── API
    └── Constants.swift
    └── APIService.swift
└── models
    └── Message.swift
    └── ChatUser.swift
    └── MeetingData.swift
└── controllers
    └── StartMeetingViewController.swift
    └── MeetingViewController.swift
    └── ChatViewController.swift

Examples

Examples for Conference

Examples for Live Streaming

Documentation

Read the documentation to start using Video SDK.

Community

  • Discord - To get involved with the Video SDK community, ask questions and share tips.
  • Twitter - To receive updates, announcements, blog posts, and general Video SDK tips.