@fishjam-cloud/react-client 0.20.0 → 0.23.0
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.
- package/dist/FishjamProvider.d.ts +4 -1
- package/dist/FishjamProvider.d.ts.map +1 -1
- package/dist/FishjamProvider.js +1 -1
- package/dist/contexts/fishjamId.d.ts +1 -0
- package/dist/contexts/fishjamId.d.ts.map +1 -1
- package/dist/contexts/fishjamId.js +8 -1
- package/dist/hooks/useConnection.d.ts +1 -5
- package/dist/hooks/useConnection.d.ts.map +1 -1
- package/dist/hooks/useConnection.js +7 -7
- package/dist/hooks/useSandbox.d.ts +1 -1
- package/dist/hooks/useSandbox.d.ts.map +1 -1
- package/dist/hooks/useSandbox.js +8 -22
- package/dist/utils/fishjamUrl.d.ts +3 -0
- package/dist/utils/fishjamUrl.d.ts.map +1 -0
- package/dist/utils/fishjamUrl.js +11 -0
- package/package.json +2 -2
|
@@ -33,7 +33,10 @@ export interface FishjamProviderProps extends PropsWithChildren {
|
|
|
33
33
|
* Configure whether to use audio simulcast and which layers to send if so.
|
|
34
34
|
*/
|
|
35
35
|
audioConfig?: StreamConfig;
|
|
36
|
-
|
|
36
|
+
/**
|
|
37
|
+
* You can get you Fishjam ID at https://fishjam.io/app
|
|
38
|
+
*/
|
|
39
|
+
fishjamId: string;
|
|
37
40
|
}
|
|
38
41
|
/**
|
|
39
42
|
* Provides the Fishjam Context
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FishjamProvider.d.ts","sourceRoot":"","sources":["../src/FishjamProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC/E,OAAO,EAAE,KAAK,iBAAiB,EAAmB,MAAM,OAAO,CAAC;AAkBhE,OAAO,KAAK,EAAE,eAAe,EAAE,yBAAyB,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAI/F;;GAEG;AACH,MAAM,WAA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e,CAAC,KAAK,EAAE,oBAAoB,2CAiF1D"}
|
package/dist/FishjamProvider.js
CHANGED
|
@@ -66,5 +66,5 @@ export function FishjamProvider(props) {
|
|
|
66
66
|
peerStatus,
|
|
67
67
|
});
|
|
68
68
|
const fishjamClientState = useFishjamClientState(fishjamClientRef.current);
|
|
69
|
-
return (_jsx(FishjamClientContext.Provider, { value: fishjamClientRef, children: _jsx(FishjamClientStateContext.Provider, { value: fishjamClientState, children: _jsx(FishjamIdContext.Provider, { value: props.fishjamId
|
|
69
|
+
return (_jsx(FishjamClientContext.Provider, { value: fishjamClientRef, children: _jsx(FishjamClientStateContext.Provider, { value: fishjamClientState, children: _jsx(FishjamIdContext.Provider, { value: props.fishjamId, children: _jsx(InitDevicesContext.Provider, { value: initializeDevices, children: _jsx(PeerStatusContext.Provider, { value: peerStatus, children: _jsx(CameraContext.Provider, { value: cameraContext, children: _jsx(MicrophoneContext.Provider, { value: microphoneContext, children: _jsx(ScreenshareContext.Provider, { value: screenShareManager, children: _jsx(CustomSourceContext.Provider, { value: customSourceManager, children: props.children }) }) }) }) }) }) }) }) }));
|
|
70
70
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fishjamId.d.ts","sourceRoot":"","sources":["../../src/contexts/fishjamId.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,gBAAgB,wCAAqC,CAAC"}
|
|
1
|
+
{"version":3,"file":"fishjamId.d.ts","sourceRoot":"","sources":["../../src/contexts/fishjamId.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,gBAAgB,wCAAqC,CAAC;AAEnE,eAAO,MAAM,YAAY,cAQxB,CAAC"}
|
|
@@ -1,2 +1,9 @@
|
|
|
1
|
-
import { createContext } from "react";
|
|
1
|
+
import { createContext, useContext } from "react";
|
|
2
2
|
export const FishjamIdContext = createContext(null);
|
|
3
|
+
export const useFishjamId = () => {
|
|
4
|
+
const fishjamId = useContext(FishjamIdContext);
|
|
5
|
+
if (!fishjamId) {
|
|
6
|
+
console.error(`You haven't passed your Fishjam ID to the FishjamProvider. You can get your Fishjam ID at https://fishjam.io/app`);
|
|
7
|
+
}
|
|
8
|
+
return fishjamId ?? "";
|
|
9
|
+
};
|
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
import type { GenericMetadata } from "@fishjam-cloud/ts-client";
|
|
2
2
|
export interface JoinRoomConfig<PeerMetadata extends GenericMetadata = GenericMetadata> {
|
|
3
|
-
/**
|
|
4
|
-
* Overrides the default url derived from the Fishjam ID passed to FishjamProvider
|
|
5
|
-
*/
|
|
6
|
-
url?: string;
|
|
7
3
|
/**
|
|
8
4
|
* Token received from server (or Room Manager)
|
|
9
5
|
*/
|
|
@@ -22,7 +18,7 @@ export declare function useConnection(): {
|
|
|
22
18
|
/**
|
|
23
19
|
* Join room and start streaming camera and microphone
|
|
24
20
|
*/
|
|
25
|
-
joinRoom: <PeerMetadata extends GenericMetadata = GenericMetadata>({
|
|
21
|
+
joinRoom: <PeerMetadata extends GenericMetadata = GenericMetadata>({ peerToken, peerMetadata, }: JoinRoomConfig<PeerMetadata>) => Promise<void>;
|
|
26
22
|
/**
|
|
27
23
|
* Leave room and stop streaming
|
|
28
24
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useConnection.d.ts","sourceRoot":"","sources":["../../src/hooks/useConnection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAShE,MAAM,WAAW,cAAc,CAAC,YAAY,SAAS,eAAe,GAAG,eAAe;IACpF;;OAEG;IACH,
|
|
1
|
+
{"version":3,"file":"useConnection.d.ts","sourceRoot":"","sources":["../../src/hooks/useConnection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAShE,MAAM,WAAW,cAAc,CAAC,YAAY,SAAS,eAAe,GAAG,eAAe;IACpF;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,YAAY,CAAC,EAAE,YAAY,CAAC;CAC7B;AAED;;;;GAIG;AACH,wBAAgB,aAAa;IAgCzB;;OAEG;eAtBF,YAAY,SAAS,eAAe,kDAGlC,cAAc,CAAC,YAAY,CAAC;IAqB/B;;OAEG;;IAEH;;OAEG;;IAEH;;OAEG;;EAGN"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { useCallback, useContext } from "react";
|
|
2
|
-
import { FISHJAM_WS_CONNECT_URL } from "../consts";
|
|
3
2
|
import { FishjamClientContext } from "../contexts/fishjamClient";
|
|
4
|
-
import {
|
|
3
|
+
import { useFishjamId } from "../contexts/fishjamId";
|
|
5
4
|
import { PeerStatusContext } from "../contexts/peerStatus";
|
|
5
|
+
import { httpToWebsocketUrl, resolveFishjamUrl } from "../utils/fishjamUrl";
|
|
6
6
|
import { useReconnection } from "./internal/useReconnection";
|
|
7
7
|
/**
|
|
8
8
|
* Hook allows to join or leave a room and check the current connection status.
|
|
@@ -11,18 +11,18 @@ import { useReconnection } from "./internal/useReconnection";
|
|
|
11
11
|
*/
|
|
12
12
|
export function useConnection() {
|
|
13
13
|
const fishjamClientRef = useContext(FishjamClientContext);
|
|
14
|
-
const fishjamId =
|
|
14
|
+
const fishjamId = useFishjamId();
|
|
15
15
|
if (!fishjamClientRef)
|
|
16
16
|
throw Error("useConnection must be used within FishjamProvider");
|
|
17
17
|
const peerStatus = useContext(PeerStatusContext);
|
|
18
18
|
const client = fishjamClientRef.current;
|
|
19
19
|
const reconnectionStatus = useReconnection();
|
|
20
|
-
const joinRoom = useCallback(({
|
|
21
|
-
if (!
|
|
20
|
+
const joinRoom = useCallback(({ peerToken, peerMetadata, }) => {
|
|
21
|
+
if (!fishjamId) {
|
|
22
22
|
throw Error(`You haven't passed your Fishjam ID to the FishjamProvider. You can get your Fishjam ID at https://fishjam.io/app`);
|
|
23
23
|
}
|
|
24
|
-
const connectUrl =
|
|
25
|
-
return client.connect({ url:
|
|
24
|
+
const connectUrl = httpToWebsocketUrl(resolveFishjamUrl(fishjamId));
|
|
25
|
+
return client.connect({ url: connectUrl, token: peerToken, peerMetadata: peerMetadata ?? {} });
|
|
26
26
|
}, [client, fishjamId]);
|
|
27
27
|
const leaveRoom = useCallback(() => {
|
|
28
28
|
client.disconnect();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSandbox.d.ts","sourceRoot":"","sources":["../../src/hooks/useSandbox.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useSandbox.d.ts","sourceRoot":"","sources":["../../src/hooks/useSandbox.ts"],"names":[],"mappings":"AAWA,MAAM,MAAM,eAAe,GAAG;IAE5B,cAAc,CAAC,EAAE;QAAE,aAAa,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CAC7C,CAAC;AAEF,MAAM,MAAM,QAAQ,GAAG,YAAY,GAAG,YAAY,GAAG,YAAY,CAAC;AAElE,eAAO,MAAM,UAAU,GAAI,QAAQ,eAAe;oCAOH,MAAM,YAAY,MAAM,aAAY,QAAQ;sCAiB1C,MAAM;qCAgBP,MAAM,aAAY,OAAO;uBAQxC,MAAM;cAAQ;YAAE,EAAE,EAAE,MAAM,CAAC;YAAC,IAAI,EAAE,MAAM,CAAA;SAAE;;CAK1E,CAAC"}
|
package/dist/hooks/useSandbox.js
CHANGED
|
@@ -1,21 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { FishjamIdContext } from "../contexts/fishjamId";
|
|
4
|
-
class FishjamIdMisconfiguredError extends Error {
|
|
5
|
-
constructor() {
|
|
6
|
-
super("You haven't passed the fishjamId to the FishjamProvider.");
|
|
7
|
-
}
|
|
8
|
-
}
|
|
1
|
+
import { useFishjamId } from "../contexts/fishjamId";
|
|
2
|
+
import { resolveFishjamUrl } from "../utils/fishjamUrl";
|
|
9
3
|
export const useSandbox = (props) => {
|
|
10
|
-
const fishjamId =
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const isFishjamIdMisconfigured = !fishjamId && !props?.configOverride?.fishjamUrl;
|
|
14
|
-
const roomManagerUrl = `${overridenFishjamUrl ?? fishjamUrl}/room-manager`;
|
|
4
|
+
const fishjamId = useFishjamId();
|
|
5
|
+
const fishjamUrl = resolveFishjamUrl(fishjamId);
|
|
6
|
+
const sandboxApiUrl = props?.configOverride?.sandboxApiUrl ?? `${fishjamUrl}/room-manager`;
|
|
15
7
|
const getSandboxPeerToken = async (roomName, peerName, roomType = "conference") => {
|
|
16
|
-
|
|
17
|
-
throw new FishjamIdMisconfiguredError();
|
|
18
|
-
const url = new URL(roomManagerUrl);
|
|
8
|
+
const url = new URL(sandboxApiUrl);
|
|
19
9
|
url.searchParams.set("roomName", roomName);
|
|
20
10
|
url.searchParams.set("peerName", peerName);
|
|
21
11
|
url.searchParams.set("roomType", roomType);
|
|
@@ -28,9 +18,7 @@ export const useSandbox = (props) => {
|
|
|
28
18
|
return data.peerToken;
|
|
29
19
|
};
|
|
30
20
|
const getSandboxViewerToken = async (roomName) => {
|
|
31
|
-
|
|
32
|
-
throw new FishjamIdMisconfiguredError();
|
|
33
|
-
const url = new URL(`${roomManagerUrl}/${roomName}/livestream-viewer-token`);
|
|
21
|
+
const url = new URL(`${sandboxApiUrl}/${roomName}/livestream-viewer-token`);
|
|
34
22
|
const res = await fetch(url);
|
|
35
23
|
if (!res.ok) {
|
|
36
24
|
let message = `Failed to retrieve viewer token for '${roomName}' livestream room.`;
|
|
@@ -43,9 +31,7 @@ export const useSandbox = (props) => {
|
|
|
43
31
|
return data.token;
|
|
44
32
|
};
|
|
45
33
|
const getSandboxLivestream = async (roomName, isPublic = false) => {
|
|
46
|
-
|
|
47
|
-
throw new FishjamIdMisconfiguredError();
|
|
48
|
-
const url = new URL(`${roomManagerUrl}/livestream`);
|
|
34
|
+
const url = new URL(`${sandboxApiUrl}/livestream`);
|
|
49
35
|
url.searchParams.set("roomName", roomName);
|
|
50
36
|
url.searchParams.set("public", isPublic.toString());
|
|
51
37
|
const res = await fetch(url);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fishjamUrl.d.ts","sourceRoot":"","sources":["../../src/utils/fishjamUrl.ts"],"names":[],"mappings":"AAAA,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAM3D;AAED,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEtD"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export function resolveFishjamUrl(fishjamId) {
|
|
2
|
+
try {
|
|
3
|
+
return new URL(fishjamId).href;
|
|
4
|
+
}
|
|
5
|
+
catch {
|
|
6
|
+
return `https://fishjam.io/api/v1/connect/${fishjamId}`;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
export function httpToWebsocketUrl(url) {
|
|
10
|
+
return url.replace("https://", "wss://").replace("http://", "ws://");
|
|
11
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fishjam-cloud/react-client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.23.0",
|
|
4
4
|
"description": "React client library for Fishjam",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Fishjam Team",
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"vitest": "^3.1.1"
|
|
61
61
|
},
|
|
62
62
|
"dependencies": {
|
|
63
|
-
"@fishjam-cloud/ts-client": "0.
|
|
63
|
+
"@fishjam-cloud/ts-client": "0.23.0",
|
|
64
64
|
"events": "3.3.0",
|
|
65
65
|
"lodash.isequal": "4.5.0"
|
|
66
66
|
},
|