@daydreamlive/react 0.1.1 → 0.3.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/README.md +41 -7
- package/dist/index.cjs +314 -56
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +109 -8
- package/dist/index.d.ts +109 -8
- package/dist/index.js +317 -52
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -1,36 +1,137 @@
|
|
|
1
|
-
import { ReconnectConfig, VideoConfig,
|
|
2
|
-
|
|
1
|
+
import { ReconnectConfig, VideoConfig, AudioConfig, ReconnectInfo, DaydreamError, CompositorOptions, Source, Size, Compositor, ContentHint, FitMode } from '@daydreamlive/browser';
|
|
2
|
+
export { AudioConfig, BroadcastState, CanvasSource, Compositor, CompositorEvent, CompositorEventMap, CompositorOptions, ContentHint, Ctx2D, DaydreamError, DaydreamErrorCode, FitMode, PlayerState, ReconnectConfig, ReconnectInfo, Size, Source, VideoConfig, VideoSource } from '@daydreamlive/browser';
|
|
3
|
+
import { RefObject, PropsWithChildren } from 'react';
|
|
4
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
3
5
|
|
|
4
6
|
interface UseBroadcastOptions {
|
|
5
7
|
whipUrl: string;
|
|
6
8
|
reconnect?: ReconnectConfig;
|
|
7
9
|
video?: VideoConfig;
|
|
10
|
+
audio?: AudioConfig;
|
|
11
|
+
iceServers?: RTCIceServer[];
|
|
12
|
+
connectionTimeout?: number;
|
|
8
13
|
onStats?: (report: RTCStatsReport) => void;
|
|
9
14
|
statsIntervalMs?: number;
|
|
10
15
|
}
|
|
16
|
+
type UseBroadcastStatus = {
|
|
17
|
+
state: "idle";
|
|
18
|
+
} | {
|
|
19
|
+
state: "connecting";
|
|
20
|
+
} | {
|
|
21
|
+
state: "live";
|
|
22
|
+
whepUrl: string;
|
|
23
|
+
} | {
|
|
24
|
+
state: "reconnecting";
|
|
25
|
+
whepUrl: string;
|
|
26
|
+
reconnectInfo: ReconnectInfo;
|
|
27
|
+
} | {
|
|
28
|
+
state: "ended";
|
|
29
|
+
} | {
|
|
30
|
+
state: "error";
|
|
31
|
+
error: DaydreamError;
|
|
32
|
+
};
|
|
11
33
|
interface UseBroadcastReturn {
|
|
12
|
-
|
|
13
|
-
whepUrl: string | null;
|
|
14
|
-
error: DaydreamError | null;
|
|
34
|
+
status: UseBroadcastStatus;
|
|
15
35
|
start: (stream: MediaStream) => Promise<void>;
|
|
16
36
|
stop: () => Promise<void>;
|
|
37
|
+
setMaxFramerate: (fps?: number) => void;
|
|
17
38
|
}
|
|
18
39
|
|
|
19
40
|
interface UsePlayerOptions {
|
|
20
41
|
reconnect?: ReconnectConfig;
|
|
42
|
+
iceServers?: RTCIceServer[];
|
|
43
|
+
connectionTimeout?: number;
|
|
44
|
+
skipIceGathering?: boolean;
|
|
21
45
|
autoPlay?: boolean;
|
|
22
46
|
onStats?: (report: RTCStatsReport) => void;
|
|
23
47
|
statsIntervalMs?: number;
|
|
24
48
|
}
|
|
49
|
+
type UsePlayerStatus = {
|
|
50
|
+
state: "idle";
|
|
51
|
+
} | {
|
|
52
|
+
state: "connecting";
|
|
53
|
+
} | {
|
|
54
|
+
state: "playing";
|
|
55
|
+
} | {
|
|
56
|
+
state: "buffering";
|
|
57
|
+
reconnectInfo: ReconnectInfo;
|
|
58
|
+
} | {
|
|
59
|
+
state: "ended";
|
|
60
|
+
} | {
|
|
61
|
+
state: "error";
|
|
62
|
+
error: DaydreamError;
|
|
63
|
+
};
|
|
25
64
|
interface UsePlayerReturn {
|
|
26
|
-
|
|
27
|
-
error: DaydreamError | null;
|
|
65
|
+
status: UsePlayerStatus;
|
|
28
66
|
play: () => Promise<void>;
|
|
29
67
|
stop: () => Promise<void>;
|
|
30
68
|
videoRef: RefObject<HTMLVideoElement | null>;
|
|
31
69
|
}
|
|
32
70
|
|
|
71
|
+
interface CompositorApi {
|
|
72
|
+
register(id: string, source: Source): void;
|
|
73
|
+
unregister(id: string): void;
|
|
74
|
+
get(id: string): Source | undefined;
|
|
75
|
+
has(id: string): boolean;
|
|
76
|
+
list(): Array<{
|
|
77
|
+
id: string;
|
|
78
|
+
source: Source;
|
|
79
|
+
}>;
|
|
80
|
+
/**
|
|
81
|
+
* Register a source, activate it, and return an unregister function.
|
|
82
|
+
* Convenience method that combines register + activate with automatic cleanup.
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```tsx
|
|
86
|
+
* useEffect(() => {
|
|
87
|
+
* const unregister = compositor.use("camera", {
|
|
88
|
+
* kind: "video",
|
|
89
|
+
* element: videoRef.current,
|
|
90
|
+
* fit: "cover",
|
|
91
|
+
* });
|
|
92
|
+
* return unregister;
|
|
93
|
+
* }, [compositor]);
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
use(id: string, source: Source): () => void;
|
|
97
|
+
/**
|
|
98
|
+
* Activate a registered source.
|
|
99
|
+
* @param id - The source ID to activate
|
|
100
|
+
*/
|
|
101
|
+
activate(id: string): void;
|
|
102
|
+
deactivate(): void;
|
|
103
|
+
readonly activeId: string | null;
|
|
104
|
+
readonly stream: MediaStream | null;
|
|
105
|
+
readonly size: Size;
|
|
106
|
+
setSize(width: number, height: number, dpr?: number): void;
|
|
107
|
+
readonly fps: number;
|
|
108
|
+
setFps(fps: number): void;
|
|
109
|
+
readonly sendFps: number;
|
|
110
|
+
setSendFps(fps: number): void;
|
|
111
|
+
addAudioTrack(track: MediaStreamTrack): void;
|
|
112
|
+
removeAudioTrack(trackId: string): void;
|
|
113
|
+
unlockAudio(): Promise<boolean>;
|
|
114
|
+
on: Compositor["on"];
|
|
115
|
+
}
|
|
116
|
+
interface CompositorProviderProps extends PropsWithChildren, Partial<Omit<CompositorOptions, "onSendFpsChange">> {
|
|
117
|
+
}
|
|
118
|
+
declare function CompositorProvider({ children, width, height, fps: initialFps, sendFps: initialSendFps, dpr, keepalive, autoUnlockAudio, unlockEvents, disableSilentAudio, }: CompositorProviderProps): react_jsx_runtime.JSX.Element;
|
|
119
|
+
declare function useCompositor(): CompositorApi;
|
|
120
|
+
|
|
121
|
+
interface UseSourceOptions {
|
|
122
|
+
kind: "video" | "canvas";
|
|
123
|
+
contentHint?: ContentHint;
|
|
124
|
+
fit?: FitMode;
|
|
125
|
+
}
|
|
126
|
+
interface UseSourceReturn<T extends HTMLVideoElement | HTMLCanvasElement> {
|
|
127
|
+
ref: React.RefObject<T>;
|
|
128
|
+
isActive: boolean;
|
|
129
|
+
activate: () => void;
|
|
130
|
+
deactivate: () => void;
|
|
131
|
+
}
|
|
132
|
+
declare function useSource<T extends HTMLVideoElement | HTMLCanvasElement = HTMLVideoElement | HTMLCanvasElement>(id: string, options: UseSourceOptions): UseSourceReturn<T>;
|
|
133
|
+
|
|
33
134
|
declare function useBroadcast(options: UseBroadcastOptions): UseBroadcastReturn;
|
|
34
135
|
declare function usePlayer(whepUrl: string | null, options?: UsePlayerOptions): UsePlayerReturn;
|
|
35
136
|
|
|
36
|
-
export { type UseBroadcastOptions, type UseBroadcastReturn, type UsePlayerOptions, type UsePlayerReturn, useBroadcast, usePlayer };
|
|
137
|
+
export { type CompositorApi, CompositorProvider, type CompositorProviderProps, type UseBroadcastOptions, type UseBroadcastReturn, type UseBroadcastStatus, type UsePlayerOptions, type UsePlayerReturn, type UsePlayerStatus, type UseSourceOptions, type UseSourceReturn, useBroadcast, useCompositor, usePlayer, useSource };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,36 +1,137 @@
|
|
|
1
|
-
import { ReconnectConfig, VideoConfig,
|
|
2
|
-
|
|
1
|
+
import { ReconnectConfig, VideoConfig, AudioConfig, ReconnectInfo, DaydreamError, CompositorOptions, Source, Size, Compositor, ContentHint, FitMode } from '@daydreamlive/browser';
|
|
2
|
+
export { AudioConfig, BroadcastState, CanvasSource, Compositor, CompositorEvent, CompositorEventMap, CompositorOptions, ContentHint, Ctx2D, DaydreamError, DaydreamErrorCode, FitMode, PlayerState, ReconnectConfig, ReconnectInfo, Size, Source, VideoConfig, VideoSource } from '@daydreamlive/browser';
|
|
3
|
+
import { RefObject, PropsWithChildren } from 'react';
|
|
4
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
3
5
|
|
|
4
6
|
interface UseBroadcastOptions {
|
|
5
7
|
whipUrl: string;
|
|
6
8
|
reconnect?: ReconnectConfig;
|
|
7
9
|
video?: VideoConfig;
|
|
10
|
+
audio?: AudioConfig;
|
|
11
|
+
iceServers?: RTCIceServer[];
|
|
12
|
+
connectionTimeout?: number;
|
|
8
13
|
onStats?: (report: RTCStatsReport) => void;
|
|
9
14
|
statsIntervalMs?: number;
|
|
10
15
|
}
|
|
16
|
+
type UseBroadcastStatus = {
|
|
17
|
+
state: "idle";
|
|
18
|
+
} | {
|
|
19
|
+
state: "connecting";
|
|
20
|
+
} | {
|
|
21
|
+
state: "live";
|
|
22
|
+
whepUrl: string;
|
|
23
|
+
} | {
|
|
24
|
+
state: "reconnecting";
|
|
25
|
+
whepUrl: string;
|
|
26
|
+
reconnectInfo: ReconnectInfo;
|
|
27
|
+
} | {
|
|
28
|
+
state: "ended";
|
|
29
|
+
} | {
|
|
30
|
+
state: "error";
|
|
31
|
+
error: DaydreamError;
|
|
32
|
+
};
|
|
11
33
|
interface UseBroadcastReturn {
|
|
12
|
-
|
|
13
|
-
whepUrl: string | null;
|
|
14
|
-
error: DaydreamError | null;
|
|
34
|
+
status: UseBroadcastStatus;
|
|
15
35
|
start: (stream: MediaStream) => Promise<void>;
|
|
16
36
|
stop: () => Promise<void>;
|
|
37
|
+
setMaxFramerate: (fps?: number) => void;
|
|
17
38
|
}
|
|
18
39
|
|
|
19
40
|
interface UsePlayerOptions {
|
|
20
41
|
reconnect?: ReconnectConfig;
|
|
42
|
+
iceServers?: RTCIceServer[];
|
|
43
|
+
connectionTimeout?: number;
|
|
44
|
+
skipIceGathering?: boolean;
|
|
21
45
|
autoPlay?: boolean;
|
|
22
46
|
onStats?: (report: RTCStatsReport) => void;
|
|
23
47
|
statsIntervalMs?: number;
|
|
24
48
|
}
|
|
49
|
+
type UsePlayerStatus = {
|
|
50
|
+
state: "idle";
|
|
51
|
+
} | {
|
|
52
|
+
state: "connecting";
|
|
53
|
+
} | {
|
|
54
|
+
state: "playing";
|
|
55
|
+
} | {
|
|
56
|
+
state: "buffering";
|
|
57
|
+
reconnectInfo: ReconnectInfo;
|
|
58
|
+
} | {
|
|
59
|
+
state: "ended";
|
|
60
|
+
} | {
|
|
61
|
+
state: "error";
|
|
62
|
+
error: DaydreamError;
|
|
63
|
+
};
|
|
25
64
|
interface UsePlayerReturn {
|
|
26
|
-
|
|
27
|
-
error: DaydreamError | null;
|
|
65
|
+
status: UsePlayerStatus;
|
|
28
66
|
play: () => Promise<void>;
|
|
29
67
|
stop: () => Promise<void>;
|
|
30
68
|
videoRef: RefObject<HTMLVideoElement | null>;
|
|
31
69
|
}
|
|
32
70
|
|
|
71
|
+
interface CompositorApi {
|
|
72
|
+
register(id: string, source: Source): void;
|
|
73
|
+
unregister(id: string): void;
|
|
74
|
+
get(id: string): Source | undefined;
|
|
75
|
+
has(id: string): boolean;
|
|
76
|
+
list(): Array<{
|
|
77
|
+
id: string;
|
|
78
|
+
source: Source;
|
|
79
|
+
}>;
|
|
80
|
+
/**
|
|
81
|
+
* Register a source, activate it, and return an unregister function.
|
|
82
|
+
* Convenience method that combines register + activate with automatic cleanup.
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```tsx
|
|
86
|
+
* useEffect(() => {
|
|
87
|
+
* const unregister = compositor.use("camera", {
|
|
88
|
+
* kind: "video",
|
|
89
|
+
* element: videoRef.current,
|
|
90
|
+
* fit: "cover",
|
|
91
|
+
* });
|
|
92
|
+
* return unregister;
|
|
93
|
+
* }, [compositor]);
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
use(id: string, source: Source): () => void;
|
|
97
|
+
/**
|
|
98
|
+
* Activate a registered source.
|
|
99
|
+
* @param id - The source ID to activate
|
|
100
|
+
*/
|
|
101
|
+
activate(id: string): void;
|
|
102
|
+
deactivate(): void;
|
|
103
|
+
readonly activeId: string | null;
|
|
104
|
+
readonly stream: MediaStream | null;
|
|
105
|
+
readonly size: Size;
|
|
106
|
+
setSize(width: number, height: number, dpr?: number): void;
|
|
107
|
+
readonly fps: number;
|
|
108
|
+
setFps(fps: number): void;
|
|
109
|
+
readonly sendFps: number;
|
|
110
|
+
setSendFps(fps: number): void;
|
|
111
|
+
addAudioTrack(track: MediaStreamTrack): void;
|
|
112
|
+
removeAudioTrack(trackId: string): void;
|
|
113
|
+
unlockAudio(): Promise<boolean>;
|
|
114
|
+
on: Compositor["on"];
|
|
115
|
+
}
|
|
116
|
+
interface CompositorProviderProps extends PropsWithChildren, Partial<Omit<CompositorOptions, "onSendFpsChange">> {
|
|
117
|
+
}
|
|
118
|
+
declare function CompositorProvider({ children, width, height, fps: initialFps, sendFps: initialSendFps, dpr, keepalive, autoUnlockAudio, unlockEvents, disableSilentAudio, }: CompositorProviderProps): react_jsx_runtime.JSX.Element;
|
|
119
|
+
declare function useCompositor(): CompositorApi;
|
|
120
|
+
|
|
121
|
+
interface UseSourceOptions {
|
|
122
|
+
kind: "video" | "canvas";
|
|
123
|
+
contentHint?: ContentHint;
|
|
124
|
+
fit?: FitMode;
|
|
125
|
+
}
|
|
126
|
+
interface UseSourceReturn<T extends HTMLVideoElement | HTMLCanvasElement> {
|
|
127
|
+
ref: React.RefObject<T>;
|
|
128
|
+
isActive: boolean;
|
|
129
|
+
activate: () => void;
|
|
130
|
+
deactivate: () => void;
|
|
131
|
+
}
|
|
132
|
+
declare function useSource<T extends HTMLVideoElement | HTMLCanvasElement = HTMLVideoElement | HTMLCanvasElement>(id: string, options: UseSourceOptions): UseSourceReturn<T>;
|
|
133
|
+
|
|
33
134
|
declare function useBroadcast(options: UseBroadcastOptions): UseBroadcastReturn;
|
|
34
135
|
declare function usePlayer(whepUrl: string | null, options?: UsePlayerOptions): UsePlayerReturn;
|
|
35
136
|
|
|
36
|
-
export { type UseBroadcastOptions, type UseBroadcastReturn, type UsePlayerOptions, type UsePlayerReturn, useBroadcast, usePlayer };
|
|
137
|
+
export { type CompositorApi, CompositorProvider, type CompositorProviderProps, type UseBroadcastOptions, type UseBroadcastReturn, type UseBroadcastStatus, type UsePlayerOptions, type UsePlayerReturn, type UsePlayerStatus, type UseSourceOptions, type UseSourceReturn, useBroadcast, useCompositor, usePlayer, useSource };
|