@fishjam-cloud/react-client 0.7.0 → 0.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. package/dist/DeviceManager.d.ts +33 -17
  2. package/dist/DeviceManager.d.ts.map +1 -1
  3. package/dist/DeviceManager.js +126 -97
  4. package/dist/constraints.d.ts +2 -3
  5. package/dist/constraints.d.ts.map +1 -1
  6. package/dist/constraints.js +9 -10
  7. package/dist/devices/MiddlewareManager.d.ts +9 -0
  8. package/dist/devices/MiddlewareManager.d.ts.map +1 -0
  9. package/dist/devices/MiddlewareManager.js +26 -0
  10. package/dist/fishjamProvider.d.ts +8 -6
  11. package/dist/fishjamProvider.d.ts.map +1 -1
  12. package/dist/fishjamProvider.js +27 -11
  13. package/dist/hooks/deviceManagers/useDeviceManager.d.ts +1 -1
  14. package/dist/hooks/deviceManagers/useDeviceManager.d.ts.map +1 -1
  15. package/dist/hooks/deviceManagers/useDeviceManager.js +2 -2
  16. package/dist/hooks/{useDevices.d.ts → devices.d.ts} +14 -2
  17. package/dist/hooks/devices.d.ts.map +1 -0
  18. package/dist/hooks/{useDevices.js → devices.js} +29 -15
  19. package/dist/hooks/public.d.ts +2 -4
  20. package/dist/hooks/public.d.ts.map +1 -1
  21. package/dist/hooks/public.js +2 -4
  22. package/dist/hooks/useConnection.d.ts +10 -2
  23. package/dist/hooks/useConnection.d.ts.map +1 -1
  24. package/dist/hooks/useConnection.js +8 -0
  25. package/dist/hooks/useFishjamClientState.d.ts +1 -2
  26. package/dist/hooks/useFishjamClientState.d.ts.map +1 -1
  27. package/dist/hooks/useFishjamClientState.js +0 -4
  28. package/dist/hooks/useFishjamClient_DO_NOT_USE.d.ts +6 -1
  29. package/dist/hooks/useFishjamClient_DO_NOT_USE.d.ts.map +1 -1
  30. package/dist/hooks/useFishjamClient_DO_NOT_USE.js +5 -0
  31. package/dist/hooks/useFishjamContext.d.ts +4 -4
  32. package/dist/hooks/useFishjamContext.d.ts.map +1 -1
  33. package/dist/hooks/usePeerStatus.d.ts +8 -0
  34. package/dist/hooks/usePeerStatus.d.ts.map +1 -0
  35. package/dist/hooks/{useParticipantStatus.js → usePeerStatus.js} +12 -12
  36. package/dist/hooks/usePeers.d.ts +10 -0
  37. package/dist/hooks/usePeers.d.ts.map +1 -0
  38. package/dist/hooks/{useParticipants.js → usePeers.js} +8 -5
  39. package/dist/hooks/useReconnection.d.ts +4 -0
  40. package/dist/hooks/useReconnection.d.ts.map +1 -1
  41. package/dist/hooks/useReconnection.js +4 -0
  42. package/dist/hooks/useScreenShare.d.ts +13 -1
  43. package/dist/hooks/useScreenShare.d.ts.map +1 -1
  44. package/dist/hooks/useScreenShare.js +34 -31
  45. package/dist/hooks/useStatus.d.ts +5 -1
  46. package/dist/hooks/useStatus.d.ts.map +1 -1
  47. package/dist/hooks/useStatus.js +4 -0
  48. package/dist/hooks/useTrackManager.d.ts +4 -4
  49. package/dist/hooks/useTrackManager.d.ts.map +1 -1
  50. package/dist/hooks/useTrackManager.js +32 -47
  51. package/dist/index.d.ts +3 -6
  52. package/dist/index.d.ts.map +1 -1
  53. package/dist/index.js +2 -3
  54. package/dist/mediaInitializer.d.ts +2 -2
  55. package/dist/mediaInitializer.d.ts.map +1 -1
  56. package/dist/mediaInitializer.js +30 -1
  57. package/dist/types/internal.d.ts +119 -0
  58. package/dist/types/internal.d.ts.map +1 -0
  59. package/dist/types/public.d.ts +65 -0
  60. package/dist/types/public.d.ts.map +1 -0
  61. package/dist/utils/errors.d.ts +1 -1
  62. package/dist/utils/errors.d.ts.map +1 -1
  63. package/dist/utils/localStorage.d.ts +3 -4
  64. package/dist/utils/localStorage.d.ts.map +1 -1
  65. package/dist/utils/localStorage.js +18 -4
  66. package/dist/utils/track.d.ts +3 -2
  67. package/dist/utils/track.d.ts.map +1 -1
  68. package/dist/utils/track.js +8 -2
  69. package/package.json +7 -7
  70. package/readme.md +20 -118
  71. package/dist/hooks/deviceManagers/useAudioDeviceManager.d.ts +0 -2
  72. package/dist/hooks/deviceManagers/useAudioDeviceManager.d.ts.map +0 -1
  73. package/dist/hooks/deviceManagers/useAudioDeviceManager.js +0 -7
  74. package/dist/hooks/deviceManagers/useVideoDeviceManager.d.ts +0 -2
  75. package/dist/hooks/deviceManagers/useVideoDeviceManager.d.ts.map +0 -1
  76. package/dist/hooks/deviceManagers/useVideoDeviceManager.js +0 -7
  77. package/dist/hooks/useDevices.d.ts.map +0 -1
  78. package/dist/hooks/useParticipantStatus.d.ts +0 -8
  79. package/dist/hooks/useParticipantStatus.d.ts.map +0 -1
  80. package/dist/hooks/useParticipants.d.ts +0 -6
  81. package/dist/hooks/useParticipants.d.ts.map +0 -1
  82. package/dist/hooks/useProcessedPreviewStream.d.ts +0 -3
  83. package/dist/hooks/useProcessedPreviewStream.d.ts.map +0 -1
  84. package/dist/hooks/useProcessedPreviewStream.js +0 -17
  85. package/dist/state.types.d.ts +0 -42
  86. package/dist/state.types.d.ts.map +0 -1
  87. package/dist/types.d.ts +0 -255
  88. package/dist/types.d.ts.map +0 -1
  89. package/dist/utils/media.d.ts +0 -12
  90. package/dist/utils/media.d.ts.map +0 -1
  91. package/dist/utils/media.js +0 -64
  92. /package/dist/{state.types.js → types/internal.js} +0 -0
  93. /package/dist/{types.js → types/public.js} +0 -0
package/readme.md CHANGED
@@ -1,133 +1,35 @@
1
- [![NPM Version](https://img.shields.io/npm/v/@fishjam-cloud/react-client)](https://www.npmjs.com/package/@fishjam-cloud/react-client)
2
- [![TypeScript Strict](https://badgen.net/badge/TS/Strict)](https://www.typescriptlang.org)
3
- [![TypeDoc](https://img.shields.io/badge/TypeDoc-8A2BE2)](https://fishjam-cloud.github.io/web-client-sdk/modules/_fishjam_dev_react_client.html)
1
+ <img src="../../.github/images/fishjam-card.png" width="100%">
4
2
 
5
- # Fishjam React Client
3
+ # Fishjam Cloud React client
6
4
 
7
- React client library for [Fishjam Cloud](https://cloud.fishjam.stream).
8
- It is a wrapper around
9
- the [TS client](../ts-client/README.md).
5
+ `@fishjam-cloud/react-client` is an easiest way to add video streaming to your React web app.
10
6
 
11
- ## Documentation
7
+ # Installation
12
8
 
13
- Documentation is available [here](https://fishjam-cloud.github.io/web-client-sdk/modules/_fishjam_dev_react_client.html) or you can generate it locally:
9
+ Check out the [installation](https://fishjam-cloud.github.io/documentation/guide/react/installation) section of our docs for the detailed installation instructions.
14
10
 
15
- ```bash
16
- yarn run docs
17
- ```
11
+ # Documentation
18
12
 
19
- ## Installation
13
+ Check out our [documentation](https://fishjam-cloud.github.io/documentation/) on how Fishjam Cloud work and how to integrate our service with your app.
20
14
 
21
- You can install this package using `npm`:
15
+ There is also [API documentation](https://fishjam-cloud.github.io/web-client-sdk/) available.
22
16
 
23
- ```bash
24
- npm install @fishjam-cloud/react-client
25
- ```
17
+ # Examples
26
18
 
27
- or `yarn`:
19
+ There are [few example apps](https://github.com/fishjam-cloud/web-client-sdk/tree/main/examples/react-client#examples-for-fishjam-client) that shows how to use Fishjam Cloud SDKs and service.
28
20
 
29
- ```bash
30
- yarn @fishjam-cloud/react-client
31
- ```
21
+ - [Fishjam Chat](https://github.com/fishjam-cloud/web-client-sdk/tree/main/examples/react-client/fishjam-chat) - example video chat app
22
+ - [minimal-react](https://github.com/fishjam-cloud/web-client-sdk/tree/main/examples/react-client/minimal-react) - minimal example that shows how to connect and broadcast screen
32
23
 
33
- ## Usage
24
+ ## License
34
25
 
35
- Prerequisites:
36
-
37
- - Account on [Fishjam Cloud](https://cloud.fishjam.stream) with App configured.
38
- - Created room and token of peer in that room.
39
- You can use Room Manager to create room and peer token.
40
-
41
- This snippet is based
42
- on [minimal-react](../../examples/react-client/minimal-react/) example.
43
-
44
- ```tsx
45
- // main.tsx
46
- import React from "react";
47
- import ReactDOM from "react-dom/client";
48
- import { App, FishjamContextProvider } from "./components/App";
49
-
50
- ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(
51
- <React.StrictMode>
52
- <FishjamContextProvider>
53
- <App />
54
- </FishjamContextProvider>
55
- </React.StrictMode>,
56
- );
57
-
58
- // components/App.tsx
59
- import VideoPlayer from "./VideoPlayer";
60
- import { SCREEN_SHARING_MEDIA_CONSTRAINTS } from "@fishjam-cloud/react-client";
61
- import { create } from "@fishjam-cloud/react-client";
62
- import { useState } from "react";
63
-
64
- // Create a Fishjam client instance
65
- // remember to use FishjamContextProvider
66
- export const { useApi, useTracks, useStatus, useConnect, useDisconnect, FishjamContextProvider } = create();
67
-
68
- export const App = () => {
69
- const [token, setToken] = useState("");
70
-
71
- const connect = useConnect();
72
- const disconnect = useDisconnect();
73
- const api = useApi();
74
- const status = useStatus();
75
- const tracks = useTracks();
76
-
77
- return (
78
- <div>
79
- <input value={token} onChange={(e) => setToken(() => e?.target?.value)} placeholder="token" />
80
- <div>
81
- <button
82
- disabled={token === "" || status === "joined"}
83
- onClick={() => {
84
- if (!token || token === "") throw Error("Token is empty");
85
- connect({
86
- token: token,
87
- });
88
- }}
89
- >
90
- Connect
91
- </button>
92
- <button
93
- disabled={status !== "joined"}
94
- onClick={() => {
95
- disconnect();
96
- }}
97
- >
98
- Disconnect
99
- </button>
100
- <button
101
- disabled={status !== "joined"}
102
- onClick={() => {
103
- // Get screen sharing MediaStream
104
- navigator.mediaDevices.getDisplayMedia(SCREEN_SHARING_MEDIA_CONSTRAINTS).then((screenStream) => {
105
- // Add local MediaStream to webrtc
106
- screenStream.getTracks().forEach((track) => api.addTrack(track, { type: "screen" }));
107
- });
108
- }}
109
- >
110
- Start screen share
111
- </button>
112
- <span>Status: {status}</span>
113
- </div>
114
- {/* Render the remote tracks from other peers*/}
115
- {Object.values(tracks).map(({ stream, trackId }) => (
116
- <VideoPlayer key={trackId} stream={stream} /> // Simple component to render a video element
117
- ))}
118
- </div>
119
- );
120
- };
121
- ```
122
-
123
- ## Examples
124
-
125
- For examples, see [examples](../../examples/react-client/) folder.
126
-
127
- ## Copyright and License
26
+ Licensed under the [Apache License, Version 2.0](LICENSE)
128
27
 
129
- Copyright 2024, [Software Mansion](https://swmansion.com/?utm_source=git&utm_medium=readme&utm_campaign=react-client)
28
+ ## Fishjam Cloud is created by Software Mansion
130
29
 
131
- [![Software Mansion](https://logo.swmansion.com/logo?color=white&variant=desktop&width=200&tag=react-client)](https://swmansion.com/?utm_source=git&utm_medium=readme&utm_campaign=react-client)
30
+ Since 2012 [Software Mansion](https://swmansion.com) is a software agency with experience in building web and mobile
31
+ apps. We are Core React Native Contributors and experts in dealing with all kinds of React Native issues. We can help
32
+ you build your next dream product –
33
+ [Hire us](https://swmansion.com/contact/projects?utm_source=fishjam&utm_medium=web-readme).
132
34
 
133
- Licensed under the [Apache License, Version 2.0](LICENSE)
35
+ [![Software Mansion](https://logo.swmansion.com/logo?color=white&variant=desktop&width=200&tag=react-client)](https://swmansion.com/contact/projects?utm_source=fishjam&utm_medium=web-readme)
@@ -1,2 +0,0 @@
1
- export declare const useAudioDeviceManager: () => import("../../types").DeviceManagerState;
2
- //# sourceMappingURL=useAudioDeviceManager.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useAudioDeviceManager.d.ts","sourceRoot":"","sources":["../../../src/hooks/deviceManagers/useAudioDeviceManager.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,qBAAqB,gDAKjC,CAAC"}
@@ -1,7 +0,0 @@
1
- import { useFishjamContext } from "../useFishjamContext";
2
- import { useDeviceManager } from "./useDeviceManager";
3
- export const useAudioDeviceManager = () => {
4
- const { audioDeviceManagerRef } = useFishjamContext();
5
- const audioDeviceState = useDeviceManager(audioDeviceManagerRef.current);
6
- return audioDeviceState;
7
- };
@@ -1,2 +0,0 @@
1
- export declare const useVideoDeviceManager: () => import("../../types").DeviceManagerState;
2
- //# sourceMappingURL=useVideoDeviceManager.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useVideoDeviceManager.d.ts","sourceRoot":"","sources":["../../../src/hooks/deviceManagers/useVideoDeviceManager.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,qBAAqB,gDAKjC,CAAC"}
@@ -1,7 +0,0 @@
1
- import { useFishjamContext } from "../useFishjamContext";
2
- import { useDeviceManager } from "./useDeviceManager";
3
- export const useVideoDeviceManager = () => {
4
- const { videoDeviceManagerRef } = useFishjamContext();
5
- const videoDeviceState = useDeviceManager(videoDeviceManagerRef.current);
6
- return videoDeviceState;
7
- };
@@ -1 +0,0 @@
1
- {"version":3,"file":"useDevices.d.ts","sourceRoot":"","sources":["../../src/hooks/useDevices.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAQpD,wBAAgB,SAAS,IAAI,MAAM,CAuBlC;AAED,wBAAgB,aAAa,IAAI,WAAW,CA0B3C;AAED,eAAO,MAAM,oBAAoB;;CAqDhC,CAAC"}
@@ -1,8 +0,0 @@
1
- import type { ParticipantStatus } from "../state.types";
2
- import type { FishjamClient } from "@fishjam-cloud/ts-client";
3
- import type { PeerMetadata, TrackMetadata } from "../types";
4
- export declare const useParticipantStatus: (client: FishjamClient<PeerMetadata, TrackMetadata>) => {
5
- readonly peerStatus: ParticipantStatus;
6
- readonly getCurrentParticipantStatus: () => ParticipantStatus;
7
- };
8
- //# sourceMappingURL=useParticipantStatus.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useParticipantStatus.d.ts","sourceRoot":"","sources":["../../src/hooks/useParticipantStatus.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAE5D,eAAO,MAAM,oBAAoB,WAAY,aAAa,CAAC,YAAY,EAAE,aAAa,CAAC;;;CA8CtF,CAAC"}
@@ -1,6 +0,0 @@
1
- import type { PeerStateWithTracks } from "../types";
2
- export declare function useParticipants(): {
3
- localParticipant: PeerStateWithTracks | null;
4
- participants: PeerStateWithTracks[];
5
- };
6
- //# sourceMappingURL=useParticipants.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useParticipants.d.ts","sourceRoot":"","sources":["../../src/hooks/useParticipants.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAcpD,wBAAgB,eAAe;;;EAQ9B"}
@@ -1,3 +0,0 @@
1
- import type { TrackManager } from "../types";
2
- export declare function useProcessedPreviewStream(trackManager: TrackManager, deviceTrack: MediaStreamTrack | null | undefined): MediaStream | null;
3
- //# sourceMappingURL=useProcessedPreviewStream.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useProcessedPreviewStream.d.ts","sourceRoot":"","sources":["../../src/hooks/useProcessedPreviewStream.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAE7C,wBAAgB,yBAAyB,CACvC,YAAY,EAAE,YAAY,EAC1B,WAAW,EAAE,gBAAgB,GAAG,IAAI,GAAG,SAAS,sBAiBjD"}
@@ -1,17 +0,0 @@
1
- import { useEffect, useState } from "react";
2
- export function useProcessedPreviewStream(trackManager, deviceTrack) {
3
- const [previewStream, setPreviewStream] = useState(null);
4
- const { currentTrack, currentTrackMiddleware } = trackManager;
5
- useEffect(() => {
6
- if (currentTrack || !deviceTrack)
7
- return;
8
- const result = currentTrackMiddleware?.(deviceTrack);
9
- if (result?.track)
10
- setPreviewStream(new MediaStream([result.track]));
11
- return () => {
12
- result?.onClear?.();
13
- setPreviewStream(null);
14
- };
15
- }, [currentTrack, deviceTrack, currentTrackMiddleware]);
16
- return previewStream;
17
- }
@@ -1,42 +0,0 @@
1
- import type { Encoding, VadStatus, SimulcastConfig } from "@fishjam-cloud/ts-client";
2
- import type { PeerMetadata, TrackMetadata } from "./types";
3
- export type TrackId = string;
4
- export type PeerId = string;
5
- export type Track = {
6
- stream: MediaStream | null;
7
- encoding: Encoding | null;
8
- trackId: TrackId;
9
- metadata?: TrackMetadata;
10
- rawMetadata: Record<string, unknown>;
11
- metadataParsingError?: any;
12
- simulcastConfig: SimulcastConfig | null;
13
- vadStatus: VadStatus;
14
- track: MediaStreamTrack | null;
15
- };
16
- export interface Origin {
17
- id: string;
18
- type: string;
19
- metadata?: PeerMetadata;
20
- rawMetadata: Record<string, unknown>;
21
- metadataParsingError?: any;
22
- }
23
- export type TrackWithOrigin = Track & {
24
- origin: Origin;
25
- };
26
- export type PeerState = {
27
- id: PeerId;
28
- metadata?: PeerMetadata;
29
- rawMetadata: Record<string, unknown>;
30
- metadataParsingError?: any;
31
- tracks: Record<TrackId, Track>;
32
- };
33
- /**
34
- * Represents the possible statuses of a peer connection.
35
- *
36
- * idle - Participant is not connected, either never connected or successfully disconnected.
37
- * connecting - Participant is in the process of connecting.
38
- * connected - Participant has successfully connected.
39
- * error - There was an error in the connection process.
40
- */
41
- export type ParticipantStatus = "connecting" | "connected" | "error" | "idle";
42
- //# sourceMappingURL=state.types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"state.types.d.ts","sourceRoot":"","sources":["../src/state.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AACrF,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE3D,MAAM,MAAM,OAAO,GAAG,MAAM,CAAC;AAC7B,MAAM,MAAM,MAAM,GAAG,MAAM,CAAC;AAE5B,MAAM,MAAM,KAAK,GAAG;IAClB,MAAM,EAAE,WAAW,GAAG,IAAI,CAAC;IAC3B,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAAC;IAC1B,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,CAAC,EAAE,aAAa,CAAC;IACzB,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrC,oBAAoB,CAAC,EAAE,GAAG,CAAC;IAC3B,eAAe,EAAE,eAAe,GAAG,IAAI,CAAC;IACxC,SAAS,EAAE,SAAS,CAAC;IACrB,KAAK,EAAE,gBAAgB,GAAG,IAAI,CAAC;CAChC,CAAC;AAEF,MAAM,WAAW,MAAM;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,YAAY,CAAC;IACxB,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrC,oBAAoB,CAAC,EAAE,GAAG,CAAC;CAC5B;AAED,MAAM,MAAM,eAAe,GAAG,KAAK,GAAG;IACpC,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,CAAC,EAAE,YAAY,CAAC;IACxB,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrC,oBAAoB,CAAC,EAAE,GAAG,CAAC;IAC3B,MAAM,EAAE,MAAM,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;CAChC,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,MAAM,iBAAiB,GAAG,YAAY,GAAG,WAAW,GAAG,OAAO,GAAG,MAAM,CAAC"}
package/dist/types.d.ts DELETED
@@ -1,255 +0,0 @@
1
- import type { ConnectConfig as TSClientConnectConfig, SimulcastConfig, TrackBandwidthLimit, TrackKind } from "@fishjam-cloud/ts-client";
2
- import type { PeerState, Track, TrackId } from "./state.types";
3
- export type PeerMetadata = {
4
- displayName?: string;
5
- };
6
- export type TrackMetadata = {
7
- type: "camera" | "microphone" | "screenShareVideo" | "screenShareAudio";
8
- paused: boolean;
9
- displayName?: string;
10
- };
11
- export type DevicesStatus = "OK" | "Error" | "Not requested" | "Requesting";
12
- export type MediaStatus = "OK" | "Error" | "Not requested" | "Requesting";
13
- export type DeviceManagerStatus = "uninitialized" | "initializing" | "initialized" | "error";
14
- export interface DeviceManagerState {
15
- deviceState: DeviceState;
16
- status: DeviceManagerStatus;
17
- tracks: MediaStreamTrack[];
18
- }
19
- export type Media = {
20
- stream: MediaStream | null;
21
- track: MediaStreamTrack | null;
22
- enabled: boolean;
23
- deviceInfo: MediaDeviceInfo | null;
24
- };
25
- export type DeviceState = {
26
- media: Media | null;
27
- mediaStatus: MediaStatus;
28
- devices: MediaDeviceInfo[] | null;
29
- devicesStatus: DevicesStatus;
30
- error: DeviceError | null;
31
- };
32
- export type MediaState = {
33
- video: DeviceState;
34
- audio: DeviceState;
35
- };
36
- export type DeviceManagerInitConfig = {
37
- videoTrackConstraints?: boolean | MediaTrackConstraints;
38
- audioTrackConstraints?: boolean | MediaTrackConstraints;
39
- };
40
- export type DeviceManagerConfig = {
41
- trackConstraints?: boolean | MediaTrackConstraints;
42
- startOnMount?: boolean;
43
- storage?: boolean | StorageConfig;
44
- };
45
- export type StorageConfig = {
46
- getLastDevice: (() => MediaDeviceInfo | null) | null;
47
- saveLastDevice: (info: MediaDeviceInfo) => void;
48
- };
49
- export type DeviceManagerStartConfig = {
50
- audioDeviceId?: string | boolean;
51
- videoDeviceId?: string | boolean;
52
- };
53
- export type DeviceError = {
54
- name: "OverconstrainedError";
55
- } | {
56
- name: "NotAllowedError";
57
- } | {
58
- name: "NotFoundError";
59
- } | {
60
- name: "UNHANDLED_ERROR";
61
- };
62
- export type CurrentDevices = {
63
- videoinput: MediaDeviceInfo | null;
64
- audioinput: MediaDeviceInfo | null;
65
- };
66
- export type UseSetupMediaConfig = {
67
- camera: {
68
- /**
69
- * Determines whether broadcasting should start when the user connects to the server with an active camera stream.
70
- */
71
- broadcastOnConnect?: boolean;
72
- /**
73
- * Determines whether broadcasting should start when the user initiates the camera and is connected to the server.
74
- */
75
- broadcastOnDeviceStart?: boolean;
76
- /**
77
- * Determines whether track should be replaced when the user requests a device.
78
- * default: replace
79
- */
80
- onDeviceChange?: "replace" | "remove";
81
- /**
82
- * Determines whether currently broadcasted track should be removed or muted
83
- * when the user stopped a device.
84
- * default: replace
85
- */
86
- onDeviceStop?: "remove" | "mute";
87
- trackConstraints: boolean | MediaTrackConstraints;
88
- defaultSimulcastConfig?: SimulcastConfig;
89
- defaultMaxBandwidth?: TrackBandwidthLimit;
90
- };
91
- microphone: {
92
- /**
93
- * Determines whether broadcasting should start when the user connects to the server with an active camera stream.
94
- */
95
- broadcastOnConnect?: boolean;
96
- /**
97
- * Determines whether broadcasting should start when the user initiates the camera and is connected to the server.
98
- */
99
- broadcastOnDeviceStart?: boolean;
100
- /**
101
- * Determines whether currently broadcasted track should be replaced or stopped
102
- * when the user changed a device.
103
- * default: replace
104
- */
105
- onDeviceChange?: "replace" | "remove";
106
- /**
107
- * Determines whether currently broadcasted track should be removed or muted
108
- * when the user stopped a device.
109
- * default: replace
110
- */
111
- onDeviceStop?: "remove" | "mute";
112
- trackConstraints: boolean | MediaTrackConstraints;
113
- defaultMaxBandwidth?: TrackBandwidthLimit;
114
- };
115
- screenShare: {
116
- /**
117
- * Determines whether broadcasting should start when the user connects to the server with an active camera stream.
118
- */
119
- broadcastOnConnect?: boolean;
120
- /**
121
- * Determines whether broadcasting should start when the user initiates the camera and is connected to the server.
122
- */
123
- broadcastOnDeviceStart?: boolean;
124
- defaultMaxBandwidth?: TrackBandwidthLimit;
125
- };
126
- startOnMount?: boolean;
127
- storage?: boolean | StorageConfig;
128
- };
129
- export type UseSetupMediaResult = {
130
- init: () => void;
131
- };
132
- export interface MediaManager {
133
- start: (deviceId?: string) => Promise<void>;
134
- stop: () => Promise<void>;
135
- disable: () => void;
136
- enable: () => void;
137
- getTracks: () => MediaStreamTrack[];
138
- getMedia: () => {
139
- stream: MediaStream | null;
140
- track: MediaStreamTrack | null;
141
- enabled: boolean;
142
- } | null;
143
- getDeviceType: () => "audio" | "video";
144
- }
145
- export type TrackMiddleware = ((track: MediaStreamTrack | null) => {
146
- track: MediaStreamTrack | null;
147
- onClear?: () => void;
148
- }) | null;
149
- export type ScreenShareState = ({
150
- stream: MediaStream;
151
- trackIds: {
152
- videoId: string;
153
- audioId?: string;
154
- };
155
- } | {
156
- stream: null;
157
- trackIds: null;
158
- }) & {
159
- tracksMiddleware?: TracksMiddleware | null;
160
- };
161
- export type Device = {
162
- isStreaming: boolean;
163
- trackId: TrackId | null;
164
- track: MediaStreamTrack | null;
165
- stream: MediaStream | null;
166
- devices: MediaDeviceInfo[];
167
- activeDevice: MediaDeviceInfo | null;
168
- } & Omit<TrackManager, "currentTrack">;
169
- export type AudioDevice = Device & {
170
- isAudioPlaying: boolean;
171
- };
172
- export type ToggleMode = "soft" | "hard";
173
- export interface TrackManager {
174
- initialize: (deviceId?: string) => Promise<void>;
175
- stop: () => Promise<void>;
176
- startStreaming: (simulcastConfig?: SimulcastConfig, maxBandwidth?: TrackBandwidthLimit) => Promise<string>;
177
- stopStreaming: () => Promise<void>;
178
- pauseStreaming: () => Promise<void>;
179
- resumeStreaming: () => Promise<void>;
180
- paused: boolean;
181
- disableTrack: () => void;
182
- enableTrack: () => void;
183
- setTrackMiddleware: (middleware: TrackMiddleware) => Promise<void>;
184
- currentTrackMiddleware: TrackMiddleware;
185
- refreshStreamedTrack: () => Promise<void>;
186
- currentTrack: Track | null;
187
- /**
188
- * Toggles the media stream state based on the provided mode.
189
- * Either initiates or terminates the device or enables or disables the stream.
190
- *
191
- * @param {ToggleMode} [mode] - The toggle mode, either "hard" or "soft". Defaults to "hard".
192
- *
193
- * - **Hard Mode** - Turns the physical device on and off.
194
- * - If started: disables the media stream, pauses streaming, and stops the device.
195
- * - If stopped: starts the device and begins (or resumes) streaming.
196
- *
197
- * - **Soft Mode** - Enables and disables the media stream. Starts the device if needed.
198
- * - If enabled: disables the media stream and pauses streaming, but does not stop the device.
199
- * - If disabled: enables the media stream and starts (or resumes) streaming.
200
- * - If stopped: starts the device, enables the media stream, and starts (or resumes) streaming.
201
- */
202
- toggle: (mode?: ToggleMode) => Promise<void>;
203
- }
204
- export type UserMediaAPI = {
205
- status: DevicesStatus | null;
206
- stream: MediaStream | null;
207
- track: MediaStreamTrack | null;
208
- enabled: boolean;
209
- mediaStatus: MediaStatus | null;
210
- deviceInfo: MediaDeviceInfo | null;
211
- error: DeviceError | null;
212
- devices: MediaDeviceInfo[] | null;
213
- };
214
- export type ScreenshareApi = {
215
- startStreaming: (props?: {
216
- audioConstraints?: boolean | MediaTrackConstraints;
217
- videoConstraints?: boolean | MediaTrackConstraints;
218
- }) => Promise<void>;
219
- stopStreaming: () => Promise<void>;
220
- stream: MediaStream | null;
221
- videoTrack: MediaStreamTrack | null;
222
- audioTrack: MediaStreamTrack | null;
223
- videoBroadcast: Track | null;
224
- audioBroadcast: Track | null;
225
- setTracksMiddleware: (middleware: TracksMiddleware | null) => Promise<void>;
226
- currentTracksMiddleware: TracksMiddleware | null;
227
- };
228
- export type Devices = {
229
- camera: UserMediaAPI;
230
- microphone: UserMediaAPI;
231
- };
232
- export type TracksMiddleware = (videoTrack: MediaStreamTrack, audioTrack: MediaStreamTrack | null) => {
233
- videoTrack: MediaStreamTrack;
234
- audioTrack: MediaStreamTrack | null;
235
- onClear: () => void;
236
- };
237
- export type ConnectConfig = Omit<TSClientConnectConfig<PeerMetadata>, "peerMetadata"> & {
238
- peerMetadata?: PeerMetadata;
239
- };
240
- export type UseConnect = (config: ConnectConfig) => Promise<void>;
241
- type DistinguishedTracks = {
242
- cameraTrack?: Track;
243
- microphoneTrack?: Track;
244
- screenShareVideoTrack?: Track;
245
- screenShareAudioTrack?: Track;
246
- };
247
- export type PeerStateWithTracks = PeerState & DistinguishedTracks;
248
- export type Participiants = {
249
- localParticipant: PeerStateWithTracks | null;
250
- participants: PeerStateWithTracks[];
251
- };
252
- export type TrackType = TrackKind | "audiovideo";
253
- export type MediaDeviceType = "displayMedia" | "userMedia";
254
- export {};
255
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],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E,aAAa,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAElE,KAAK,mBAAmB,GAAG;IACzB,WAAW,CAAC,EAAE,KAAK,CAAC;IACpB,eAAe,CAAC,EAAE,KAAK,CAAC;IACxB,qBAAqB,CAAC,EAAE,KAAK,CAAC;IAC9B,qBAAqB,CAAC,EAAE,KAAK,CAAC;CAC/B,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG,SAAS,GAAG,mBAAmB,CAAC;AAElE,MAAM,MAAM,aAAa,GAAG;IAC1B,gBAAgB,EAAE,mBAAmB,GAAG,IAAI,CAAC;IAC7C,YAAY,EAAE,mBAAmB,EAAE,CAAC;CACrC,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG,SAAS,GAAG,YAAY,CAAC;AACjD,MAAM,MAAM,eAAe,GAAG,cAAc,GAAG,WAAW,CAAC"}
@@ -1,12 +0,0 @@
1
- import type { CurrentDevices, DeviceError, DeviceState, StorageConfig } from "../types";
2
- export declare const removeSpecifiedDeviceFromConstraints: (trackConstraints?: boolean | MediaTrackConstraints) => boolean | MediaTrackConstraints | undefined;
3
- export declare const REQUESTING = "Requesting";
4
- export declare const NOT_REQUESTED = "Not requested";
5
- export declare const getDeviceInfo: (trackDeviceId: string | null, devices: MediaDeviceInfo[]) => MediaDeviceInfo | null;
6
- export declare const getCurrentDevicesSettings: (requestedDevices: MediaStream, mediaDeviceInfos: MediaDeviceInfo[]) => CurrentDevices;
7
- export declare const isDeviceDifferentFromLastSession: (lastDevice: MediaDeviceInfo | null, currentDevice: MediaDeviceInfo | null) => boolean | null;
8
- export declare const isAnyDeviceDifferentFromLastSession: (lastVideoDevice: MediaDeviceInfo | null, lastAudioDevice: MediaDeviceInfo | null, currentDevices: CurrentDevices | null) => boolean;
9
- export declare const stopTracks: (requestedDevices: MediaStream) => void;
10
- export declare const prepareDeviceState: (stream: MediaStream | null, track: MediaStreamTrack | null, devices: MediaDeviceInfo[], error: DeviceError | null, shouldAsk: boolean) => DeviceState;
11
- export declare const getLocalStorageConfig: (deviceType: "audio" | "video") => StorageConfig;
12
- //# sourceMappingURL=media.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"media.d.ts","sourceRoot":"","sources":["../../src/utils/media.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAiB,WAAW,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAIvG,eAAO,MAAM,oCAAoC,sBAC5B,OAAO,GAAG,qBAAqB,KACjD,OAAO,GAAG,qBAAqB,GAAG,SAKpC,CAAC;AAEF,eAAO,MAAM,UAAU,eAAe,CAAC;AACvC,eAAO,MAAM,aAAa,kBAAkB,CAAC;AAE7C,eAAO,MAAM,aAAa,kBAAmB,MAAM,GAAG,IAAI,WAAW,eAAe,EAAE,KAAG,eAAe,GAAG,IACpB,CAAC;AAExF,eAAO,MAAM,yBAAyB,qBAClB,WAAW,oBACX,eAAe,EAAE,KAClC,cAcF,CAAC;AAEF,eAAO,MAAM,gCAAgC,eAC/B,eAAe,GAAG,IAAI,iBACnB,eAAe,GAAG,IAAI,mBAC2E,CAAC;AAEnH,eAAO,MAAM,mCAAmC,oBAC7B,eAAe,GAAG,IAAI,mBACtB,eAAe,GAAG,IAAI,kBACvB,cAAc,GAAG,IAAI,KACpC,OAMA,CAAC;AAEJ,eAAO,MAAM,UAAU,qBAAsB,WAAW,SAIvD,CAAC;AAQF,eAAO,MAAM,kBAAkB,WACrB,WAAW,GAAG,IAAI,SACnB,gBAAgB,GAAG,IAAI,WACrB,eAAe,EAAE,SACnB,WAAW,GAAG,IAAI,aACd,OAAO,KACjB,WAgBF,CAAC;AAEF,eAAO,MAAM,qBAAqB,eAAgB,OAAO,GAAG,OAAO,KAAG,aAMrE,CAAC"}
@@ -1,64 +0,0 @@
1
- import { loadObject, saveObject } from "./localStorage";
2
- export const removeSpecifiedDeviceFromConstraints = (trackConstraints) => {
3
- if (typeof trackConstraints === "object") {
4
- return { ...trackConstraints, deviceId: undefined };
5
- }
6
- return trackConstraints;
7
- };
8
- export const REQUESTING = "Requesting";
9
- export const NOT_REQUESTED = "Not requested";
10
- export const getDeviceInfo = (trackDeviceId, devices) => (trackDeviceId && devices.find(({ deviceId }) => trackDeviceId === deviceId)) || null;
11
- export const getCurrentDevicesSettings = (requestedDevices, mediaDeviceInfos) => {
12
- const currentDevices = { videoinput: null, audioinput: null };
13
- for (const track of requestedDevices.getTracks()) {
14
- const settings = track.getSettings();
15
- if (settings.deviceId) {
16
- const currentDevice = mediaDeviceInfos.find((device) => device.deviceId == settings.deviceId);
17
- const kind = currentDevice?.kind ?? null;
18
- if ((currentDevice && kind === "videoinput") || kind === "audioinput") {
19
- currentDevices[kind] = currentDevice ?? null;
20
- }
21
- }
22
- }
23
- return currentDevices;
24
- };
25
- export const isDeviceDifferentFromLastSession = (lastDevice, currentDevice) => lastDevice && (currentDevice?.deviceId !== lastDevice.deviceId || currentDevice?.label !== lastDevice?.label);
26
- export const isAnyDeviceDifferentFromLastSession = (lastVideoDevice, lastAudioDevice, currentDevices) => !!((currentDevices?.videoinput &&
27
- isDeviceDifferentFromLastSession(lastVideoDevice, currentDevices?.videoinput || null)) ||
28
- (currentDevices?.audioinput &&
29
- isDeviceDifferentFromLastSession(lastAudioDevice, currentDevices?.audioinput || null)));
30
- export const stopTracks = (requestedDevices) => {
31
- for (const track of requestedDevices.getTracks()) {
32
- track.stop();
33
- }
34
- };
35
- const prepareStatus = (requested, track) => {
36
- if (!requested)
37
- return ["Not requested", null];
38
- if (track)
39
- return ["OK", null];
40
- return ["Error", null];
41
- };
42
- export const prepareDeviceState = (stream, track, devices, error, shouldAsk) => {
43
- const deviceInfo = getDeviceInfo(track?.getSettings()?.deviceId || null, devices);
44
- const [devicesStatus, newError] = prepareStatus(shouldAsk, track);
45
- return {
46
- devices,
47
- devicesStatus,
48
- media: {
49
- stream: track ? stream : null,
50
- track: track,
51
- deviceInfo,
52
- enabled: !!track,
53
- },
54
- mediaStatus: devicesStatus,
55
- error: newError ?? error,
56
- };
57
- };
58
- export const getLocalStorageConfig = (deviceType) => {
59
- const key = `last-selected-${deviceType}-device`;
60
- return {
61
- getLastDevice: () => loadObject(key, null),
62
- saveLastDevice: (info) => saveObject(key, info),
63
- };
64
- };
File without changes
File without changes