-
Notifications
You must be signed in to change notification settings - Fork 3
Add fishjam hooks to composition package #282
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
76022ce
Add fishjam hooks to composition package
AHGIJMKLKKZNPJKQR 3b07f87
Format
AHGIJMKLKKZNPJKQR c4f181f
Fix build ordering
AHGIJMKLKKZNPJKQR e1e7b7a
Format
AHGIJMKLKKZNPJKQR 402a023
Prevent unnecessary rerenders
AHGIJMKLKKZNPJKQR 6cbf1e0
Make hooks surface simpler to use
AHGIJMKLKKZNPJKQR 231dda9
Add global declaration
AHGIJMKLKKZNPJKQR 8588005
Make TrackRemoved update vad
AHGIJMKLKKZNPJKQR b36d3f9
Fix eventBus typo
AHGIJMKLKKZNPJKQR 0164903
Rename internal to core
AHGIJMKLKKZNPJKQR bdba2dc
Export interface
AHGIJMKLKKZNPJKQR fa70461
Prevent re-emitting js-server-sdk types
AHGIJMKLKKZNPJKQR File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| export { compositionStore } from './store'; | ||
| export type { CompositionEvent, RoomSnapshot, CompositionStoreFeed } from './store'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| export interface CompositionEventBus { | ||
| on<T = unknown>(eventName: string, callback: (data: T) => void): () => void; | ||
| } | ||
|
|
||
| declare global { | ||
| // eslint-disable-next-line no-var | ||
| var eventBus: CompositionEventBus; | ||
| } | ||
|
|
||
| export const eventBus = globalThis.eventBus; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| import { useCallback, useSyncExternalStore } from 'react'; | ||
| import { compositionStore } from './store'; | ||
| import type { PeerWithStreams, VadStatus } from './types'; | ||
|
|
||
| /** | ||
| * All peers in the linked room, projected into composition streams. Flat list — | ||
| * the worker is not a peer, so there is no local/remote split. | ||
| */ | ||
| export function usePeers<PeerMetadata = unknown, ServerMetadata = unknown>(): PeerWithStreams< | ||
| PeerMetadata, | ||
| ServerMetadata | ||
| >[] { | ||
| const peers = useSyncExternalStore(compositionStore.subscribe, compositionStore.getPeers, compositionStore.getPeers); | ||
| return peers as PeerWithStreams<PeerMetadata, ServerMetadata>[]; | ||
| } | ||
|
|
||
| /** | ||
| * The peer with the given `peerId`, or `undefined`. | ||
| */ | ||
| export function usePeer<PeerMetadata = unknown, ServerMetadata = unknown>( | ||
| peerId: string | ||
| ): PeerWithStreams<PeerMetadata, ServerMetadata> | undefined { | ||
| const getSnapshot = useCallback(() => compositionStore.getPeer(peerId), [peerId]); | ||
| const peer = useSyncExternalStore(compositionStore.subscribe, getSnapshot, getSnapshot); | ||
| return peer as PeerWithStreams<PeerMetadata, ServerMetadata> | undefined; | ||
| } | ||
|
|
||
| /** | ||
| * The linked room's id, or `undefined` when no room is linked. | ||
| */ | ||
| export function useRoom(): { id: string } | undefined { | ||
| const roomId = useSyncExternalStore( | ||
| compositionStore.subscribe, | ||
| compositionStore.getRoomId, | ||
| compositionStore.getRoomId | ||
| ); | ||
| return roomId ? { id: roomId } : undefined; | ||
| } | ||
|
|
||
| /** | ||
| * Voice-activity status for the peer identified by `peerId`: `'speech'` when any | ||
| * of the peer's forwarded audio inputs is speaking, otherwise `'silence'`. | ||
| */ | ||
| export function useSpeakingState(peerId: string): VadStatus { | ||
| const getSnapshot = useCallback(() => compositionStore.getVadStatus(peerId), [peerId]); | ||
| return useSyncExternalStore(compositionStore.subscribe, getSnapshot, getSnapshot); | ||
| } | ||
|
AHGIJMKLKKZNPJKQR marked this conversation as resolved.
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,10 @@ | ||
| export interface CompositionEventBus { | ||
| on<T = unknown>(eventName: string, callback: (data: T) => void): () => void; | ||
| } | ||
|
|
||
| export const eventBus = (globalThis as unknown as { eventBus: CompositionEventBus }).eventBus; | ||
| /** | ||
| * React hooks for composition templates receiving track forwardings from rooms. | ||
| * Templates have access to a room's state (peers, tracks, voice activity). | ||
| * | ||
| * @packageDocumentation | ||
| */ | ||
| export { usePeers, usePeer, useRoom, useSpeakingState } from './hooks'; | ||
| export type { PeerWithStreams, Stream, TrackState, VideoTrackState, AudioTrackState, VadStatus } from './types'; | ||
| export { eventBus } from './eventBus'; | ||
| export type { CompositionEventBus } from './eventBus'; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.