@flyfish-dev/rtsp-player 0.1.23
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 +125 -0
- package/dist/index.d.ts +54 -0
- package/dist/react.d.ts +29 -0
- package/dist/react.js +87 -0
- package/dist/rtsp-player.esm.js +922 -0
- package/dist/rtsp-player.global.js +247 -0
- package/dist/vue.d.ts +22 -0
- package/dist/vue.js +67 -0
- package/dist/web.js +922 -0
- package/examples/index.html +21 -0
- package/package.json +48 -0
- package/src/global.js +246 -0
- package/src/index.d.ts +54 -0
- package/src/react.d.ts +29 -0
- package/src/react.js +86 -0
- package/src/vue.d.ts +22 -0
- package/src/vue.js +66 -0
- package/src/web.js +921 -0
package/README.md
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
# @flyfish-dev/rtsp-player
|
|
2
|
+
|
|
3
|
+
Universal RTSP components for pages that use the RTSP Chrome Runtime extension
|
|
4
|
+
and for Electron/Tauri apps that bundle the Go desktop runtime.
|
|
5
|
+
|
|
6
|
+
The SDK does not decode RTSP directly in a normal web page. Browsers cannot open
|
|
7
|
+
RTSP sockets, so the Chrome extension and Go Native Host still provide the local
|
|
8
|
+
runtime. This package gives application code a stable component API for plain
|
|
9
|
+
HTML, JavaScript, React, and Vue.
|
|
10
|
+
|
|
11
|
+
When a customer does not want to install the Chrome extension, ship the desktop
|
|
12
|
+
Gateway path instead: Electron/Tauri starts the bundled Go runtime and exposes
|
|
13
|
+
`window.rtspNative`. See `docs/web-component-gateway.md` for the customer-facing
|
|
14
|
+
installation guidance.
|
|
15
|
+
|
|
16
|
+
Default media policy is WebRTC first and WebSocket/WebCodecs fallback:
|
|
17
|
+
|
|
18
|
+
```html
|
|
19
|
+
<rtsp-player transport="auto" codec="auto"></rtsp-player>
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Recoverable decode, WebRTC, WebSocket, and stream-stall failures are handled
|
|
23
|
+
automatically. The element emits `recovering` while it restarts the stream and
|
|
24
|
+
`recovered` after frames resume; `error` is reserved for final failure.
|
|
25
|
+
|
|
26
|
+
## Install
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
npm install @flyfish-dev/rtsp-player
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Script Tag
|
|
33
|
+
|
|
34
|
+
```html
|
|
35
|
+
<script
|
|
36
|
+
src="/rtsp-player.global.js"
|
|
37
|
+
data-extension-id="YOUR_CHROME_EXTENSION_ID"></script>
|
|
38
|
+
|
|
39
|
+
<rtsp-player
|
|
40
|
+
url="rtsp://user:pass@192.168.1.64:554/Streaming/Channels/101"
|
|
41
|
+
width="960"
|
|
42
|
+
height="540"
|
|
43
|
+
transport="auto"
|
|
44
|
+
codec="auto"
|
|
45
|
+
autoplay
|
|
46
|
+
controls></rtsp-player>
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## JavaScript
|
|
50
|
+
|
|
51
|
+
```js
|
|
52
|
+
import { configureRTSP, createRTSPPlayer } from "@flyfish-dev/rtsp-player";
|
|
53
|
+
|
|
54
|
+
configureRTSP({ extensionId: "YOUR_CHROME_EXTENSION_ID" });
|
|
55
|
+
|
|
56
|
+
const player = createRTSPPlayer({
|
|
57
|
+
url: "rtsp://user:pass@192.168.1.64:554/Streaming/Channels/101",
|
|
58
|
+
width: 960,
|
|
59
|
+
height: 540,
|
|
60
|
+
autoplay: true,
|
|
61
|
+
controls: true,
|
|
62
|
+
transport: "auto",
|
|
63
|
+
codec: "auto",
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
player.addEventListener("ready", () => console.log("ready"));
|
|
67
|
+
player.addEventListener("error", (event) => console.error(event.detail.error));
|
|
68
|
+
|
|
69
|
+
document.body.append(player);
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## React
|
|
73
|
+
|
|
74
|
+
```jsx
|
|
75
|
+
import { RtspPlayer } from "@flyfish-dev/rtsp-player/react";
|
|
76
|
+
|
|
77
|
+
export function CameraView() {
|
|
78
|
+
return (
|
|
79
|
+
<RtspPlayer
|
|
80
|
+
extensionId="YOUR_CHROME_EXTENSION_ID"
|
|
81
|
+
url="rtsp://user:pass@192.168.1.64:554/Streaming/Channels/101"
|
|
82
|
+
width="100%"
|
|
83
|
+
height={540}
|
|
84
|
+
autoplay
|
|
85
|
+
controls
|
|
86
|
+
transport="auto"
|
|
87
|
+
codec="auto"
|
|
88
|
+
onReady={() => console.log("ready")}
|
|
89
|
+
onError={(event) => console.error(event.detail.error)}
|
|
90
|
+
/>
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Vue
|
|
96
|
+
|
|
97
|
+
```vue
|
|
98
|
+
<script setup>
|
|
99
|
+
import { RtspPlayer } from "@flyfish-dev/rtsp-player/vue";
|
|
100
|
+
</script>
|
|
101
|
+
|
|
102
|
+
<template>
|
|
103
|
+
<RtspPlayer
|
|
104
|
+
extension-id="YOUR_CHROME_EXTENSION_ID"
|
|
105
|
+
url="rtsp://user:pass@192.168.1.64:554/Streaming/Channels/101"
|
|
106
|
+
width="100%"
|
|
107
|
+
:height="540"
|
|
108
|
+
autoplay
|
|
109
|
+
controls
|
|
110
|
+
transport="auto"
|
|
111
|
+
codec="auto"
|
|
112
|
+
@ready="() => console.log('ready')"
|
|
113
|
+
@error="(event) => console.error(event.detail.error)"
|
|
114
|
+
/>
|
|
115
|
+
</template>
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## Desktop Runtime
|
|
119
|
+
|
|
120
|
+
Electron/Tauri apps expose `window.rtspNative` or `window.__RTSP_DESKTOP__` and
|
|
121
|
+
use:
|
|
122
|
+
|
|
123
|
+
```html
|
|
124
|
+
<rtsp-player runtime="desktop" transport="auto" codec="auto" url="rtsp://camera/stream"></rtsp-player>
|
|
125
|
+
```
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
export interface RTSPConfigureOptions {
|
|
2
|
+
extensionId?: string;
|
|
3
|
+
tagName?: string;
|
|
4
|
+
runtime?: RTSPRuntime;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export type RTSPRuntime = "extension" | "desktop" | "auto";
|
|
8
|
+
export type RTSPMediaTransport = "auto" | "webrtc" | "ws-annexb";
|
|
9
|
+
export type RTSPCodec = "auto" | "h264" | "h265";
|
|
10
|
+
|
|
11
|
+
export interface RTSPPlayerOptions extends RTSPConfigureOptions {
|
|
12
|
+
url?: string;
|
|
13
|
+
src?: string;
|
|
14
|
+
width?: string | number;
|
|
15
|
+
height?: string | number;
|
|
16
|
+
autoplay?: boolean;
|
|
17
|
+
controls?: boolean;
|
|
18
|
+
muted?: boolean;
|
|
19
|
+
transport?: RTSPMediaTransport | "tcp" | string;
|
|
20
|
+
rtspTransport?: "tcp" | "udp" | string;
|
|
21
|
+
mediaTransport?: RTSPMediaTransport | string;
|
|
22
|
+
codec?: RTSPCodec | string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export declare const RTSP_PLAYER_VERSION: string;
|
|
26
|
+
|
|
27
|
+
export declare function configureRTSP(options?: RTSPConfigureOptions): {
|
|
28
|
+
extensionId: string;
|
|
29
|
+
tagName: string;
|
|
30
|
+
runtime: RTSPRuntime;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export declare function defineRTSPPlayer(
|
|
34
|
+
tagName?: string,
|
|
35
|
+
options?: RTSPConfigureOptions,
|
|
36
|
+
): CustomElementConstructor | undefined;
|
|
37
|
+
|
|
38
|
+
export declare function probeRTSPCapabilities(codec?: RTSPCodec | string): Promise<{
|
|
39
|
+
desktopRuntime: boolean;
|
|
40
|
+
webcodecs: boolean;
|
|
41
|
+
webrtc: boolean;
|
|
42
|
+
h264WebRTC: boolean;
|
|
43
|
+
h265WebRTC: boolean;
|
|
44
|
+
h264WebCodecs: boolean;
|
|
45
|
+
h265WebCodecs: boolean;
|
|
46
|
+
requestedCodec: RTSPCodec;
|
|
47
|
+
}>;
|
|
48
|
+
|
|
49
|
+
export declare function createRTSPPlayer(options?: RTSPPlayerOptions): HTMLElement;
|
|
50
|
+
|
|
51
|
+
export declare function updateRTSPPlayer<T extends HTMLElement>(
|
|
52
|
+
element: T,
|
|
53
|
+
options?: RTSPPlayerOptions,
|
|
54
|
+
): T;
|
package/dist/react.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { CSSProperties, ForwardRefExoticComponent, RefAttributes } from "react";
|
|
2
|
+
|
|
3
|
+
export interface RtspPlayerProps {
|
|
4
|
+
extensionId?: string;
|
|
5
|
+
url?: string;
|
|
6
|
+
src?: string;
|
|
7
|
+
width?: string | number;
|
|
8
|
+
height?: string | number;
|
|
9
|
+
autoplay?: boolean;
|
|
10
|
+
controls?: boolean;
|
|
11
|
+
muted?: boolean;
|
|
12
|
+
transport?: "auto" | "webrtc" | "ws-annexb" | "tcp" | string;
|
|
13
|
+
rtspTransport?: "tcp" | "udp" | string;
|
|
14
|
+
mediaTransport?: "auto" | "webrtc" | "ws-annexb" | string;
|
|
15
|
+
codec?: "auto" | "h264" | "h265" | string;
|
|
16
|
+
runtime?: "extension" | "desktop" | "auto";
|
|
17
|
+
tagName?: string;
|
|
18
|
+
className?: string;
|
|
19
|
+
style?: CSSProperties;
|
|
20
|
+
onReady?: (event: CustomEvent) => void;
|
|
21
|
+
onError?: (event: CustomEvent) => void;
|
|
22
|
+
onStarting?: (event: CustomEvent) => void;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export declare const RtspPlayer: ForwardRefExoticComponent<
|
|
26
|
+
RtspPlayerProps & RefAttributes<HTMLElement>
|
|
27
|
+
>;
|
|
28
|
+
|
|
29
|
+
export default RtspPlayer;
|
package/dist/react.js
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
// RTSP SDK 0.1.23 - generated by scripts/build-sdk.mjs
|
|
2
|
+
import React, {
|
|
3
|
+
forwardRef,
|
|
4
|
+
useEffect,
|
|
5
|
+
useImperativeHandle,
|
|
6
|
+
useRef,
|
|
7
|
+
} from "react";
|
|
8
|
+
import { configureRTSP, defineRTSPPlayer, updateRTSPPlayer } from "./web.js";
|
|
9
|
+
|
|
10
|
+
export const RtspPlayer = forwardRef(function RtspPlayer(props, ref) {
|
|
11
|
+
const {
|
|
12
|
+
extensionId,
|
|
13
|
+
url,
|
|
14
|
+
src,
|
|
15
|
+
width = 640,
|
|
16
|
+
height = 360,
|
|
17
|
+
autoplay = false,
|
|
18
|
+
controls = true,
|
|
19
|
+
muted = false,
|
|
20
|
+
transport = "auto",
|
|
21
|
+
rtspTransport = "tcp",
|
|
22
|
+
mediaTransport,
|
|
23
|
+
codec = "auto",
|
|
24
|
+
runtime = "extension",
|
|
25
|
+
tagName = "rtsp-player",
|
|
26
|
+
className,
|
|
27
|
+
style,
|
|
28
|
+
onReady,
|
|
29
|
+
onError,
|
|
30
|
+
onStarting,
|
|
31
|
+
...rest
|
|
32
|
+
} = props;
|
|
33
|
+
const innerRef = useRef(null);
|
|
34
|
+
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
configureRTSP({ extensionId, tagName, runtime });
|
|
37
|
+
defineRTSPPlayer(tagName);
|
|
38
|
+
}, [extensionId, tagName, runtime]);
|
|
39
|
+
|
|
40
|
+
useImperativeHandle(ref, () => innerRef.current, []);
|
|
41
|
+
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
if (!innerRef.current) return;
|
|
44
|
+
updateRTSPPlayer(innerRef.current, {
|
|
45
|
+
extensionId,
|
|
46
|
+
url,
|
|
47
|
+
src,
|
|
48
|
+
width,
|
|
49
|
+
height,
|
|
50
|
+
autoplay,
|
|
51
|
+
controls,
|
|
52
|
+
muted,
|
|
53
|
+
transport,
|
|
54
|
+
rtspTransport,
|
|
55
|
+
mediaTransport,
|
|
56
|
+
codec,
|
|
57
|
+
runtime,
|
|
58
|
+
});
|
|
59
|
+
}, [extensionId, url, src, width, height, autoplay, controls, muted, transport, rtspTransport, mediaTransport, codec, runtime]);
|
|
60
|
+
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
const el = innerRef.current;
|
|
63
|
+
if (!el) return undefined;
|
|
64
|
+
const listeners = [
|
|
65
|
+
["ready", onReady],
|
|
66
|
+
["error", onError],
|
|
67
|
+
["starting", onStarting],
|
|
68
|
+
];
|
|
69
|
+
for (const [type, handler] of listeners) {
|
|
70
|
+
if (handler) el.addEventListener(type, handler);
|
|
71
|
+
}
|
|
72
|
+
return () => {
|
|
73
|
+
for (const [type, handler] of listeners) {
|
|
74
|
+
if (handler) el.removeEventListener(type, handler);
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
}, [onReady, onError, onStarting]);
|
|
78
|
+
|
|
79
|
+
return React.createElement(tagName, {
|
|
80
|
+
...rest,
|
|
81
|
+
ref: innerRef,
|
|
82
|
+
className,
|
|
83
|
+
style,
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
export default RtspPlayer;
|