Skip to main content
Version: 2.0.x

Relay Media(PK Host) - iOS

Overview​

The Relay Media feature enables hosts to relay their media (audio, video, screen share) to one or multiple other live streams. This creates cross-stream interactions similar to "PK battles" or collaborative broadcasts.

This feature allows audiences in one live stream to view and hear hosts from another live stream without changing rooms, creating powerful interactive experiences.

Key Concepts​

  • Media Relay: The process of transmitting a host's audio/video from one live stream to another
  • Source Meeting: The original live stream where the host is broadcasting
  • Destination Meeting: The target live stream(s) where the host's media will be relayed
  • Relay Kinds: The types of media that can be relayed (video, audio, screen share, etc.)

Sequence Diagram​

sequenceDiagram participant HostA as Host A participant HostB as Host B participant AudienceB as Audience B HostA->>HostB: requestMediaRelay(meetingB_Id, token, kinds) HostB-->>HostB: mediaRelayRequestReceived event alt Accept HostB->>HostA: accept() HostA-->>HostA: mediaRelayRequestResponse("accepted") HostA-->>HostA: mediaRelayStarted(meetingB_Id) HostA->>AudienceB: Media streaming else Reject HostB->>HostA: reject() HostA-->>HostA: mediaRelayRequestResponse("rejected") end HostA->>HostB: stopMediaRelay(meetingB_Id) HostA-->>HostA: mediaRelayStopped(meetingB_Id, reason);

Implementation Guide​

1. Requesting Media Relay​

requestMediaRelay()​

Parameters:

  • destinationMeetingId: ID of the target liveStream
  • token: Authentication token for the destination liveStream
  • kinds : Optional array of media types to relay. Supported values:
    • "video": Camera video
    • "audio": Microphone audio
    • "share": Screen share video
    • "share_audio": Screen share audio
@IBAction func requestRelayBtn(_ sender: UIButton) {
Task {
meeting.requestMediaRelay(destinationMeetingId: "abc123", token: "YOUR_TOKEN_HERE", kinds: ["audio", "video"])
}
}

2. Handling Relay Requests (Destination Meeting)​

In the destination liveStream, hosts (participants with SEND_AND_RECV mode) will receive relay requests:

func liveStreamController : MeetingEventListener { 

func onMediaRelayRequestReceived(participantId: String, meetingId: String, displayName: String, accept: @escaping () -> Void, reject: @escaping () -> Void) {

guard let viewController = getTopViewController() else {
return
}

let alert = UIAlertController(
title: "Entry Request",
message: "\(displayName) Reaquest MediaRelayRequest for \(meetingId). Allow?",
preferredStyle: .alert
)

let acceptAction = UIAlertAction(title: "Accept", style: .default) { _ in
accept()
}

let declineAction = UIAlertAction(title: "Decline", style: .destructive) { _ in
reject()
}

alert.addAction(acceptAction)
alert.addAction(declineAction)

DispatchQueue.main.async {
viewController.present(alert, animated: true)
}

}
}

3. Handling Request Responses (Source Meeting)​

In the source liveStream, track the response to your relay requests:


func liveStreamController : MeetingEventListener {

func onMediaRelayRequestResponse(decision: String, decidedBy: String, meetingId: String) {
print("onMediaRelayRequestResponse: \(decision), \(decidedBy), \(meetingId)")
}

}

4. Tracking Active Relays​

When a relay successfully starts:

func liveStreamController : MeetingEventListener { 

func onMediaRelayStarted(meetingId: String) {
print("onMediaRelayStarted: \(meetingId)")
}

}

5. Stopping Media Relay​

To stop an ongoing relay:

stopMediaRelay()​

Parameters:

  • liveStreamId (string): ID of the liveStream where the relay should stop
@IBAction func stopMediaRelayBtn(_ sender: UIButton) {
Task {
meeting?.stopMediaRelay(liveStreamId: "abc123")
}
}

6. Handling Relay Stop Events​

When a relay stops for any reason:


func liveStreamController: MeetingEventListener {

func onMediaRelayStopped(liveStreamId, reason) {
print("onMediaRelayStopped: \(liveStreamId) \ (reason)")
}

}

7. Handling Relay Errors​

To handle errors that may occur during relay:

func liveStreamController: MeetingEventListener { 

func onMediaRealyError(liveStreamId: String, error: String) {
print("onMediaRealyError: \(liveStreamId), \(error)")
}

}

Use Cases​

  1. Guest Appearances: Allow popular hosts to make guest appearances in other streams without leaving their audience
  2. Cross-Stream Competitions: Create "battles" or competitions between hosts in different streams
  3. Multi-Location Broadcasting: Connect hosts from different physical locations into a shared experience
  4. Expert Commentary: Bring in subject matter experts to comment on events in another stream

Troubleshooting​

Common Issues​

  1. Relay Request Not Received

    • Verify both meetings are active
    • Check that destination liveStream ID is correct
    • Ensure the token has proper permissions
  2. Media Not Visible After Acceptance

    • Verify network connectivity
    • Check that appropriate media kinds were specified
    • Ensure the host has enabled their camera/microphone
  3. Unexpected Relay Termination

    • Check for network connectivity issues
    • Verify that both meetings remain active
    • Look for error events with specific reasons

API Reference​

Got a Question? Ask us on discord