diff --git a/examples/react-client/use-camera-and-microphone/src/DeviceControls.tsx b/examples/react-client/use-camera-and-microphone/src/DeviceControls.tsx index 6b3ed55a..945b9ce8 100644 --- a/examples/react-client/use-camera-and-microphone/src/DeviceControls.tsx +++ b/examples/react-client/use-camera-and-microphone/src/DeviceControls.tsx @@ -38,7 +38,7 @@ export const DeviceControls = ({ className="btn btn-error btn-sm" disabled={!device?.stream} onClick={() => { - device?.cleanup(); + device?.stop(); }} > Stop {type} device diff --git a/examples/react-client/use-camera-and-microphone/src/MainControls.tsx b/examples/react-client/use-camera-and-microphone/src/MainControls.tsx index 7f95319c..3da6840d 100644 --- a/examples/react-client/use-camera-and-microphone/src/MainControls.tsx +++ b/examples/react-client/use-camera-and-microphone/src/MainControls.tsx @@ -375,7 +375,7 @@ export const MainControls = () => { }} defaultOptionText="Select video device" stop={() => { - video.cleanup(); + video.stop(); }} /> @@ -389,7 +389,7 @@ export const MainControls = () => { }} defaultOptionText="Select audio device" stop={() => { - audio.cleanup(); + audio.stop(); }} /> diff --git a/packages/react-client/src/Client.ts b/packages/react-client/src/Client.ts index e9c7b43d..3ee2aac7 100644 --- a/packages/react-client/src/Client.ts +++ b/packages/react-client/src/Client.ts @@ -399,8 +399,10 @@ export class Client extends (EventEmitter as { this.tsClient.on("disconnected", () => { this.status = null; - this.videoTrackManager.stopStreaming(); - this.audioTrackManager.stopStreaming(); + + this.videoTrackManager.cleanup(); + this.audioTrackManager.cleanup(); + this.stateToSnapshot(); this.emit("disconnected", this); diff --git a/packages/react-client/src/index.ts b/packages/react-client/src/index.ts index 6a712bc4..84589be8 100644 --- a/packages/react-client/src/index.ts +++ b/packages/react-client/src/index.ts @@ -24,6 +24,7 @@ export type { UseSetupMediaResult, UseSetupMediaConfig, CreateFishjamClient, + ScreenshareApi, UseConnect, GenericTrackManager, } from "./types"; diff --git a/packages/react-client/src/trackManager.ts b/packages/react-client/src/trackManager.ts index 293761da..9f43f563 100644 --- a/packages/react-client/src/trackManager.ts +++ b/packages/react-client/src/trackManager.ts @@ -4,8 +4,8 @@ import type { Track } from "./state.types"; import { getRemoteOrLocalTrack } from "./utils/track"; export class TrackManager implements GenericTrackManager { - private mediaManager: GenericMediaManager; - private tsClient: FishjamClient; + private readonly mediaManager: GenericMediaManager; + private readonly tsClient: FishjamClient; private currentTrackId: string | null = null; constructor(tsClient: FishjamClient, deviceManager: GenericMediaManager) { @@ -31,10 +31,14 @@ export class TrackManager implements GenericTrackMa this.mediaManager?.start(deviceId ?? true); }; - public cleanup = async () => { + public stop = async () => { this?.mediaManager?.stop(); }; + public cleanup = () => { + this.currentTrackId = null; + }; + public startStreaming = async ( trackMetadata?: TrackMetadata, simulcastConfig?: SimulcastConfig, diff --git a/packages/react-client/src/types.ts b/packages/react-client/src/types.ts index 9963f629..8a6ad492 100644 --- a/packages/react-client/src/types.ts +++ b/packages/react-client/src/types.ts @@ -155,7 +155,7 @@ export interface GenericMediaManager { export interface GenericTrackManager { initialize: (deviceId?: string) => Promise; - cleanup: () => Promise; + stop: () => Promise; startStreaming: ( trackMetadata?: TrackMetadata, simulcastConfig?: SimulcastConfig, @@ -181,7 +181,7 @@ export type UserMediaAPI = { }; export type ScreenshareApi = { - startStreaming: () => Promise; + startStreaming: (props?: { metadata?: TrackMetadata; requestAudio?: boolean }) => Promise; stopStreaming: () => Promise; stream: MediaStream | null; videoTrack: MediaStreamTrack | null;