1- import * as StreamIO from '@ezuikit/stream-io' ;
2- import StreamIO__default from '@ezuikit/stream-io' ;
3- import * as I18n from '@ezuikit/utils-i18n' ;
4- import I18n__default from '@ezuikit/utils-i18n' ;
51import * as _ezuikit_utils_service_dist_types_fetch from '@ezuikit/utils-service/dist/types/fetch' ;
62import { LoggerCls } from '@ezuikit/utils-logger/dist/types/logger' ;
73import { LoggerOptions } from '@ezuikit/utils-logger' ;
4+ import * as I18n from '@ezuikit/utils-i18n' ;
5+ import I18n__default from '@ezuikit/utils-i18n' ;
86import Service , { DeviceCapacityRes , DeviceInfoRes } from '@ezuikit/utils-service' ;
97import { EzopenURL } from '@ezuikit/utils-tools' ;
10- import { PlayerPluginRecord } from '@ezuikit/player-plugin-record' ;
118import EventEmitter from 'eventemitter3' ;
9+ import { PlayerPluginRecord } from '@ezuikit/player-plugin-record' ;
1210
1311/**
1412 * 环境
@@ -55,7 +53,7 @@ interface PlayerOptions {
5553 */
5654 streamInfoCBType : 0 | 1 ;
5755}
58- interface IResult < T > {
56+ interface IResult$1 < T > {
5957 data ?: T ;
6058 code ?: number ;
6159 msg ?: string ;
@@ -111,6 +109,127 @@ interface IBufferItem {
111109 duration : number ;
112110}
113111
112+ interface IResult < T > {
113+ data ?: T ;
114+ code ?: number ;
115+ msg ?: string ;
116+ }
117+ /**
118+ * 播放器标准接口
119+ */
120+ interface PlayerInterface extends EventEmitter {
121+ playing : boolean ;
122+ volume : number ;
123+ playbackRate : number ;
124+ deviceCapacity : Record < string , any > ;
125+ i18n : any ;
126+ logger : any ;
127+ event : EventEmitter ;
128+ wasmplayer : any ;
129+ _wss_info : any ;
130+ _options : any ;
131+ /**
132+ * 播放
133+ * @param options
134+ * @returns {Promise }
135+ */
136+ play : ( options ?: any ) => Promise < unknown > ;
137+ /**
138+ * 暂停播放
139+ * @returns
140+ */
141+ pause : ( bool ?: boolean ) => Promise < unknown > ;
142+ /**
143+ * 销毁并断流
144+ * @returns
145+ */
146+ destroy : ( ) => Promise < unknown > ;
147+ /**
148+ * 截图
149+ * @param {string } name 文件名 默认时间戳(new Date().getTime())
150+ * @param {"png" | "jpeg" } fmt 图片格式
151+ * @param {"base64" } type 文件格式 默认base64
152+ * @param {boolean } download 是否直接下载 默认不直接下载
153+ * @returns 返回base64字符
154+ */
155+ snapshot : ( name ?: string , fmt ?: 'jpeg' , type ?: 'base64' , download ?: boolean ) => Promise < IResult < {
156+ fileName ?: string ;
157+ base64 ?: string ;
158+ } | null > > ;
159+ /**
160+ * 开始录制视频
161+ * @param {string } name 文件名 默认时间戳(new Date().getTime())
162+ * @param {"mp4" } fmt 图片格式 默认mp4
163+ * @returns
164+ */
165+ startRecord ?: ( name ?: string , fmt ?: 'mp4' ) => Promise < any > ;
166+ /**
167+ * 停止录制
168+ * @returns
169+ */
170+ stopRecord ?: ( ) => Promise < any > ;
171+ /**
172+ * 全屏
173+ * @returns
174+ */
175+ fullScreen : ( ) => Promise < void > ;
176+ /**
177+ * 退出全屏
178+ * @returns
179+ */
180+ exitScreen : ( ) => Promise < void > ;
181+ /**
182+ * 设置画布/视频的尺寸 不设置 默认使用容器的高宽(充满容器)
183+ * @param {number= } width 画布的宽度
184+ * @param {number= } height 画布的高度
185+ * @returns
186+ */
187+ resize : ( width ?: number , height ?: number ) => Promise < {
188+ width : number ;
189+ height : number ;
190+ } > ;
191+ /**
192+ * 设置音量
193+ * @param volume 音量 [0-1], 0:表示静音
194+ * @returns {void }
195+ */
196+ setVolume : ( volume : number ) => void ;
197+ /**
198+ * 设置封面
199+ * @param url
200+ * @returns
201+ */
202+ setPoster ?: ( postUrl : string ) => void ;
203+ /**
204+ * 设置播放速度
205+ * @param rate
206+ * @returns
207+ */
208+ setPlaybackRate ?: ( rate : number ) => void ;
209+ /**
210+ * 当前版本号
211+ * @returns
212+ */
213+ getVersion : ( ) => object ;
214+ /**
215+ * 设置日志打印的级别 INFO | LOG | WARN | ERROR
216+ *
217+ *
218+ * @param {string } level 日志级别 一次从大到小 3 -> 0 (为了更好的扩展)
219+ * @returns
220+ */
221+ setDebug ?: ( level : 'INFO' | 'LOG' | 'WARN' | 'ERROR' ) => void ;
222+ }
223+
224+ interface PlayerPlugin {
225+ name : string ;
226+ init ?: ( player ?: PlayerInterface ) => void ;
227+ beforeExec ?: ( player ?: PlayerInterface ) => boolean | Promise < boolean > ;
228+ exec : ( player ?: PlayerInterface ) => void ;
229+ afterExec ?: ( player ?: PlayerInterface ) => void ;
230+ destroy ?: ( player ?: PlayerInterface ) => void ;
231+ }
232+
114233declare class ESCanvas {
115234 constructor ( szCanvasId : any ) ;
116235 m_iCanvasWidth : any ;
@@ -464,32 +583,32 @@ interface WasmDecoderStatue {
464583 bSupHardOrSoft : boolean ;
465584 bSupHardDecAVC : boolean ;
466585 bSupHardDecHEVC : boolean ;
467- cmd : " loaded" | " onebyone" ;
586+ cmd : ' loaded' | ' onebyone' ;
468587 errorCode : number ;
469588 status : any ;
470589}
471590
472591type Zoom3DCallback = ( oRECT ?: any ) => void ;
473592
474- type SnapshotFmt = " jpeg" ;
593+ type SnapshotFmt = ' jpeg' ;
475594
476595/**
477596 * @description 插件管理系统
478597 */
479598declare class PluginManager {
480599 context : EZopenPlayer ;
481- plugins : Map < string , PlayerPluginRecord > ;
600+ plugins : Map < string , PlayerPlugin > ;
482601 constructor ( player : EZopenPlayer ) ;
483602 /**
484603 * @description 注册插件做个插件
485604 * @param plugins
486605 */
487- usePlugins ( plugins : PlayerPluginRecord [ ] ) : Promise < void > ;
606+ usePlugins ( plugins : PlayerPlugin [ ] ) : Promise < void > ;
488607 /**
489608 * @description 注册插件
490609 * @param plugins
491610 */
492- use ( plugin : PlayerPluginRecord ) : Promise < void > ;
611+ use ( plugin : PlayerPlugin ) : Promise < void > ;
493612 /**
494613 * @description 通过name销毁指定插件
495614 * @param {string } name 插件名
@@ -646,7 +765,7 @@ interface EZopenPlayerOptions extends PlayerOptions {
646765 /** 全屏节点 */
647766 fullScreenEle ?: HTMLElement ;
648767 /** 指定解码类型, v1 软解 v3 包括硬解和多线程 */
649- decoderType ?: " auto" | "v1" | "v3" ;
768+ decoderType ?: ' auto' | 'v1' | 'v3' ;
650769 /** 下载当前原始视频流,用于调试,不能动态设置,结束或销毁播放时自动保存成文件并下载 */
651770 debugDownloadData ?: boolean ;
652771 extraParams ?: {
@@ -663,7 +782,7 @@ interface EZopenPlayerOptions extends PlayerOptions {
663782 isLive ?: boolean ;
664783}
665784declare class EZopenPlayer extends EventEmitter {
666- _options : EZopenPlayerOptions | undefined ;
785+ _options : EZopenPlayerOptions ;
667786 static EVENT_TYPE : {
668787 initializing : string ;
669788 loadstart : string ;
@@ -743,6 +862,7 @@ declare class EZopenPlayer extends EventEmitter {
743862 */
744863 event : any ;
745864 isHls : boolean ;
865+ isLive : boolean ;
746866 initializing : boolean ;
747867 loading : boolean ;
748868 /** 播放速度 */
@@ -765,11 +885,7 @@ declare class EZopenPlayer extends EventEmitter {
765885 $container : HTMLElement ;
766886 esCanvas : ESCanvas ;
767887 fECCorrect : FECCorrect ;
768- /** 当前播放时间,单位秒 */
769- currentTime : number ;
770- /** 视频总时长,单位秒 */
771- duration : number ;
772- _oStreamClient : StreamIO__default ;
888+ _oStreamClient : StreamClient ;
773889 _aHead : Uint8Array ;
774890 /** @private */
775891 _detectTimer : any ;
@@ -811,7 +927,7 @@ declare class EZopenPlayer extends EventEmitter {
811927 * @param options
812928 * @returns
813929 */
814- play ( options ?: Partial < Pick < EZopenPlayerOptions , " url" | " accessToken" > > ) : Promise < unknown > ;
930+ play ( options ?: Partial < Pick < EZopenPlayerOptions , ' url' | ' accessToken' > > ) : Promise < unknown > ;
815931 _wss_play ( szUrl : string , oParams ?: {
816932 playURL : string ;
817933 } ) : Promise < unknown > ;
@@ -846,7 +962,7 @@ declare class EZopenPlayer extends EventEmitter {
846962 * @param {boolean } canvas 是否使用 canvas
847963 * @returns 返回base64字符
848964 */
849- snapshot ( name ?: string , fmt ?: SnapshotFmt , type ?: " base64" , download ?: boolean , canvas ?: boolean ) : Promise < IResult < {
965+ snapshot ( name ?: string , fmt ?: SnapshotFmt , type ?: ' base64' , download ?: boolean , canvas ?: boolean ) : Promise < IResult$1 < {
850966 fileName ?: string | undefined ;
851967 base64 ?: string | undefined ;
852968 } | null > > ;
@@ -857,7 +973,7 @@ declare class EZopenPlayer extends EventEmitter {
857973 * @param {boolean } download 是否直接下载 默认不直接下载 false
858974 * @returns 返回base64字符
859975 */
860- snapshotByCanvas ( name ?: string , fmt ?: SnapshotFmt , download ?: boolean ) : Promise < IResult < {
976+ snapshotByCanvas ( name ?: string , fmt ?: SnapshotFmt , download ?: boolean ) : Promise < IResult$1 < {
861977 fileName ?: string | undefined ;
862978 base64 ?: string | undefined ;
863979 } | null > > ;
@@ -893,7 +1009,7 @@ declare class EZopenPlayer extends EventEmitter {
8931009 * @description 插件管理
8941010 * @param plugin 插件
8951011 */
896- use ( plugin : typeof PlayerPluginRecord ) : void ;
1012+ use ( plugin : PlayerPlugin ) : void ;
8971013 /**
8981014 *
8991015 * @param {Object } type 矫正类型 参考 src/ezopen/constants.js
@@ -952,7 +1068,7 @@ declare class EZopenPlayer extends EventEmitter {
9521068 */
9531069 disable3DZoom ( ) : number ;
9541070 /**
955- * @description 获取当前osd (时间戳) , 当获取失败返回 0
1071+ * @description 获取当前osd, 当获取失败返回 0
9561072 * @returns {number }
9571073 */
9581074 getOSDTime ( ) : number ;
@@ -963,7 +1079,6 @@ declare class EZopenPlayer extends EventEmitter {
9631079 getFrameInfo ( ) : IFrameInfo ;
9641080 /**
9651081 * @description 设置播放视频区域 (仅视频不是画布)
966- * @deprecated
9671082 * @param {number } left 视频展示区域 x轴开始位置
9681083 * @param {number } right 视频展示区域 x轴结束位置
9691084 * @param {number } top 视频展示区域 y轴开始位置
@@ -983,7 +1098,7 @@ declare class EZopenPlayer extends EventEmitter {
9831098 *
9841099 * @returns
9851100 */
986- getOptions ( ) : EZopenPlayerOptions | undefined ;
1101+ getOptions ( ) : EZopenPlayerOptions ;
9871102 /**
9881103 * @description 切换调试日志等级
9891104 * @param {LoggerOptions } loggerOptions 日志等级
@@ -1034,15 +1149,61 @@ declare class EZopenPlayer extends EventEmitter {
10341149 */
10351150 setStreamInfoCallBackType ( type : 0 | 1 , cb ?: StreamInfoCallBackFn ) : void ;
10361151 _addEventListener ( ) : void ;
1152+ }
1153+
1154+ declare class StreamClient {
1155+ private readonly _player ;
1156+ private _streamClient ;
1157+ _streamUUID : string ;
1158+ constructor ( player : EZopenPlayer ) ;
1159+ private _getStreamClientFactory ;
10371160 /**
1038- * 是否是 hls 直播, 优先使用用户传的值, 如果你没有传值(boolean),则根据 m3u8 的解析结果进行判断
1039- * @returns {boolean }
1161+ * @description 开流, 此时设备的流还没有发出来
1162+ * @param {string } szUrl 取流路径,如ws://hostname:port/channel
1163+ * @param {object } oParams 取流需要涉及的相关参数
1164+ * @param {function } cbMessage 消息回调函数
1165+ * @param {function } cbClose 关闭回调
1166+ * @param {function } cbError 错误回调
1167+ * @returns {Promise<string> } 返回Promise对象 // 取流uuid,用于区分每条取流连接
10401168 */
1041- get isLive ( ) : boolean ;
1169+ openStream ( szUrl : string , oParams : object , cbMessage : ( msg : object ) => void , cbClose : ( id ?: string ) => void , cbError : ( id ?: string , msg ?: any ) => void ) : Promise < string > ;
10421170 /**
1043- * 片段列表
1171+ * @description 开始取流
1172+ *
1173+ * @param {string } id websocket id,在openStream的时候生成
1174+ * @param {string } szStartTime 开始时间
1175+ * @param {string } szStopTime 结束时间
1176+ * @param {function } cbMessage 码流回调函数
1177+ *
1178+ * @returns {Promise<unknown> } 返回Promise对象
10441179 */
1045- get segments ( ) : any ;
1180+ startPlay ( id ?: string ) : Promise < void > ;
1181+ /**
1182+ * @description 设置播放速度
1183+ * @param rate 播放速度
1184+ * @param uuid websocket id,在openStream的时候生成
1185+ * @returns
1186+ */
1187+ setPlayRate ( rate : number , id ?: string ) : Promise < void > ;
1188+ /**
1189+ * @description 定位回放
1190+ *
1191+ * @param {string } id websocket id在openStream的时候生成
1192+ * @param {string } startTime 开始时间
1193+ * @param {string } stopTime 结束时间
1194+ *
1195+ * @returns {Promise<unknown> } Promise
1196+ */
1197+ seek ( startTime : string , stopTime : string , id ?: string ) : Promise < void > ;
1198+ /**
1199+ * @description 停止所有流
1200+ * @returns
1201+ */
1202+ stopAll ( ) : Promise < void > ;
1203+ /**
1204+ * @description 客户端销毁
1205+ */
1206+ destroy ( ) : void ;
10461207}
10471208
10481209declare class JSPlugin {
@@ -1052,20 +1213,18 @@ declare class JSPlugin {
10521213 player : EZopenPlayer ;
10531214 i18n : I18n . default ;
10541215 downloadRecord : any ;
1055- _recordPlugin : any ;
1216+ _recordPlugin : PlayerPluginRecord ;
10561217 nWidth : number ;
10571218 nHeight : number ;
1058- oStreamClient : StreamIO . default ;
1219+ oStreamClient : StreamClient ;
10591220 g_port : number ;
1060- get isHls ( ) : boolean ;
1061- get isLive ( ) : boolean ;
10621221 get bPlay ( ) : boolean ;
10631222 get iRate ( ) : number ;
1064- set playURL ( url : string ) ;
1223+ set playURL ( arg : string ) ;
10651224 get playURL ( ) : string ;
1066- set FECSplitIds ( ids : string | undefined ) ;
1225+ set FECSplitIds ( arg : string | undefined ) ;
10671226 get FECSplitIds ( ) : string | undefined ;
1068- set correctType ( type : any ) ;
1227+ set correctType ( arg : any ) ;
10691228 get correctType ( ) : any ;
10701229 _initEventCallback ( ) : void ;
10711230 JSPlayM4_SetDecodeEngine ( useHard : any ) : void ;
@@ -1102,8 +1261,8 @@ declare class JSPlugin {
11021261 * @returns {none } 无
11031262 */
11041263 JS_Disable3DZoom ( ) : none ;
1105- JS_StartSave ( fileName : string | undefined , stopCallback : any , secretKey : any ) : any ;
1106- JS_StopSave ( download ?: boolean ) : any ;
1264+ JS_StartSave ( fileName : string | undefined , stopCallback : any , secretKey : any ) : Promise < void > ;
1265+ JS_StopSave ( download ?: boolean ) : Promise < unknown > ;
11071266 _JSPlayM4_GetFrameInfo ( ) : IFrameInfo ;
11081267 _JSPlayM4_SetDisplayRegion ( left : any , right : any , top : any , bottom : any , flag : boolean | undefined , isFullScreen : any ) : boolean ;
11091268 JS_CapturePicture ( port : any , fileName : any , format : any , callback : any , download : any , canvas : any ) : Promise < any > ;
0 commit comments