media-av 0.0.13 → 0.0.14

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 (4) hide show
  1. package/LICENSE +20 -20
  2. package/README.md +14 -14
  3. package/index.d.ts +357 -353
  4. package/package.json +1 -1
package/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2023-present, w.w.
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023-present, w.w.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
21
  THE SOFTWARE.
package/README.md CHANGED
@@ -1,15 +1,15 @@
1
- # 本接口需要后台服务端支持
2
-
3
- 1. 支持通过http+flv拉流
4
- 2. 支持通过webrtc接流
5
- 3. 支持软电话,实现音视频呼叫
6
- 4. 支持音视频全双工半/双工呼叫
7
-
8
- 2024/01/26 0.0.13
9
- 1. 新增app代理, 支持音视频全双工/半双工呼叫
10
-
11
- 2023/09/04
12
- 1. 新增广播喊话
13
-
14
- # 使用用例
1
+ # 本接口需要后台服务端支持
2
+
3
+ 1. 支持通过http+flv拉流
4
+ 2. 支持通过webrtc接流
5
+ 3. 支持软电话,实现音视频呼叫
6
+ 4. 支持音视频全双工半/双工呼叫
7
+
8
+ 2024/01/26 0.0.13
9
+ 1. 新增app代理, 支持音视频全双工/半双工呼叫
10
+
11
+ 2023/09/04
12
+ 1. 新增广播喊话
13
+
14
+ # 使用用例
15
15
  https://gitee.com/slad__shang/media-av-demo
package/index.d.ts CHANGED
@@ -1,354 +1,358 @@
1
-
2
- export interface RtspPullSessionListener {
3
- /**
4
- * 错误回调
5
- * @param err{Error}
6
- */
7
- onError(err: Error): void;
8
- /**
9
- * 添加远端媒体流
10
- * @param stream{MediaStream} 媒体流
11
- */
12
- onAddRemoteStream(stream: MediaStream): void;
13
- }
14
-
15
- export interface IRtspPullSession {
16
- /**
17
- * 添加回调监听
18
- * @param listener 监听器
19
- */
20
- setRtspPullSessionListener(listener: RtspPullSessionListener): void;
21
-
22
- /**
23
- * 开始拉流
24
- */
25
- start(): void;
26
-
27
- /**
28
- * 停止拉流
29
- */
30
- stop(): void;
31
- }
32
-
33
- export interface BroadcastSessionListener {
34
-
35
- /**
36
- * 视频推送时会上报
37
- * @param stream
38
- */
39
- onAddLocalStream(stream: MediaStream): void
40
-
41
- /**
42
- * 错误回调
43
- * @param err{Error}
44
- */
45
- onError(err: Error): void
46
- }
47
-
48
- export interface IBroadcastSession {
49
- /**
50
- * 添加回调监听
51
- * @param listener 监听器
52
- */
53
- setBroadcastSessionListener(listener: BroadcastSessionListener): void;
54
-
55
- /**
56
- * 开始广播
57
- */
58
- start(): void;
59
-
60
- /**
61
- * 停止广播
62
- */
63
- stop(): void;
64
- }
65
-
66
- /**
67
- * in 呼入
68
- * out 呼出
69
- */
70
- type CallDirect = "in" | "out";
71
-
72
- /**
73
- * full-duplex 全双工
74
- * half-duplex 半双工(对讲)
75
- */
76
- type CallMode = "full-duplex" | "half-duplex"
77
-
78
- /**
79
- * video 视频
80
- * audio 语音
81
- */
82
- type MediaType = "video" | "audio"
83
-
84
- /**
85
- * -1 离线
86
- * 0 空闲
87
- * 1 呼叫中
88
- * 2 振铃
89
- * 3 通话
90
- */
91
- type SessionStatus = -1 | 0 | 1 | 2 | 3
92
-
93
- export class CallInfo {
94
- /**
95
- * 对方号码
96
- */
97
- tel: string;
98
- /**
99
- * 呼叫媒体类型
100
- */
101
- mediaType: MediaType;
102
- /**
103
- * 呼叫模式
104
- */
105
- callMode: CallMode;
106
- constructor(tel: string, mediaType: MediaType, callMode: CallMode);
107
- }
108
-
109
- /**
110
- * tb_granted 申请话权成功
111
- * tb_taken 其他人申请话权成功
112
- * tb_deny 申请话权失败
113
- * tb_idle 空闲,没有人说话
114
- * tb_revoke 话权被抢
115
- */
116
- type ETbcpType = "tb_granted" | "tb_taken" | "tb_deny" | "tb_idle" | "tb_revoke"
117
-
118
- export interface ITbcpMessage {
119
- /**
120
- * 话权类型
121
- */
122
- type : ETbcpType
123
-
124
- callId ?: string
125
-
126
- /**
127
- * 其他信息
128
- * type -> tb_taken: 申请话权成功之人的号码
129
- * 其他类型暂时不用处理此字段
130
- */
131
- info ?: string
132
- }
133
-
134
- export interface CallSessionListener {
135
- /**
136
- * 初始化结果回调
137
- * @param result true 成功 false 失败
138
- */
139
- onInitResult(result: boolean): void;
140
-
141
- /**
142
- * 对方振铃,呼出时有回调
143
- */
144
- onRing(): void;
145
-
146
- /**
147
- * 对方接听,呼出时有回调
148
- */
149
- onAnswer(): void;
150
- /**
151
- * 1. 呼叫失败
152
- * 2. 呼出时,对方还没有接听前,对方拒绝接听
153
- * 3. 呼入/呼出时,通话接束后,对方挂机
154
- * 4. 呼入时,还没有接听,对方取消呼叫
155
- * @param reason 挂机原因
156
- */
157
- onHangup(reason?: Number): void;
158
-
159
- /**
160
- * 收到对方呼入电话
161
- * @param callInfo 呼入信息
162
- */
163
- onNewCall(callInfo: CallInfo): void;
164
-
165
- /**
166
- * 呼叫过程发生错误
167
- * @param err 错误原因
168
- */
169
- onError(err: Error): void;
170
-
171
- /**
172
- * 添加本地视频流,视频呼叫时收到
173
- * 建议video标签静音,不然会听到自己的声音
174
- * @param stream
175
- */
176
- onAddRemoteStream(stream: MediaStream): void;
177
-
178
- /**
179
- * 添加远端音视频流
180
- * @param stream
181
- */
182
- onAddLocalStream(stream: MediaStream): void;
183
-
184
- /**
185
- * 会话连接关闭
186
- * @param reason 关闭原因
187
- */
188
- onClose(reason: Error): void;
189
- }
190
-
191
- export interface AppCallSessionListener extends CallSessionListener {
192
- /**
193
- * 话权消息回调
194
- * @param msg
195
- */
196
- onTbcpMessage(msg: ITbcpMessage): void
197
- }
198
-
199
- export interface ICallSession {
200
- /**
201
- * 本会话的号码
202
- */
203
- readonly tel: string;
204
-
205
- /**
206
- * 会话当前状态
207
- */
208
- readonly status: SessionStatus;
209
-
210
- /**
211
- * 会话呼叫类型
212
- */
213
- readonly mediaType: MediaType;
214
-
215
- /**
216
- * 会话呼叫方向
217
- */
218
- readonly callDirect: CallDirect;
219
-
220
- /**
221
- * 设置回调监听
222
- * @param listener 监听器
223
- */
224
- setCallSessionListener(listener: CallSessionListener): void;
225
-
226
- /**
227
- * 初始化
228
- */
229
- init(): void;
230
-
231
- /**
232
- * 发起呼叫
233
- * @param called 要呼叫的号码
234
- * @param mediaType 呼叫类型
235
- * @param callMode 呼叫模式
236
- */
237
- makeCall(called: string, mediaType?: MediaType, callMode?: CallMode): void;
238
-
239
- /**
240
- * 应答
241
- */
242
- answer(): void;
243
-
244
- /**
245
- * 挂机/拒绝接听
246
- */
247
- hangup(): void;
248
-
249
- /**
250
- * 发送dtmf
251
- * @param dtmf{string} 要发送的按键值 0-9 * #
252
- */
253
- dtmf(dtmf: string): boolean;
254
-
255
- /**
256
- * 转换前后置摄像头
257
- * @returns {Promise<string>}
258
- * @constructor
259
- */
260
- changeCamera(): Promise<string>;
261
-
262
- /**
263
- * 改变麦克风状态
264
- * @returns {Promise<boolean>}
265
- * @constructor
266
- */
267
- changeMuted(): Promise<boolean>;
268
-
269
- /**
270
- * 改变本地摄像头状态, 打开或关闭本地摄像头
271
- * @returns {Promise<boolean>}
272
- * @constructor
273
- */
274
- changeCameraOpened(): Promise<boolean>;
275
-
276
- /**
277
- * 注销
278
- */
279
- destroy():void;
280
- }
281
-
282
- export interface IAppCallSession extends ICallSession {
283
- /**
284
- * 会话呼叫模式
285
- */
286
- readonly callMode: CallMode;
287
-
288
- /**
289
- * 设置回调监听
290
- * @param listener 监听器
291
- */
292
- setCallSessionListener(listener: AppCallSessionListener): void;
293
-
294
- /**
295
- * 发起语音对讲呼叫
296
- * @param called 要呼叫的号码
297
- */
298
- audioHalfCall(called : string): void
299
-
300
- /**
301
- * 发起视频对讲呼叫
302
- * @param called 要呼叫的号码
303
- */
304
- videoHalfCall(called : string): void
305
-
306
- /**
307
- * 申请话权
308
- */
309
- tbcpRequest(): void;
310
-
311
- /**
312
- * 释放话权
313
- */
314
- tbcpRelease(): void;
315
- }
316
-
317
- /**
318
- * 初始化voip模块
319
- * @param baseUrl{string} ws(s)://ip:port
320
- */
321
- export declare function voipModuleInit(baseUrl: string): void;
322
-
323
- /**
324
- * 创建呼叫会话
325
- * @param tel 本端号码,可为空由服务端随机分配
326
- */
327
- export declare function createCallSession(tel?: string): ICallSession;
328
-
329
- /**
330
- * 创建app会话
331
- * @param tel 账号配置的app号码
332
- * @param accountId 账号id
333
- */
334
- export declare function createAppCallSession(tel:string, accountId:string): IAppCallSession;
335
-
336
- /**
337
- * 初始化video模块
338
- * @param baseUrl{string} http(s)://ip:port
339
- */
340
- export declare function videoModuleInit(baseUrl: string): void;
341
-
342
- /**
343
- * 创建rtsp拉流会话
344
- * @param rtspUrl{string} rtsp地址
345
- */
346
- export declare function createRtspPullSession(rtspUrl: string): IRtspPullSession;
347
-
348
-
349
- /**
350
- * 创建广播会话
351
- * @param tel 广播号码
352
- * @param mediaType 广播类型, 默认 audio
353
- */
1
+
2
+ export interface RtspPullSessionListener {
3
+ /**
4
+ * 错误回调
5
+ * @param err{Error}
6
+ */
7
+ onError(err: Error): void;
8
+ /**
9
+ * 添加远端媒体流
10
+ * @param stream{MediaStream} 媒体流
11
+ */
12
+ onAddRemoteStream(stream: MediaStream): void;
13
+ }
14
+
15
+ export interface IRtspPullSession {
16
+ /**
17
+ * 添加回调监听
18
+ * @param listener 监听器
19
+ */
20
+ setRtspPullSessionListener(listener: RtspPullSessionListener): void;
21
+
22
+ /**
23
+ * 开始拉流
24
+ */
25
+ start(): void;
26
+
27
+ /**
28
+ * 停止拉流
29
+ */
30
+ stop(): void;
31
+ }
32
+
33
+ export interface BroadcastSessionListener {
34
+
35
+ /**
36
+ * 视频推送时会上报
37
+ * @param stream
38
+ */
39
+ onAddLocalStream(stream: MediaStream): void
40
+
41
+ /**
42
+ * 错误回调
43
+ * @param err{Error}
44
+ */
45
+ onError(err: Error): void
46
+ }
47
+
48
+ export interface IBroadcastSession {
49
+ /**
50
+ * 添加回调监听
51
+ * @param listener 监听器
52
+ */
53
+ setBroadcastSessionListener(listener: BroadcastSessionListener): void;
54
+
55
+ /**
56
+ * 开始广播
57
+ */
58
+ start(): void;
59
+
60
+ /**
61
+ * 停止广播
62
+ */
63
+ stop(): void;
64
+ }
65
+
66
+ /**
67
+ * in 呼入
68
+ * out 呼出
69
+ */
70
+ type CallDirect = "in" | "out";
71
+
72
+ /**
73
+ * full-duplex 全双工
74
+ * half-duplex 半双工(对讲)
75
+ */
76
+ type CallMode = "full-duplex" | "half-duplex"
77
+
78
+ /**
79
+ * video 视频
80
+ * audio 语音
81
+ */
82
+ type MediaType = "video" | "audio"
83
+
84
+ /**
85
+ * -1 离线
86
+ * 0 空闲
87
+ * 1 呼叫中
88
+ * 2 振铃
89
+ * 3 通话
90
+ */
91
+ type SessionStatus = -1 | 0 | 1 | 2 | 3
92
+
93
+ export class CallInfo {
94
+ /**
95
+ * 对方号码
96
+ */
97
+ tel: string;
98
+ /**
99
+ * 呼叫媒体类型
100
+ */
101
+ mediaType: MediaType;
102
+ /**
103
+ * 呼叫模式
104
+ */
105
+ callMode: CallMode;
106
+ constructor(tel: string, mediaType: MediaType, callMode: CallMode);
107
+ }
108
+
109
+ /**
110
+ * tb_granted 申请话权成功
111
+ * tb_taken 其他人申请话权成功
112
+ * tb_deny 申请话权失败
113
+ * tb_idle 空闲,没有人说话
114
+ * tb_revoke 话权被抢
115
+ */
116
+ type ETbcpType = "tb_granted" | "tb_taken" | "tb_deny" | "tb_idle" | "tb_revoke"
117
+
118
+ export interface ITbcpMessage {
119
+ /**
120
+ * 话权类型
121
+ */
122
+ type : ETbcpType
123
+
124
+ callId ?: string
125
+
126
+ /**
127
+ * 其他信息
128
+ * type -> tb_taken: 申请话权成功之人的号码
129
+ * 其他类型暂时不用处理此字段
130
+ */
131
+ info ?: string
132
+ }
133
+
134
+ export interface CallSessionListener {
135
+ /**
136
+ * 初始化结果回调
137
+ * @param result true 成功 false 失败
138
+ */
139
+ onInitResult(result: boolean): void;
140
+
141
+ /**
142
+ * 对方振铃,呼出时有回调
143
+ */
144
+ onRing(): void;
145
+
146
+ /**
147
+ * 对方接听,呼出时有回调
148
+ */
149
+ onAnswer(): void;
150
+ /**
151
+ * 1. 呼叫失败
152
+ * 2. 呼出时,对方还没有接听前,对方拒绝接听
153
+ * 3. 呼入/呼出时,通话接束后,对方挂机
154
+ * 4. 呼入时,还没有接听,对方取消呼叫
155
+ * @param reason 挂机原因
156
+ */
157
+ onHangup(reason?: Number): void;
158
+
159
+ /**
160
+ * 收到对方呼入电话
161
+ * @param callInfo 呼入信息
162
+ */
163
+ onNewCall(callInfo: CallInfo): void;
164
+
165
+ /**
166
+ * 呼叫过程发生错误
167
+ * @param err 错误原因
168
+ */
169
+ onError(err: Error): void;
170
+
171
+ /**
172
+ * 添加本地视频流,视频呼叫时收到
173
+ * 建议video标签静音,不然会听到自己的声音
174
+ * @param stream
175
+ */
176
+ onAddRemoteStream(stream: MediaStream): void;
177
+
178
+ /**
179
+ * 添加远端音视频流
180
+ * @param stream
181
+ */
182
+ onAddLocalStream(stream: MediaStream): void;
183
+
184
+ /**
185
+ * 会话连接关闭
186
+ * @param reason 关闭原因
187
+ */
188
+ onClose(reason: Error): void;
189
+ }
190
+
191
+ export interface AppCallSessionListener extends CallSessionListener {
192
+ /**
193
+ * 话权消息回调
194
+ * @param msg
195
+ */
196
+ onTbcpMessage(msg: ITbcpMessage): void
197
+ }
198
+
199
+ export interface ICallSession {
200
+ /**
201
+ * 本会话的号码
202
+ */
203
+ readonly tel: string;
204
+
205
+ /**
206
+ * 会话当前状态
207
+ */
208
+ readonly status: SessionStatus;
209
+
210
+ /**
211
+ * 会话呼叫类型
212
+ */
213
+ readonly mediaType: MediaType;
214
+
215
+ /**
216
+ * 会话呼叫方向
217
+ */
218
+ readonly callDirect: CallDirect;
219
+
220
+ /**
221
+ * 设置回调监听
222
+ * @param listener 监听器
223
+ */
224
+ setCallSessionListener(listener: CallSessionListener): void;
225
+
226
+ /**
227
+ * 初始化
228
+ */
229
+ init(): void;
230
+
231
+ /**
232
+ * 发起语音呼叫
233
+ * @param called 要呼叫的号码
234
+ */
235
+ audioCall(called : string): void
236
+
237
+ /**
238
+ * 发起视频呼叫
239
+ * @param called 要呼叫的号码
240
+ */
241
+ videoCall(called : string): void
242
+
243
+ /**
244
+ * 应答
245
+ */
246
+ answer(): void;
247
+
248
+ /**
249
+ * 挂机/拒绝接听
250
+ */
251
+ hangup(): void;
252
+
253
+ /**
254
+ * 发送dtmf
255
+ * @param dtmf{string} 要发送的按键值 0-9 * #
256
+ */
257
+ dtmf(dtmf: string): boolean;
258
+
259
+ /**
260
+ * 转换前后置摄像头
261
+ * @returns {Promise<string>}
262
+ * @constructor
263
+ */
264
+ changeCamera(): Promise<string>;
265
+
266
+ /**
267
+ * 改变麦克风状态
268
+ * @returns {Promise<boolean>}
269
+ * @constructor
270
+ */
271
+ changeMuted(): Promise<boolean>;
272
+
273
+ /**
274
+ * 改变本地摄像头状态, 打开或关闭本地摄像头
275
+ * @returns {Promise<boolean>}
276
+ * @constructor
277
+ */
278
+ changeCameraOpened(): Promise<boolean>;
279
+
280
+ /**
281
+ * 注销
282
+ */
283
+ destroy():void;
284
+ }
285
+
286
+ export interface IAppCallSession extends ICallSession {
287
+ /**
288
+ * 会话呼叫模式
289
+ */
290
+ readonly callMode: CallMode;
291
+
292
+ /**
293
+ * 设置回调监听
294
+ * @param listener 监听器
295
+ */
296
+ setCallSessionListener(listener: AppCallSessionListener): void;
297
+
298
+ /**
299
+ * 发起语音对讲呼叫
300
+ * @param called 要呼叫的号码
301
+ */
302
+ audioHalfCall(called : string): void
303
+
304
+ /**
305
+ * 发起视频对讲呼叫
306
+ * @param called 要呼叫的号码
307
+ */
308
+ videoHalfCall(called : string): void
309
+
310
+ /**
311
+ * 申请话权
312
+ */
313
+ tbcpRequest(): void;
314
+
315
+ /**
316
+ * 释放话权
317
+ */
318
+ tbcpRelease(): void;
319
+ }
320
+
321
+ /**
322
+ * 初始化voip模块
323
+ * @param baseUrl{string} ws(s)://ip:port
324
+ */
325
+ export declare function voipModuleInit(baseUrl: string): void;
326
+
327
+ /**
328
+ * 创建呼叫会话
329
+ * @param tel 本端号码,可为空由服务端随机分配
330
+ */
331
+ export declare function createCallSession(tel?: string): ICallSession;
332
+
333
+ /**
334
+ * 创建app会话
335
+ * @param tel 账号配置的app号码
336
+ * @param accountId 账号id
337
+ */
338
+ export declare function createAppCallSession(tel:string, accountId:string): IAppCallSession;
339
+
340
+ /**
341
+ * 初始化video模块
342
+ * @param baseUrl{string} http(s)://ip:port
343
+ */
344
+ export declare function videoModuleInit(baseUrl: string): void;
345
+
346
+ /**
347
+ * 创建rtsp拉流会话
348
+ * @param rtspUrl{string} rtsp地址
349
+ */
350
+ export declare function createRtspPullSession(rtspUrl: string): IRtspPullSession;
351
+
352
+
353
+ /**
354
+ * 创建广播会话
355
+ * @param tel 广播号码
356
+ * @param mediaType 广播类型, 默认 audio
357
+ */
354
358
  export declare function createBroadcastSession(tel: string, mediaType?: MediaType): IBroadcastSession;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "media-av",
3
3
  "private": false,
4
- "version": "0.0.13",
4
+ "version": "0.0.14",
5
5
  "type": "module",
6
6
  "author": "W.w.",
7
7
  "license": "MIT",