@havue/solutions 1.0.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.
Files changed (53) hide show
  1. package/README.md +0 -0
  2. package/bc-connect/README.md +3 -0
  3. package/bc-connect/dist/bc-connect.mjs +342 -0
  4. package/bc-connect/dist/bc-connect.umd.js +346 -0
  5. package/bc-connect/dist/types/src/index.d.ts +1 -0
  6. package/bc-connect/dist/types/src/manager.d.ts +135 -0
  7. package/bc-connect/package.json +38 -0
  8. package/bc-connect/src/index.ts +1 -0
  9. package/bc-connect/src/manager.ts +388 -0
  10. package/bc-connect/vite.config.ts +4 -0
  11. package/dist/solutions.full.js +8504 -0
  12. package/dist/solutions.full.min.js +18 -0
  13. package/dist/solutions.full.min.js.map +1 -0
  14. package/dist/solutions.mjs +2 -0
  15. package/dist/solutions.umd.js +18 -0
  16. package/dist/types/bc-connect/src/index.d.ts +1 -0
  17. package/dist/types/bc-connect/src/manager.d.ts +135 -0
  18. package/dist/types/src/index.d.ts +2 -0
  19. package/dist/types/ws-video-manager/src/hooks/useVideoPlay.d.ts +73 -0
  20. package/dist/types/ws-video-manager/src/index.d.ts +5 -0
  21. package/dist/types/ws-video-manager/src/loader/index.d.ts +2 -0
  22. package/dist/types/ws-video-manager/src/loader/websocket-loader.d.ts +62 -0
  23. package/dist/types/ws-video-manager/src/manager/index.d.ts +144 -0
  24. package/dist/types/ws-video-manager/src/render/drawer.d.ts +44 -0
  25. package/dist/types/ws-video-manager/src/render/index.d.ts +105 -0
  26. package/package.json +44 -0
  27. package/src/index.ts +2 -0
  28. package/vite.config.ts +4 -0
  29. package/ws-video-manager/README.md +3 -0
  30. package/ws-video-manager/dist/types/src/hooks/useVideoPlay.d.ts +73 -0
  31. package/ws-video-manager/dist/types/src/index.d.ts +5 -0
  32. package/ws-video-manager/dist/types/src/loader/index.d.ts +2 -0
  33. package/ws-video-manager/dist/types/src/loader/websocket-loader.d.ts +62 -0
  34. package/ws-video-manager/dist/types/src/manager/index.d.ts +144 -0
  35. package/ws-video-manager/dist/types/src/render/drawer.d.ts +44 -0
  36. package/ws-video-manager/dist/types/src/render/index.d.ts +105 -0
  37. package/ws-video-manager/dist/ws-video-manager.mjs +8132 -0
  38. package/ws-video-manager/dist/ws-video-manager.umd.js +8135 -0
  39. package/ws-video-manager/node_modules/.bin/tsc +17 -0
  40. package/ws-video-manager/node_modules/.bin/tsc.CMD +12 -0
  41. package/ws-video-manager/node_modules/.bin/tsc.ps1 +41 -0
  42. package/ws-video-manager/node_modules/.bin/tsserver +17 -0
  43. package/ws-video-manager/node_modules/.bin/tsserver.CMD +12 -0
  44. package/ws-video-manager/node_modules/.bin/tsserver.ps1 +41 -0
  45. package/ws-video-manager/package.json +41 -0
  46. package/ws-video-manager/src/hooks/useVideoPlay.ts +357 -0
  47. package/ws-video-manager/src/index.ts +6 -0
  48. package/ws-video-manager/src/loader/index.ts +3 -0
  49. package/ws-video-manager/src/loader/websocket-loader.ts +278 -0
  50. package/ws-video-manager/src/manager/index.ts +429 -0
  51. package/ws-video-manager/src/render/drawer.ts +255 -0
  52. package/ws-video-manager/src/render/index.ts +475 -0
  53. package/ws-video-manager/vite.config.ts +4 -0
@@ -0,0 +1,17 @@
1
+ #!/bin/sh
2
+ basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
3
+
4
+ case `uname` in
5
+ *CYGWIN*) basedir=`cygpath -w "$basedir"`;;
6
+ esac
7
+
8
+ if [ -z "$NODE_PATH" ]; then
9
+ export NODE_PATH="/mnt/e/study/VueComponents/node_modules/.pnpm/typescript@5.8.2/node_modules/typescript/bin/node_modules:/mnt/e/study/VueComponents/node_modules/.pnpm/typescript@5.8.2/node_modules/typescript/node_modules:/mnt/e/study/VueComponents/node_modules/.pnpm/typescript@5.8.2/node_modules:/mnt/e/study/VueComponents/node_modules/.pnpm/node_modules"
10
+ else
11
+ export NODE_PATH="/mnt/e/study/VueComponents/node_modules/.pnpm/typescript@5.8.2/node_modules/typescript/bin/node_modules:/mnt/e/study/VueComponents/node_modules/.pnpm/typescript@5.8.2/node_modules/typescript/node_modules:/mnt/e/study/VueComponents/node_modules/.pnpm/typescript@5.8.2/node_modules:/mnt/e/study/VueComponents/node_modules/.pnpm/node_modules:$NODE_PATH"
12
+ fi
13
+ if [ -x "$basedir/node" ]; then
14
+ exec "$basedir/node" "$basedir/../../../../../node_modules/.pnpm/typescript@5.8.2/node_modules/typescript/bin/tsc" "$@"
15
+ else
16
+ exec node "$basedir/../../../../../node_modules/.pnpm/typescript@5.8.2/node_modules/typescript/bin/tsc" "$@"
17
+ fi
@@ -0,0 +1,12 @@
1
+ @SETLOCAL
2
+ @IF NOT DEFINED NODE_PATH (
3
+ @SET "NODE_PATH=E:\study\VueComponents\node_modules\.pnpm\typescript@5.8.2\node_modules\typescript\bin\node_modules;E:\study\VueComponents\node_modules\.pnpm\typescript@5.8.2\node_modules\typescript\node_modules;E:\study\VueComponents\node_modules\.pnpm\typescript@5.8.2\node_modules;E:\study\VueComponents\node_modules\.pnpm\node_modules"
4
+ ) ELSE (
5
+ @SET "NODE_PATH=E:\study\VueComponents\node_modules\.pnpm\typescript@5.8.2\node_modules\typescript\bin\node_modules;E:\study\VueComponents\node_modules\.pnpm\typescript@5.8.2\node_modules\typescript\node_modules;E:\study\VueComponents\node_modules\.pnpm\typescript@5.8.2\node_modules;E:\study\VueComponents\node_modules\.pnpm\node_modules;%NODE_PATH%"
6
+ )
7
+ @IF EXIST "%~dp0\node.exe" (
8
+ "%~dp0\node.exe" "%~dp0\..\..\..\..\..\node_modules\.pnpm\typescript@5.8.2\node_modules\typescript\bin\tsc" %*
9
+ ) ELSE (
10
+ @SET PATHEXT=%PATHEXT:;.JS;=;%
11
+ node "%~dp0\..\..\..\..\..\node_modules\.pnpm\typescript@5.8.2\node_modules\typescript\bin\tsc" %*
12
+ )
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env pwsh
2
+ $basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent
3
+
4
+ $exe=""
5
+ $pathsep=":"
6
+ $env_node_path=$env:NODE_PATH
7
+ $new_node_path="E:\study\VueComponents\node_modules\.pnpm\typescript@5.8.2\node_modules\typescript\bin\node_modules;E:\study\VueComponents\node_modules\.pnpm\typescript@5.8.2\node_modules\typescript\node_modules;E:\study\VueComponents\node_modules\.pnpm\typescript@5.8.2\node_modules;E:\study\VueComponents\node_modules\.pnpm\node_modules"
8
+ if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {
9
+ # Fix case when both the Windows and Linux builds of Node
10
+ # are installed in the same directory
11
+ $exe=".exe"
12
+ $pathsep=";"
13
+ } else {
14
+ $new_node_path="/mnt/e/study/VueComponents/node_modules/.pnpm/typescript@5.8.2/node_modules/typescript/bin/node_modules:/mnt/e/study/VueComponents/node_modules/.pnpm/typescript@5.8.2/node_modules/typescript/node_modules:/mnt/e/study/VueComponents/node_modules/.pnpm/typescript@5.8.2/node_modules:/mnt/e/study/VueComponents/node_modules/.pnpm/node_modules"
15
+ }
16
+ if ([string]::IsNullOrEmpty($env_node_path)) {
17
+ $env:NODE_PATH=$new_node_path
18
+ } else {
19
+ $env:NODE_PATH="$new_node_path$pathsep$env_node_path"
20
+ }
21
+
22
+ $ret=0
23
+ if (Test-Path "$basedir/node$exe") {
24
+ # Support pipeline input
25
+ if ($MyInvocation.ExpectingInput) {
26
+ $input | & "$basedir/node$exe" "$basedir/../../../../../node_modules/.pnpm/typescript@5.8.2/node_modules/typescript/bin/tsc" $args
27
+ } else {
28
+ & "$basedir/node$exe" "$basedir/../../../../../node_modules/.pnpm/typescript@5.8.2/node_modules/typescript/bin/tsc" $args
29
+ }
30
+ $ret=$LASTEXITCODE
31
+ } else {
32
+ # Support pipeline input
33
+ if ($MyInvocation.ExpectingInput) {
34
+ $input | & "node$exe" "$basedir/../../../../../node_modules/.pnpm/typescript@5.8.2/node_modules/typescript/bin/tsc" $args
35
+ } else {
36
+ & "node$exe" "$basedir/../../../../../node_modules/.pnpm/typescript@5.8.2/node_modules/typescript/bin/tsc" $args
37
+ }
38
+ $ret=$LASTEXITCODE
39
+ }
40
+ $env:NODE_PATH=$env_node_path
41
+ exit $ret
@@ -0,0 +1,17 @@
1
+ #!/bin/sh
2
+ basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
3
+
4
+ case `uname` in
5
+ *CYGWIN*) basedir=`cygpath -w "$basedir"`;;
6
+ esac
7
+
8
+ if [ -z "$NODE_PATH" ]; then
9
+ export NODE_PATH="/mnt/e/study/VueComponents/node_modules/.pnpm/typescript@5.8.2/node_modules/typescript/bin/node_modules:/mnt/e/study/VueComponents/node_modules/.pnpm/typescript@5.8.2/node_modules/typescript/node_modules:/mnt/e/study/VueComponents/node_modules/.pnpm/typescript@5.8.2/node_modules:/mnt/e/study/VueComponents/node_modules/.pnpm/node_modules"
10
+ else
11
+ export NODE_PATH="/mnt/e/study/VueComponents/node_modules/.pnpm/typescript@5.8.2/node_modules/typescript/bin/node_modules:/mnt/e/study/VueComponents/node_modules/.pnpm/typescript@5.8.2/node_modules/typescript/node_modules:/mnt/e/study/VueComponents/node_modules/.pnpm/typescript@5.8.2/node_modules:/mnt/e/study/VueComponents/node_modules/.pnpm/node_modules:$NODE_PATH"
12
+ fi
13
+ if [ -x "$basedir/node" ]; then
14
+ exec "$basedir/node" "$basedir/../../../../../node_modules/.pnpm/typescript@5.8.2/node_modules/typescript/bin/tsserver" "$@"
15
+ else
16
+ exec node "$basedir/../../../../../node_modules/.pnpm/typescript@5.8.2/node_modules/typescript/bin/tsserver" "$@"
17
+ fi
@@ -0,0 +1,12 @@
1
+ @SETLOCAL
2
+ @IF NOT DEFINED NODE_PATH (
3
+ @SET "NODE_PATH=E:\study\VueComponents\node_modules\.pnpm\typescript@5.8.2\node_modules\typescript\bin\node_modules;E:\study\VueComponents\node_modules\.pnpm\typescript@5.8.2\node_modules\typescript\node_modules;E:\study\VueComponents\node_modules\.pnpm\typescript@5.8.2\node_modules;E:\study\VueComponents\node_modules\.pnpm\node_modules"
4
+ ) ELSE (
5
+ @SET "NODE_PATH=E:\study\VueComponents\node_modules\.pnpm\typescript@5.8.2\node_modules\typescript\bin\node_modules;E:\study\VueComponents\node_modules\.pnpm\typescript@5.8.2\node_modules\typescript\node_modules;E:\study\VueComponents\node_modules\.pnpm\typescript@5.8.2\node_modules;E:\study\VueComponents\node_modules\.pnpm\node_modules;%NODE_PATH%"
6
+ )
7
+ @IF EXIST "%~dp0\node.exe" (
8
+ "%~dp0\node.exe" "%~dp0\..\..\..\..\..\node_modules\.pnpm\typescript@5.8.2\node_modules\typescript\bin\tsserver" %*
9
+ ) ELSE (
10
+ @SET PATHEXT=%PATHEXT:;.JS;=;%
11
+ node "%~dp0\..\..\..\..\..\node_modules\.pnpm\typescript@5.8.2\node_modules\typescript\bin\tsserver" %*
12
+ )
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env pwsh
2
+ $basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent
3
+
4
+ $exe=""
5
+ $pathsep=":"
6
+ $env_node_path=$env:NODE_PATH
7
+ $new_node_path="E:\study\VueComponents\node_modules\.pnpm\typescript@5.8.2\node_modules\typescript\bin\node_modules;E:\study\VueComponents\node_modules\.pnpm\typescript@5.8.2\node_modules\typescript\node_modules;E:\study\VueComponents\node_modules\.pnpm\typescript@5.8.2\node_modules;E:\study\VueComponents\node_modules\.pnpm\node_modules"
8
+ if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {
9
+ # Fix case when both the Windows and Linux builds of Node
10
+ # are installed in the same directory
11
+ $exe=".exe"
12
+ $pathsep=";"
13
+ } else {
14
+ $new_node_path="/mnt/e/study/VueComponents/node_modules/.pnpm/typescript@5.8.2/node_modules/typescript/bin/node_modules:/mnt/e/study/VueComponents/node_modules/.pnpm/typescript@5.8.2/node_modules/typescript/node_modules:/mnt/e/study/VueComponents/node_modules/.pnpm/typescript@5.8.2/node_modules:/mnt/e/study/VueComponents/node_modules/.pnpm/node_modules"
15
+ }
16
+ if ([string]::IsNullOrEmpty($env_node_path)) {
17
+ $env:NODE_PATH=$new_node_path
18
+ } else {
19
+ $env:NODE_PATH="$new_node_path$pathsep$env_node_path"
20
+ }
21
+
22
+ $ret=0
23
+ if (Test-Path "$basedir/node$exe") {
24
+ # Support pipeline input
25
+ if ($MyInvocation.ExpectingInput) {
26
+ $input | & "$basedir/node$exe" "$basedir/../../../../../node_modules/.pnpm/typescript@5.8.2/node_modules/typescript/bin/tsserver" $args
27
+ } else {
28
+ & "$basedir/node$exe" "$basedir/../../../../../node_modules/.pnpm/typescript@5.8.2/node_modules/typescript/bin/tsserver" $args
29
+ }
30
+ $ret=$LASTEXITCODE
31
+ } else {
32
+ # Support pipeline input
33
+ if ($MyInvocation.ExpectingInput) {
34
+ $input | & "node$exe" "$basedir/../../../../../node_modules/.pnpm/typescript@5.8.2/node_modules/typescript/bin/tsserver" $args
35
+ } else {
36
+ & "node$exe" "$basedir/../../../../../node_modules/.pnpm/typescript@5.8.2/node_modules/typescript/bin/tsserver" $args
37
+ }
38
+ $ret=$LASTEXITCODE
39
+ }
40
+ $env:NODE_PATH=$env_node_path
41
+ exit $ret
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@havue/ws-video-manager",
3
+ "version": "1.0.0",
4
+ "description": "Javascript class for websocket video manager",
5
+ "keywords": [
6
+ "havue",
7
+ "websocket",
8
+ "video",
9
+ "fmp4"
10
+ ],
11
+ "license": "MIT",
12
+ "scripts": {
13
+ "build": "vite build --mode package"
14
+ },
15
+ "homepage": "https://happypedestrian.github.io/havue/guide/",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/HappyPedestrian/havue.git"
19
+ },
20
+ "dependencies": {
21
+ "@havue/shared": "workspace:^",
22
+ "@vueuse/core": "^11.0.3"
23
+ },
24
+ "publishConfig": {
25
+ "access": "public",
26
+ "registry": "https://registry.npmjs.org/"
27
+ },
28
+ "files": [
29
+ "dist"
30
+ ],
31
+ "main": "./dist/ws-video-manager.umd.js",
32
+ "module": "./dist/ws-video-manager.mjs",
33
+ "types": "./dist/types/src/index.d.ts",
34
+ "exports": {
35
+ ".": {
36
+ "require": "./dist/ws-video-manager.umd.js",
37
+ "import": "./dist/ws-video-manager.mjs",
38
+ "types": "./dist/types/src/index.d.ts"
39
+ }
40
+ }
41
+ }
@@ -0,0 +1,357 @@
1
+ import type { Ref, MaybeRef } from 'vue'
2
+ import type { RenderConstructorOptionType, VideoInfo } from '../render'
3
+ import { WsVideoManagerEventEnums, type WsVideoManager } from '../manager'
4
+ import { ref, computed, onBeforeUnmount, toValue, isRef, watch } from 'vue'
5
+ import { useElementVisibility, useResizeObserver } from '@vueuse/core'
6
+ import wsVideoPlayer from '../index'
7
+ import { AudioState, VideoState } from '../render'
8
+
9
+ export type CanvasResizeOption = {
10
+ /** 是否启用自动更新canvas width 和 height属性,默认为true */
11
+ enable?: boolean
12
+ /** 设置canvas width 和 height时,
13
+ * 缩放的比例,即元素实际尺寸乘以scale,
14
+ * 放大是为了画面更清晰
15
+ * 默认 1
16
+ */
17
+ scale?: number
18
+ /** 限制canvas width最大值,默认1920 */
19
+ maxWidth?: number
20
+ /** 限制canvas height最大值,默认1080 */
21
+ maxHeight?: number
22
+ }
23
+
24
+ export type ParamsOptions = {
25
+ /** websocket 地址 */
26
+ wsUrl: MaybeRef<string | undefined>
27
+ /** 是否播放视频 */
28
+ isReady: MaybeRef<boolean>
29
+ /** 使用的WsVideoManager 实例 默认为wsVideoPlayer */
30
+ wsVideoPlayerIns?: WsVideoManager
31
+ /** 视频渲染到的canvas元素, 不传会返回一个元素引用变量:canvasRef */
32
+ target?: MaybeRef<HTMLCanvasElement | undefined>
33
+ /** 是否自动更新canvas width和height属性的配置, 默认为 DEFAULT_RESIZE_OPTIONS */
34
+ canvasResize?: MaybeRef<CanvasResizeOption | undefined>
35
+ /** 视口中元素不可见时断开连接, 默认为true */
36
+ closeOnHidden?: MaybeRef<boolean>
37
+ /** 自定义Render配置 */
38
+ renderOptions?: MaybeRef<Partial<RenderConstructorOptionType>>
39
+ }
40
+
41
+ // canvasResize 默认值
42
+ export const DEFAULT_RESIZE_OPTIONS = Object.freeze({
43
+ enable: true,
44
+ scale: 1,
45
+ maxWidth: 1920,
46
+ maxHeight: 1080
47
+ })
48
+
49
+ export type ReturnType = {
50
+ /** canvas引用 */
51
+ canvasRef: Ref<HTMLCanvasElement | undefined>
52
+ /** 是否静音 */
53
+ isMuted: Ref<boolean>
54
+ /** 是否暂停 */
55
+ isPaused: Ref<boolean>
56
+ /** 视频信息 */
57
+ videoInfo: Ref<VideoInfo>
58
+ /** 已经连接的WebSocket地址列表 */
59
+ linkedWsUrlList: Ref<string[]>
60
+ /** 视频流地址是否已添加 */
61
+ isLinked: Ref<boolean>
62
+ /** 是否达到websocket拉流数最大值 */
63
+ isReachConnectLimit: Ref<boolean>
64
+ /** 暂停其他WebSocket视频流的音频播放 */
65
+ pauseOtherAudio: () => void
66
+ /** 设置当前WebSocket视频流的音频是否暂停 */
67
+ setAudioMutedState: (muted: boolean) => void
68
+ /** 暂停其他WebSocket视频流的视频播放 */
69
+ pauseOtherVideo: () => void
70
+ /** 设置当前WebSocket视频流的视频是否暂停 */
71
+ setOneVideoPausedState: (paused: boolean) => void
72
+ /** 设置所有WebSocket视频流的视频是否暂停 */
73
+ setAllVideoPausedState: (paused: boolean) => void
74
+ /** 刷新当前WebSocket视频流的时间,如果连接断开会进行重连 */
75
+ refresh: () => void
76
+ }
77
+
78
+ /**
79
+ * websocket视频流播放
80
+ * @param {ParamsOptions} options 配置项
81
+ * @returns
82
+ */
83
+ export function useVideoPlay(options: ParamsOptions): ReturnType {
84
+ let canvasRef: Ref<HTMLCanvasElement | undefined> = ref<HTMLCanvasElement>()
85
+
86
+ const {
87
+ wsUrl,
88
+ isReady,
89
+ target,
90
+ wsVideoPlayerIns = wsVideoPlayer,
91
+ canvasResize,
92
+ closeOnHidden,
93
+ renderOptions
94
+ } = options
95
+
96
+ if (target) {
97
+ canvasRef = computed<HTMLCanvasElement | undefined>(() => {
98
+ return isRef(target) ? toValue(target) : target
99
+ })
100
+ }
101
+
102
+ /** 是否可添加到WsViderPlayer中 */
103
+ const _isReady = computed<boolean>(() => {
104
+ return isRef(isReady) ? toValue(isReady) : isReady
105
+ })
106
+
107
+ /** 预监WebSocket地址 */
108
+ const previewWsUrl = computed<string>(() => {
109
+ const url = wsUrl
110
+ const _wsUrl = (isRef(url) ? toValue(url) : url) || ''
111
+ return _wsUrl
112
+ })
113
+
114
+ const _canvasResizeOpt = computed(() => {
115
+ const canvasResizeOpt = isRef(canvasResize) ? toValue(canvasResize) : canvasResize || {}
116
+
117
+ const opt = Object.assign({}, DEFAULT_RESIZE_OPTIONS, canvasResizeOpt || {})
118
+ return opt
119
+ })
120
+
121
+ const _closeOnHidden = computed<boolean>(() => {
122
+ const closeOpt = isRef(closeOnHidden) ? toValue(closeOnHidden) : closeOnHidden
123
+ return closeOpt === undefined ? true : closeOpt
124
+ })
125
+
126
+ const _renderOptions = computed<Partial<RenderConstructorOptionType> | undefined>(() => {
127
+ const renderOpt = isRef(renderOptions) ? toValue(renderOptions) : renderOptions || undefined
128
+
129
+ return renderOpt
130
+ })
131
+
132
+ /** 是否静音 */
133
+ const isMuted = ref(true)
134
+ /** 视频是否暂停播放 */
135
+ const isPaused = ref(false)
136
+ const videoInfo = ref<VideoInfo>({
137
+ width: 0,
138
+ height: 0
139
+ })
140
+ /** 上一次播放使用的url */
141
+ const lastPreviewUrl = ref<string>()
142
+ /** 已连接的websocket地址 */
143
+ const linkedWsUrlList = ref<string[]>([...wsVideoPlayer.linkedUrlList])
144
+
145
+ /** 预监地址是否已添加 */
146
+ const isLinked = computed(() => {
147
+ return linkedWsUrlList.value.includes(previewWsUrl.value)
148
+ })
149
+
150
+ const connectLimit = wsVideoPlayer.connectLimit
151
+
152
+ /** 达到websocket拉流数最大值 */
153
+ const isReachConnectLimit = computed(() => {
154
+ return linkedWsUrlList.value.length >= connectLimit
155
+ })
156
+
157
+ function handleWsUrlChange(urls: string[]) {
158
+ linkedWsUrlList.value = [...urls]
159
+ }
160
+
161
+ function handleAudioStateChange(url: string, state: AudioState) {
162
+ if (url === previewWsUrl.value) {
163
+ console.log('音频状态更改', url, state)
164
+ isMuted.value = state === AudioState.MUTED
165
+ }
166
+ }
167
+
168
+ function handleVideoStateChange(url: string, state: VideoState) {
169
+ if (url === previewWsUrl.value) {
170
+ console.log('视频状态更改', url, state)
171
+ isPaused.value = state === VideoState.PAUSE
172
+ }
173
+ }
174
+
175
+ function handleVideoInfoUpdate(url: string, info: VideoInfo) {
176
+ if (url === previewWsUrl.value) {
177
+ videoInfo.value = {
178
+ ...info
179
+ }
180
+ }
181
+ }
182
+
183
+ wsVideoPlayer.on(WsVideoManagerEventEnums.WS_URL_CHANGE, handleWsUrlChange)
184
+
185
+ wsVideoPlayer.on(WsVideoManagerEventEnums.AUDIO_STATE_CHANGE, handleAudioStateChange)
186
+
187
+ wsVideoPlayer.on(WsVideoManagerEventEnums.VIDEO_STATE_CHANGE, handleVideoStateChange)
188
+
189
+ wsVideoPlayer.on(WsVideoManagerEventEnums.VIDEO_INFO_UPDATE, handleVideoInfoUpdate)
190
+
191
+ /** canvas在视口中 */
192
+ const canvasIsVisible = useElementVisibility(canvasRef)
193
+
194
+ let stopResizeObserver: () => void = () => {}
195
+
196
+ watch(
197
+ _canvasResizeOpt,
198
+ (val) => {
199
+ stopResizeObserver && stopResizeObserver()
200
+ if (val.enable) {
201
+ /** 监听尺寸变化,更新canvas width/height */
202
+ const { stop } = useResizeObserver(canvasRef, (entries) => {
203
+ if (!canvasRef.value) {
204
+ return
205
+ }
206
+ const [entry] = entries
207
+ const { width, height } = entry.contentRect
208
+ const { scale, maxWidth, maxHeight } = _canvasResizeOpt.value
209
+
210
+ // 乘以scale
211
+ let comWidth = width * scale
212
+ let comHeight = height * scale
213
+
214
+ /**
215
+ * 如果超出最大值,设置为
216
+ * 能被maxWidth*maxHeight的矩形中能包含的
217
+ * 最大矩形宽高, (保持canvas宽高比)
218
+ */
219
+ const canvasRate = width / height
220
+ if (comWidth > maxWidth || comHeight > maxHeight) {
221
+ const optionRate = maxWidth / maxHeight
222
+
223
+ comWidth = canvasRate > optionRate ? maxWidth : maxHeight * canvasRate
224
+ comHeight = canvasRate > optionRate ? maxWidth / canvasRate : maxHeight
225
+ }
226
+ // 限制最大值
227
+ canvasRef.value.width = comWidth
228
+ canvasRef.value.height = comHeight
229
+ })
230
+ stopResizeObserver = stop
231
+ }
232
+ },
233
+ {
234
+ immediate: true,
235
+ deep: true
236
+ }
237
+ )
238
+
239
+ watch(
240
+ _renderOptions,
241
+ () => {
242
+ if (_renderOptions.value && isLinked.value) {
243
+ wsVideoPlayerIns.updateRenderOptions(previewWsUrl.value, _renderOptions.value)
244
+ }
245
+ },
246
+ {
247
+ deep: true
248
+ }
249
+ )
250
+
251
+ onBeforeUnmount(() => {
252
+ stopResizeObserver()
253
+ wsVideoPlayer.off(WsVideoManagerEventEnums.WS_URL_CHANGE, handleWsUrlChange)
254
+
255
+ wsVideoPlayer.off(WsVideoManagerEventEnums.AUDIO_STATE_CHANGE, handleAudioStateChange)
256
+
257
+ wsVideoPlayer.off(WsVideoManagerEventEnums.VIDEO_STATE_CHANGE, handleVideoStateChange)
258
+
259
+ wsVideoPlayer.off(WsVideoManagerEventEnums.VIDEO_INFO_UPDATE, handleVideoInfoUpdate)
260
+ if (!canvasRef.value) return
261
+ // 删除收集的 canvas
262
+ wsVideoPlayerIns.removeCanvas(canvasRef.value)
263
+ isMuted.value = true
264
+ })
265
+
266
+ const canPreview = computed(() => {
267
+ if (_closeOnHidden.value) {
268
+ return canvasIsVisible.value && _isReady.value && previewWsUrl.value
269
+ }
270
+ return _isReady.value && previewWsUrl.value
271
+ })
272
+
273
+ watch([canvasRef, canPreview, linkedWsUrlList, previewWsUrl], () => {
274
+ if (!canvasRef.value) {
275
+ return
276
+ }
277
+ if (canPreview.value) {
278
+ // 如果预监地址更改,移除canvas
279
+ if (
280
+ lastPreviewUrl.value &&
281
+ previewWsUrl.value !== lastPreviewUrl.value &&
282
+ wsVideoPlayerIns.isCanvasExist(canvasRef.value)
283
+ ) {
284
+ wsVideoPlayerIns.removeCanvas(canvasRef.value)
285
+ }
286
+
287
+ if (!wsVideoPlayerIns.isCanvasExist(canvasRef.value)) {
288
+ // 新增canvas
289
+ wsVideoPlayerIns.addCanvas(canvasRef.value, previewWsUrl.value, _renderOptions.value)
290
+ lastPreviewUrl.value = previewWsUrl.value
291
+ }
292
+ } else {
293
+ if (wsVideoPlayerIns.isCanvasExist(canvasRef.value)) {
294
+ // 移除canvas
295
+ wsVideoPlayerIns.removeCanvas(canvasRef.value)
296
+ isMuted.value = true
297
+ isPaused.value = false
298
+ }
299
+ }
300
+ })
301
+
302
+ /** 播放当前音乐,静音其他音乐 */
303
+ function pauseOtherAudio() {
304
+ wsVideoPlayer.playOneAudio(previewWsUrl.value)
305
+ }
306
+
307
+ /**
308
+ * 设置当前视频音乐静音状态
309
+ * @param muted 是否静音
310
+ */
311
+ function setAudioMutedState(muted: boolean) {
312
+ wsVideoPlayer.setOneMutedState(previewWsUrl.value, muted)
313
+ }
314
+
315
+ /**
316
+ * 只播放此视频,其他暂停
317
+ */
318
+ function pauseOtherVideo() {
319
+ wsVideoPlayer.playOneVideo(previewWsUrl.value)
320
+ }
321
+
322
+ /**
323
+ * 设置此视频是否暂停播放
324
+ * @param {boolean} paused 是否暂停播放
325
+ */
326
+ function setOneVideoPausedState(paused: boolean) {
327
+ wsVideoPlayer.setOneVideoPausedState(previewWsUrl.value, paused)
328
+ }
329
+
330
+ /**
331
+ * 设置所有视频是否暂停播放
332
+ * @param {boolean} paused 是否暂停播放
333
+ */
334
+ function setAllVideoPausedState(paused: boolean) {
335
+ wsVideoPlayer.setAllVideoPausedState(paused)
336
+ }
337
+
338
+ const refresh = () => {
339
+ wsVideoPlayer.refresh(previewWsUrl.value)
340
+ }
341
+
342
+ return {
343
+ canvasRef,
344
+ isMuted,
345
+ isPaused,
346
+ videoInfo,
347
+ linkedWsUrlList,
348
+ isLinked,
349
+ isReachConnectLimit,
350
+ pauseOtherAudio,
351
+ setAudioMutedState,
352
+ pauseOtherVideo,
353
+ setOneVideoPausedState,
354
+ setAllVideoPausedState,
355
+ refresh
356
+ }
357
+ }
@@ -0,0 +1,6 @@
1
+ export * from './manager'
2
+ export * from './render'
3
+
4
+ import { WsVideoManager } from './manager'
5
+
6
+ export default new WsVideoManager()
@@ -0,0 +1,3 @@
1
+ import WebSocketLoader from './websocket-loader'
2
+
3
+ export { WebSocketLoader }