Skip to main content

Recover Rooms and Control Media by SDK

Keep a MediaSFU room usable when a device changes, a track stops, the network drops, or the meeting ends. Choose your SDK below; every section names only that package's public controls and limitations.

Complete SDK setup and authority and your platform's room lifecycle first.

For device lists, input/output selection, virtual backgrounds, and translation, continue with devices, backgrounds, and translation by SDK.

Share a room without sharing host authority

Where a package supplies a share dialog, it copies a meeting ID, link, or passcode. That is presentation—not secure invitation redemption. Your backend must decide whether a signed-in person may redeem an invitation, which role it grants, whether it expired or was already used, and whether the room ended.

Never put account credentials or reusable host authority in an invitation. After redemption, return only the approved join handoff. Expire unused or single-use invitations and require a new one after the room ends.

ReactJS 4.3.0

Use ShareEventModal inside the supplied room to present its shareable room details. Your application backend owns invitation redemption.

For a custom media-settings surface, React exports switchUserAudio and switchUserVideo. The package also exports clickAudio, clickVideo, and clickScreenShare for current-room track controls. These functions require the complete live room options; do not construct partial socket, producer, or state objects.

import {
switchUserAudio,
switchUserVideo,
clickAudio,
clickVideo,
} from 'mediasfu-reactjs';

type SwitchAudioRequest = Parameters<typeof switchUserAudio>[0];
type SwitchVideoRequest = Parameters<typeof switchUserVideo>[0];

export const selectMicrophone = (request: SwitchAudioRequest) =>
switchUserAudio(request);
export const selectCamera = (request: SwitchVideoRequest) =>
switchUserVideo(request);

ModernMediasfuGeneric owns current socket and room state. During a transient disconnect, keep one room runtime mounted, wait for current state, and never replay a moderation, poll, recording, or host action automatically. Use meetingEnded, participant leave, and ordinary socket loss as different UI states. The complete workflow is in React room recovery.

React does not publish speaker/output-device selection as part of this contract. Browser output selection may also be unavailable.

Angular 2.3.1

Use ShareEventModal for the room's share display. Redemption remains an authenticated backend operation.

Angular exports the SwitchUserAudio and SwitchUserVideo services for input selection, plus ClickAudio, ClickVideo, and ClickScreenShare for current track controls. Provide the service with the complete current room parameters; let the supplied room own them when possible.

This injectable facade keeps the SDK's complete room parameter types intact. A device picker can call these two methods with the selected device ID and the parameter object from the mounted room:

import {Injectable} from '@angular/core';
import {
SwitchUserAudio,
SwitchUserVideo,
type SwitchUserAudioOptions,
type SwitchUserVideoOptions,
} from 'mediasfu-angular';

@Injectable({providedIn: 'root'})
export class RoomInputDevices {
constructor(
private readonly audio: SwitchUserAudio,
private readonly video: SwitchUserVideo,
) {}

selectMicrophone(
deviceId: string,
parameters: SwitchUserAudioOptions['parameters'],
): Promise<void> {
return this.audio.switchUserAudio({audioPreference: deviceId, parameters});
}

selectCamera(
deviceId: string,
parameters: SwitchUserVideoOptions['parameters'],
): Promise<void> {
return this.video.switchUserVideo({
videoPreference: deviceId,
checkoff: false,
parameters,
});
}
}

The package exposes disconnect and meeting-ended handlers, but version 2.3.1 does not publish an automatic room-and-media restoration operation or a structured semantic end-reason model. Show a bounded reconnect screen only while your application still has valid authority. Otherwise obtain a fresh backend handoff or show a final ended/removed state.

There is no complete public one-call teardown or speaker-selection operation. On exit, stop app-owned tracks, unsubscribe app listeners, close app-created media elements, and discard old room authority.

React Native 2.4.0

Use ShareEventModal for shareable room details. The receiving app must send the invitation to your authenticated backend; the package does not redeem or validate invitation tokens.

Use switchVideoAlt for front/back camera changes and switchUserVideo or switchUserVideoAlt for a selected camera flow. Use clickAudio and clickVideo for local track controls. Microphone input selection is not published through the package root, and operating-system audio routes remain platform-owned.

import {
switchVideoAlt,
switchUserVideo,
clickAudio,
clickVideo,
} from 'mediasfu-reactnative';

export type CameraFlipRequest = Parameters<typeof switchVideoAlt>[0];
export const flipCamera = (request: CameraFlipRequest) =>
switchVideoAlt(request);

Version 2.4.0 does not publish an automatic rejoin/media-restore operation or a semantic host-ended reason. Treat backgrounding, network loss, participant removal, participant leave, and a product-level meeting end separately in your navigation state. On terminal exit, use the supplied leave flow, stop app-owned tracks, remove subscriptions, clear cached room data, and obtain new authority before entering again.

Test camera changes, Bluetooth/wired routes, interruption, background restore, and cleanup on physical Android and iOS devices.

Expo 2.5.0

Use ShareEventModal for meeting details and your authenticated backend for invitation redemption.

Expo exports switchVideoAlt, switchUserVideo, switchUserVideoAlt, clickAudio, and clickVideo. Use them only with the complete active room parameters. Camera selection and front/back switching can differ on Android, iOS, and web; Expo does not publish root-level microphone-device selection.

Version 2.5.0 does not publish automatic room/media restoration or a semantic host-ended reason. After backgrounding or connection loss, inspect current app and room state before enabling controls. Never replay a pending action. If the session is no longer valid, obtain a fresh backend handoff.

On terminal exit, stop app-owned tracks, remove listeners, clear stale room snapshots, and rebuild native applications after permission/configuration changes. Test all target platforms separately.

Vue 1.1.1

Use ShareEventModal for room details and your backend for invitation redemption. Vue exports clickAudio, clickVideo, and clickScreenShare for current-room track controls.

Version 1.1.1 does not export standalone device-switch functions, an automatic reconnect operation, socket end-reason helpers, or one complete teardown call from the package root. Use the supplied media-settings UI for available device changes. If your custom Vue shell owns device enumeration, keep that code application-owned and do not advertise speaker switching where the browser does not support it.

During a failure, keep unaffected controls usable, stop stale app-owned tracks, and show whether the cause is permission denial, device loss, screen-picker cancellation, transport failure, or blocked playback. Require a fresh backend handoff when authority expired.

Flutter 2.3.0

Flutter exports getMediaDevicesList, switchAudio, and switchVideo, and provides MediaSettingsModal for the supplied UI. It also provides the normal microphone, camera, and screen-share controls described in the Flutter room guide.

import 'package:mediasfu_sdk/mediasfu_sdk.dart';

Future<void> chooseMicrophone(SwitchAudioOptions options) async {
await switchAudio(options);
}

Future<void> chooseCamera(SwitchVideoOptions options) async {
await switchVideo(options);
}

The package does not publish secure invitation redemption, a general room reconnect/restore operation, a semantic end-reason model, speaker selection, or one complete teardown function. Share links from your app UI and redeem them through your backend. On failure, keep unaffected controls available and stop app-owned superseded tracks. On final exit, close app-owned observers, drafts, timers, and temporary media.

Validate switching and route behavior on every Flutter platform you ship.

Android 1.0.5

Use the room state's microphone, camera, and screen-share actions only after the room is ready. If Android denies a permission, keep the room visible, explain how to enable it, and leave unrelated controls usable.

Button(onClick = state::toggleAudio) { Text("Microphone") }
Button(onClick = state::toggleVideo) { Text("Camera") }
Button(onClick = state::toggleScreenShare) { Text("Share screen") }
Button(onClick = state::exitSession) { Text("Leave") }

After a connection interruption, wait for current participants, producers, and consumers before re-enabling controls. Do not tell users their room and media were restored merely because the socket reconnected. On exit, release any tracks, observers, and timers owned by the application.

Kotlin Multiplatform 1.0.5

Kotlin exports getMediaDevicesList, switchAudio, and switchVideo for input selection and the normal audio/video/screen controls for active tracks.

SocketManager exposes onDisconnect, onError, onReconnect, onReconnectAttempt, onReconnectFailed, and getConnectionState. These are observation hooks; they do not promise that room membership, transports, or media were restored.

socketManager.onReconnect { attempt ->
showRecovering(attempt)
}
socketManager.onReconnectFailed {
showFreshJoinRequired()
}

After a reconnect notification, wait for current room, participant, transport, producer, and consumer state before enabling controls. If authority expired, obtain a fresh backend handoff. Use MediaSfuEngine.disconnect() for the engine connection, then clear app-owned state and tracks.

Kotlin does not publish secure invitation redemption, automatic room/media restoration, a semantic host-ended reason, or one operation that proves backend residue cleanup. Android audio-output routing is available through the 1.0.5 media-settings path; test speaker, Bluetooth, and wired routes on each target instead of assuming identical KMP behavior.

Swift and Apple platforms 0.1.3

Use triggerToggleAudio(), triggerToggleVideo(), and triggerToggleScreenShare() only after makeHostViewController has mounted the room. A false result means the hosted room has not installed that action yet; keep the control disabled or show a short retry message.

guard bridge.triggerToggleAudio() else {
showMessage("Join the room before enabling your microphone.")
return
}

Present permission denial and network interruption as recoverable states. The current Apple surface does not guarantee automatic room/media restoration or a separate semantic host-end event. Release app-owned observers and dismiss the hosted controller when the participant leaves.

Unity 0.1.0-preview.2

Unity does not publish an invitation create/redeem method. Your scene may show app-owned room details, while your backend issues and redeems invitations.

Use the explicit client controls:

await client.SetMicrophoneEnabledAsync(true);
await client.SetCameraEnabledAsync(true);
await client.SetScreenShareEnabledAsync(false);

await client.PauseConsumerAsync(consumerId);
await client.ResumeConsumerAsync(consumerId);

ConnectionStateChanged and ErrorOccurred let the scene present recovery. MediaSfuSocketConfig.AutoReconnect and ConnectionState.Reconnecting expose socket reconnection state, but they do not promise room or media restoration. Wait for current room and track state before enabling controls.

Unity distinguishes participant exit with LeaveRoomAsync from host-wide end with EndMeetingAsync. After the terminal action, unsubscribe events, release native tracks/renderers owned by the media backend, call Dispose, and clear scene-owned room authority. There is no generic camera/microphone/speaker device switching method in this package; the attached media backend owns device routes.

Shared core 1.1.0

The shared core exports switchAudio, switchVideo, switchUserAudio, and switchUserVideo, plus clickAudio, clickVideo, and clickScreenShare. These are low-level functions: your renderer must supply the live socket, transport, producer, media-device, and state-update dependencies.

import {
switchAudio,
switchVideo,
clickAudio,
clickVideo,
} from 'mediasfu-shared';

type MicrophoneSwitch = Parameters<typeof switchAudio>[0];
type CameraSwitch = Parameters<typeof switchVideo>[0];

The shared core does not render invitation UI, redeem invitations, guarantee automatic room/media restoration, select speakers, expose a semantic end reason, or provide a single complete application teardown call. Your framework and backend own those workflows. Stop superseded tracks, close transports and sockets you created, remove listeners, clear stale state, and obtain new authority when needed.

Failure and cleanup checklist

  • Invitation redemption rejects expired, reused, unauthorized, and ended-room invitations.
  • No invitation contains reusable account or host authority.
  • Reconnection never replays a pending moderation or collaboration action.
  • Current room and media state—not a remembered toggle—enables controls.
  • Camera and microphone switching stops superseded input tracks.
  • Unsupported speaker selection is hidden or explained.
  • Permission denial, missing device, device loss, picker cancellation, transport failure, and blocked playback have different recovery messages.
  • Participant leave, participant removal, connection loss, and host end lead to different next actions.
  • Terminal exit clears app-owned tracks, transports, listeners, timers, drafts, media elements, room snapshots, and temporary authority.
  • Backend invitations, grants, and room residue expire according to product policy.