Skip to content

Commit

Permalink
[FCE-399] Remove create fn (#71)
Browse files Browse the repository at this point in the history
## Description

Removes the create function and segregates the hooks in the `/hooks`
directory.

## Motivation and Context

We don't want to export our hooks through a function. The boundary of a
client is now managed by the FishjamProvider.

## Types of changes

- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to
      not work as expected)
  • Loading branch information
czerwiukk authored Aug 28, 2024
1 parent 1025a46 commit 3264419
Show file tree
Hide file tree
Showing 29 changed files with 569 additions and 604 deletions.
8 changes: 4 additions & 4 deletions examples/react-client/minimal-react/src/components/App.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import VideoPlayer from "./VideoPlayer";
import type { Client } from "@fishjam-cloud/react-client";
import { SCREEN_SHARING_MEDIA_CONSTRAINTS } from "@fishjam-cloud/react-client";
import { useState } from "react";
import {
SCREEN_SHARING_MEDIA_CONSTRAINTS,
useClient,
useConnect,
useDisconnect,
useClient,
useStatus,
useTracks,
} from "./client";
} from "@fishjam-cloud/react-client";
import { useState } from "react";

const FISHJAM_URL = "ws://localhost:5002";

Expand Down
12 changes: 0 additions & 12 deletions examples/react-client/minimal-react/src/components/client.ts

This file was deleted.

6 changes: 3 additions & 3 deletions examples/react-client/minimal-react/src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React from "react";
import ReactDOM from "react-dom/client";
import { App } from "./components/App";
import { FishjamContextProvider } from "./components/client";
import { FishjamProvider } from "@fishjam-cloud/react-client";

ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(
<React.StrictMode>
<FishjamContextProvider>
<FishjamProvider>
<App />
</FishjamContextProvider>
</FishjamProvider>
</React.StrictMode>,
);
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { useCamera, useMicrophone, useStatus } from "./fishjamSetup";
import { DeviceControls } from "./DeviceControls";
import { atomWithStorage } from "jotai/utils";
import { useAtom } from "jotai";
import VideoPlayer from "./VideoPlayer";
import AudioVisualizer from "./AudioVisualizer";
import {
useCamera,
useMicrophone,
useStatus,
} from "@fishjam-cloud/react-client";

const showAdditionalComponentAtom = atomWithStorage(
"show-additional-component",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import VideoPlayer from "./VideoPlayer";
import { DeviceSelector } from "./DeviceSelector";
import { useAtom } from "jotai";
import { atomWithStorage } from "jotai/utils";
import { ThreeStateRadio } from "./ThreeStateRadio";
import AudioVisualizer from "./AudioVisualizer";
import {
useAuthErrorReason,
AUDIO_TRACK_CONSTRAINTS,
useCamera,
useClient,
useConnect,
Expand All @@ -9,21 +15,13 @@ import {
useSelector,
useSetupMedia,
useStatus,
} from "./fishjamSetup";
import VideoPlayer from "./VideoPlayer";
import { DeviceSelector } from "./DeviceSelector";
import { useAtom } from "jotai";
import { atomWithStorage } from "jotai/utils";
import { ThreeStateRadio } from "./ThreeStateRadio";
import AudioVisualizer from "./AudioVisualizer";
import {
AUDIO_TRACK_CONSTRAINTS,
VIDEO_TRACK_CONSTRAINTS,
} from "@fishjam-cloud/react-client";
import { Badge } from "./Badge";
import { DeviceControls } from "./DeviceControls";
import { Radio } from "./Radio";
import { ScreenShareControls } from "./ScreenShareControls";
import { useAuthErrorReason } from "./fishjamSetup";

type OnDeviceChange = "remove" | "replace" | undefined;
type OnDeviceStop = "remove" | "mute" | undefined;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useScreenShare } from "./fishjamSetup";
import { useScreenShare } from "@fishjam-cloud/react-client";

export const ScreenShareControls = () => {
const screenShare = useScreenShare();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,6 @@
import type { ClientEvents } from "@fishjam-cloud/react-client";
import { create } from "@fishjam-cloud/react-client";
import { useClient, type ClientEvents } from "@fishjam-cloud/react-client";
import { useEffect, useState } from "react";

export const {
useStatus,
useConnect,
useDisconnect,
FishjamContextProvider,
useSetupMedia,
useCamera,
useMicrophone,
useScreenShare,
useSelector,
useClient,
} = create();

export const useAuthErrorReason = () => {
const client = useClient();
const [authError, setAuthError] = useState<string | null>(null);
Expand Down
6 changes: 3 additions & 3 deletions examples/react-client/use-camera-and-microphone/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import React from "react";
import ReactDOM from "react-dom/client";
import MainControls from "./MainControls";
import "./index.css";
import { FishjamContextProvider } from "./fishjamSetup";
import AdditionalControls from "./AdditionalControls";
import { FishjamProvider } from "@fishjam-cloud/react-client";

ReactDOM.createRoot(document.getElementById("root")!).render(
<React.StrictMode>
<FishjamContextProvider>
<FishjamProvider>
<MainControls />
<AdditionalControls />
</FishjamContextProvider>
</FishjamProvider>
</React.StrictMode>,
);
2 changes: 1 addition & 1 deletion examples/react-client/videoroom/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { useEffect } from "react";
import { useClient, useParticipants } from "./client";
import { DevicePicker } from "./components/DevicePicker";
import { RoomConnector } from "./components/RoomConnector";
import { VideoTracks } from "./components/VideoTracks";
import { AudioTracks } from "./components/AudioTracks";
import { useClient, useParticipants } from "@fishjam-cloud/react-client";

function App() {
const client = useClient();
Expand Down
16 changes: 0 additions & 16 deletions examples/react-client/videoroom/src/client.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { TrackMiddleware } from "@fishjam-cloud/react-client";
import { TrackMiddleware, useCamera } from "@fishjam-cloud/react-client";
import { useRef, useCallback } from "react";
import { useCamera } from "../client";
import { BlurProcessor } from "../utils/blur/BlurProcessor";
import { Button } from "./Button";

Expand Down
10 changes: 8 additions & 2 deletions examples/react-client/videoroom/src/components/DevicePicker.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import { FC } from "react";
import AudioVisualizer from "./AudioVisualizer";
import { useCamera, useMicrophone, useScreenShare, useStatus } from "../client";
import VideoPlayer from "./VideoPlayer";
import { TrackManager, UserMediaAPI } from "@fishjam-cloud/react-client";
import {
TrackManager,
useCamera,
useMicrophone,
UserMediaAPI,
useScreenShare,
useStatus,
} from "@fishjam-cloud/react-client";
import { Button } from "./Button";
import { BlurToggle } from "./BlurToggle";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { Button } from "./Button";
import { useConnect, useStatus, useDisconnect } from "../client";
import {
useConnect,
useDisconnect,
useStatus,
} from "@fishjam-cloud/react-client";

import { Button } from "./Button";
type FormProps = {
roomName: string;
userName: string;
Expand Down
6 changes: 3 additions & 3 deletions examples/react-client/videoroom/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import React from "react";
import ReactDOM from "react-dom/client";
import App from "./App.tsx";
import "./index.css";
import { FishjamContextProvider } from "./client.ts";
import { FishjamProvider } from "@fishjam-cloud/react-client";

ReactDOM.createRoot(document.getElementById("root")!).render(
<React.StrictMode>
<FishjamContextProvider>
<FishjamProvider>
<App />
</FishjamContextProvider>
</FishjamProvider>
</React.StrictMode>,
);
4 changes: 2 additions & 2 deletions packages/react-client/src/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ export interface ClientEvents {
) => void;
}

export type ReactClientCreteConfig<PeerMetadata, TrackMetadata> = {
export type ReactClientCreateConfig = {
clientConfig?: CreateConfig<PeerMetadata, TrackMetadata>;
deviceManagerDefaultConfig?: DeviceManagerConfig;
};
Expand All @@ -291,7 +291,7 @@ export class Client extends (EventEmitter as new () => TypedEmitter<Required<Cli
public audioDeviceManager: DeviceManager;
private initialized: boolean = false;

constructor(config?: ReactClientCreteConfig<PeerMetadata, TrackMetadata>) {
constructor(config?: ReactClientCreateConfig) {
super();

this.tsClient = new FishjamClient<PeerMetadata, TrackMetadata>(config?.clientConfig);
Expand Down
Loading

0 comments on commit 3264419

Please sign in to comment.