跳轉到

Disconnection

A call with one participant ends when either side hangs up or the connection to them fails. Both sides then receive participantDidDisconnect. The room itself never closes: you can invite friends again at any time.

Leave the room

Call Room.disconnectAll() on Room.shared to hang up on every remote participant. The room itself stays, so you can invite friends again afterwards.

import RevueSDK

/// Hang up on every remote participant. The room itself stays, so you can invite friends again afterwards.
@MainActor
func leaveRoom() {
    Room.shared.disconnectAll()
}

To hang up on one participant only, call RemoteParticipant.disconnect() on them. Everyone else stays connected.

Call Room.disconnectAll() and RemoteParticipant.disconnect() on the main thread. Both are marked @MainActor, and the disconnect events are delivered before the call returns.

import RevueSDK

/// Hang up on one remote participant. Everyone else in the room stays connected.
@MainActor
func hangUp(on friendId: String) {
    Room.shared.remoteParticipants[friendId]?.disconnect()
}

When a participant disconnects

Your RoomDelegate receives participantDidDisconnect for every remote participant who leaves, including the ones you hung up on yourself. By the time it arrives, the participant has already been removed from Room.remoteParticipants.

To tell why, read RemoteParticipant.lastDisconnectReason, a DisconnectReason:

Reason Meaning
DisconnectReason.leave The call was ended on purpose: the other side hung up, or you did.
DisconnectReason.networkLost The call ended because the connection to the other side failed.
import RevueSDK

/// Find out why a remote participant left, to show the right message.
final class CallEndedHandler: RoomDelegate {
    var onCallEnded: ((RemoteParticipant, String) -> Void)?

    func room(_ room: Room, participantDidDisconnect participant: RemoteParticipant) {
        onCallEnded?(participant, callEndedText(for: participant))
    }
}

func callEndedText(for participant: RemoteParticipant) -> String {
    switch participant.lastDisconnectReason {
    case .networkLost?:
        return "Connection to \(participant.name ?? participant.identity) was lost"
    case .leave?, nil:
        return "Call ended"
    }
}

The participant's own ParticipantDelegate receives the same reason in didDisconnectWithReason.

A friend connection that drops for a moment does not end the call, and you do not receive participantDidDisconnect for it. See Connection state.

Shut down the SDK

Revue.destroy(_:) ends every call, removes all delegates and stops the SDK, for example when the user signs out. After that, nobody can find you or call you until you call initialize again.

import RevueSDK

/// Shut the whole SDK down, for example when the user signs out. Call initialize again to start over.
@MainActor
func stopRevue() async {
    await Revue.shared.destroy()
}

What destroy can delete, and how to start again, is covered in Initialization and configuration.