@fishjam-cloud/react-client 0.20.0 → 0.22.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.
@@ -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
- fishjamId?: string;
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,WAAW,oBAAqB,SAAQ,iBAAiB;IAC7D;;;OAGG;IACH,SAAS,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC;IACtC;;;;OAIG;IACH,WAAW,CAAC,EAAE,IAAI,CAAC,sBAAsB,EAAE,OAAO,GAAG,OAAO,CAAC,CAAC;IAC9D;;;OAGG;IACH,iBAAiB,CAAC,EAAE,OAAO,GAAG,yBAAyB,CAAC;IACxD;;OAEG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC,eAAe,CAAC,CAAC;IAC3C;;OAEG;IACH,WAAW,CAAC,EAAE,YAAY,CAAC;IAC3B;;OAEG;IACH,WAAW,CAAC,EAAE,YAAY,CAAC;IAK3B,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB,2CAiF1D"}
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,WAAW,oBAAqB,SAAQ,iBAAiB;IAC7D;;;OAGG;IACH,SAAS,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC;IACtC;;;;OAIG;IACH,WAAW,CAAC,EAAE,IAAI,CAAC,sBAAsB,EAAE,OAAO,GAAG,OAAO,CAAC,CAAC;IAC9D;;;OAGG;IACH,iBAAiB,CAAC,EAAE,OAAO,GAAG,yBAAyB,CAAC;IACxD;;OAEG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC,eAAe,CAAC,CAAC;IAC3C;;OAEG;IACH,WAAW,CAAC,EAAE,YAAY,CAAC;IAC3B;;OAEG;IACH,WAAW,CAAC,EAAE,YAAY,CAAC;IAC3B;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB,2CAiF1D"}
@@ -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 ?? null, 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 }) }) }) }) }) }) }) }) }));
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,2 +1,3 @@
1
1
  export declare const FishjamIdContext: import("react").Context<string | null>;
2
+ export declare const useFishjamId: () => string;
2
3
  //# sourceMappingURL=fishjamId.d.ts.map
@@ -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>({ url, peerToken, peerMetadata, }: JoinRoomConfig<PeerMetadata>) => Promise<void>;
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,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,YAAY,CAAC,EAAE,YAAY,CAAC;CAC7B;AAED;;;;GAIG;AACH,wBAAgB,aAAa;IAgCzB;;OAEG;eAvBF,YAAY,SAAS,eAAe,uDAIlC,cAAc,CAAC,YAAY,CAAC;IAqB/B;;OAEG;;IAEH;;OAEG;;IAEH;;OAEG;;EAGN"}
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 { FishjamIdContext } from "../contexts/fishjamId";
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 = useContext(FishjamIdContext);
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(({ url, peerToken, peerMetadata, }) => {
21
- if (!url && !fishjamId) {
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 = `${FISHJAM_WS_CONNECT_URL}/${fishjamId}`;
25
- return client.connect({ url: url ?? connectUrl, token: peerToken, peerMetadata: peerMetadata ?? {} });
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,6 +1,6 @@
1
1
  export type UseSandboxProps = {
2
2
  configOverride?: {
3
- fishjamUrl?: string;
3
+ sandboxApiUrl?: string;
4
4
  };
5
5
  };
6
6
  export type RoomType = "conference" | "livestream" | "audio_only";
@@ -1 +1 @@
1
- {"version":3,"file":"useSandbox.d.ts","sourceRoot":"","sources":["../../src/hooks/useSandbox.ts"],"names":[],"mappings":"AAmBA,MAAM,MAAM,eAAe,GAAG;IAE5B,cAAc,CAAC,EAAE;QAAE,UAAU,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CAC1C,CAAC;AAEF,MAAM,MAAM,QAAQ,GAAG,YAAY,GAAG,YAAY,GAAG,YAAY,CAAC;AAElE,eAAO,MAAM,UAAU,GAAI,QAAQ,eAAe;oCAUH,MAAM,YAAY,MAAM,aAAY,QAAQ;sCAmB1C,MAAM;qCAkBP,MAAM,aAAY,OAAO;uBAUxC,MAAM;cAAQ;YAAE,EAAE,EAAE,MAAM,CAAC;YAAC,IAAI,EAAE,MAAM,CAAA;SAAE;;CAK1E,CAAC"}
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"}
@@ -1,21 +1,11 @@
1
- import { useContext } from "react";
2
- import { FISHJAM_HTTP_CONNECT_URL } from "../consts";
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 = useContext(FishjamIdContext);
11
- const overridenFishjamUrl = props?.configOverride?.fishjamUrl;
12
- const fishjamUrl = `${FISHJAM_HTTP_CONNECT_URL}/${fishjamId}`;
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
- if (isFishjamIdMisconfigured)
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
- if (isFishjamIdMisconfigured)
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
- if (isFishjamIdMisconfigured)
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,3 @@
1
+ export declare function resolveFishjamUrl(fishjamId: string): string;
2
+ export declare function httpToWebsocketUrl(url: string): string;
3
+ //# sourceMappingURL=fishjamUrl.d.ts.map
@@ -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.20.0",
3
+ "version": "0.22.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.20.0",
63
+ "@fishjam-cloud/ts-client": "0.22.0",
64
64
  "events": "3.3.0",
65
65
  "lodash.isequal": "4.5.0"
66
66
  },