@realsee/live 0.4.0-alpha.3 → 0.4.0-alpha.4
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 +52 -54
- package/dist/realsee-live.cjs.development.js +46 -2
- package/dist/realsee-live.cjs.development.js.map +1 -1
- package/dist/realsee-live.cjs.production.js +1 -1
- package/dist/realsee-live.cjs.production.js.map +1 -1
- package/dist/realsee-live.esm.js +46 -3
- package/dist/realsee-live.esm.js.map +1 -1
- package/dist/realsee-live.umd.development.js +1798 -33
- package/dist/realsee-live.umd.development.js.map +1 -1
- package/dist/realsee-live.umd.production.js +1 -1
- package/dist/realsee-live.umd.production.js.map +1 -1
- package/dist/typings/live/Live.d.ts +6 -1
- package/dist/typings/live/LiveOptions.d.ts +14 -1
- package/dist/typings/rtc/type.d.ts +4 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -30,26 +30,24 @@ SDKs(iOS/Android/微信小程序)和 Live API 可以快速实现实时同屏
|
|
|
30
30
|
|
|
31
31
|
```bash
|
|
32
32
|
# npm
|
|
33
|
-
npm i @realsee/live
|
|
33
|
+
npm i @realsee/live
|
|
34
34
|
# yarn
|
|
35
|
-
yarn add @realsee/live
|
|
35
|
+
yarn add @realsee/live
|
|
36
36
|
```
|
|
37
37
|
|
|
38
|
-
> **Live** 通过 [TypeScript](http://www.typescriptlang.org/) 编写,依赖 [tslib]() 运行时,如果你的项目不是由 [TypeScript](http://www.typescriptlang.org/) 构成,请安装此运行时。
|
|
39
|
-
|
|
40
38
|
### 如何使用
|
|
41
39
|
|
|
42
40
|
简单使用样例(先不考虑实时语音能力):
|
|
43
41
|
|
|
44
42
|
```js
|
|
45
|
-
import { createLive } from '@realsee/live'
|
|
43
|
+
import { createLive } from '@realsee/live';
|
|
46
44
|
|
|
47
45
|
const live = createLive({
|
|
48
46
|
url: 'wss://ws-access.realsee.com/***/?=xxx' /* 连接 WebSocket 服务的 URL */,
|
|
49
47
|
getTicket: async () => {
|
|
50
48
|
/* 获取带看"门票"的回调函数 */
|
|
51
49
|
},
|
|
52
|
-
})
|
|
50
|
+
});
|
|
53
51
|
```
|
|
54
52
|
|
|
55
53
|
在创建 `live` 实例时配置了两个参数:
|
|
@@ -82,12 +80,12 @@ const live = createLive({
|
|
|
82
80
|
|
|
83
81
|
```js
|
|
84
82
|
// 发送本地 帧数据 (Five State)
|
|
85
|
-
live.sendKeyframe('five', { panoIndex: 13 })
|
|
83
|
+
live.sendKeyframe('five', { panoIndex: 13 });
|
|
86
84
|
|
|
87
85
|
// 接收远程 帧数据 (Five State)
|
|
88
86
|
live.keyframes.on('five', (newState, prevState) => {
|
|
89
87
|
// 可以拿最新的 `newState` 更新本地 UI 状态
|
|
90
|
-
})
|
|
88
|
+
});
|
|
91
89
|
```
|
|
92
90
|
|
|
93
91
|
您也可以通过 `live.snapshot` 属性来获取当前所有序列帧数据的"快照"。
|
|
@@ -98,19 +96,19 @@ live.keyframes.on('five', (newState, prevState) => {
|
|
|
98
96
|
|
|
99
97
|
```js
|
|
100
98
|
// 属性:获取本地用户信息
|
|
101
|
-
live.selfInfo
|
|
99
|
+
live.selfInfo;
|
|
102
100
|
|
|
103
101
|
// 属性:获取当前房间内所有用户列表
|
|
104
|
-
live.userList
|
|
102
|
+
live.userList;
|
|
105
103
|
|
|
106
104
|
// 方法:更新本地用户信息
|
|
107
|
-
live.setSelfInfo({})
|
|
105
|
+
live.setSelfInfo({});
|
|
108
106
|
|
|
109
107
|
// 事件:本地用户信息发生变更
|
|
110
|
-
live.on('selfInfoUpdate', (userInfo) => {})
|
|
108
|
+
live.on('selfInfoUpdate', (userInfo) => {});
|
|
111
109
|
|
|
112
110
|
// 事件:房间用户列表信息发生变更
|
|
113
|
-
live.on('userListUpdate', (userList) => {})
|
|
111
|
+
live.on('userListUpdate', (userList) => {});
|
|
114
112
|
```
|
|
115
113
|
|
|
116
114
|
### 广播消息
|
|
@@ -118,13 +116,16 @@ live.on('userListUpdate', (userList) => {})
|
|
|
118
116
|
除了帧数据和房间信息之外,还可以用事件的形式向房间内的其他用户广播消息:
|
|
119
117
|
|
|
120
118
|
```js
|
|
121
|
-
live.broadcast(
|
|
119
|
+
live.broadcast(
|
|
120
|
+
data /* 广播的数据 */,
|
|
121
|
+
['user_id_1', 'user_id_2'] /* 收到此用户的userId */,
|
|
122
|
+
);
|
|
122
123
|
```
|
|
123
124
|
|
|
124
125
|
此时,房间内用户 Id 为 `user_id_1`、`user_id_2` 的用户会收到此广播消息(其他用户无感知):
|
|
125
126
|
|
|
126
127
|
```js
|
|
127
|
-
live.on('broadcast', (data /* 广播的数据 */) => {})
|
|
128
|
+
live.on('broadcast', (data /* 广播的数据 */) => {});
|
|
128
129
|
```
|
|
129
130
|
|
|
130
131
|
更多的例子请查看 [Live API](https://unpkg.com/@realsee/live/docs/index.html) 文档 。
|
|
@@ -139,8 +140,8 @@ live.on('broadcast', (data /* 广播的数据 */) => {})
|
|
|
139
140
|
|
|
140
141
|
```ts
|
|
141
142
|
live.on('ws.readyStateUpdate', (readyState: WebSocketState) => {
|
|
142
|
-
console.log(readyState) // readyState 即是最新的 WebScoket 状态
|
|
143
|
-
})
|
|
143
|
+
console.log(readyState); // readyState 即是最新的 WebScoket 状态
|
|
144
|
+
});
|
|
144
145
|
```
|
|
145
146
|
|
|
146
147
|
### WebSocket 事件
|
|
@@ -202,8 +203,8 @@ live.on('ws.readyStateUpdate', (readyState: WebSocketState) => {
|
|
|
202
203
|
|
|
203
204
|
```ts
|
|
204
205
|
live.$RTC.on('userVolumes', (userVolumes: UserVolume[]) => {
|
|
205
|
-
console.log(userVolumes) // userVolumes 正在说话的用户及其音量数据。
|
|
206
|
-
})
|
|
206
|
+
console.log(userVolumes); // userVolumes 正在说话的用户及其音量数据。
|
|
207
|
+
});
|
|
207
208
|
```
|
|
208
209
|
|
|
209
210
|
### 异常处理
|
|
@@ -256,32 +257,31 @@ live.$RTC.on('userVolumes', (userVolumes: UserVolume[]) => {
|
|
|
256
257
|
如果是 iOS/Android App(已接入如视 VRTC 容器 SDK)
|
|
257
258
|
|
|
258
259
|
```js
|
|
259
|
-
import
|
|
260
|
-
import { createLive } from '@realsee/live'
|
|
261
|
-
import { VRWebViewRTC } from '@realsee/live/RTC/VRWebViewRTC'
|
|
260
|
+
import JSBridge from '@realsee/jsbridge-x';
|
|
261
|
+
import { createLive, VRWebViewRTC } from '@realsee/live';
|
|
262
262
|
|
|
263
|
-
const jsBridgeInstance = new
|
|
263
|
+
const jsBridgeInstance = new JSBridge();
|
|
264
264
|
|
|
265
265
|
const rtcInstance = new VRWebViewRTC({
|
|
266
266
|
jsBridge,
|
|
267
267
|
getVoiceSign: () => {},
|
|
268
|
-
})
|
|
268
|
+
});
|
|
269
269
|
|
|
270
270
|
const live = createLive({
|
|
271
271
|
rtc: rtcInstance,
|
|
272
272
|
getTicket: async () => '',
|
|
273
|
-
})
|
|
273
|
+
});
|
|
274
274
|
```
|
|
275
275
|
|
|
276
276
|
提供 RTC 实例配置参数之后,语音的连接、断开、重连等逻辑就托管给了 **Live** 。您可以通过 live 实例上的 `$RTC` 命名空间访问语音相关的状态和事件。
|
|
277
277
|
|
|
278
278
|
```js
|
|
279
279
|
// 状态:用户是否成功加入语音房间
|
|
280
|
-
live.$RTC.joined
|
|
280
|
+
live.$RTC.joined;
|
|
281
281
|
// 状态:用户麦克风状态
|
|
282
|
-
live.$RTC.micro
|
|
282
|
+
live.$RTC.micro;
|
|
283
283
|
// 监听用户音量变化
|
|
284
|
-
live.$RTC.on('userVolumes', (userVolumes) => {})
|
|
284
|
+
live.$RTC.on('userVolumes', (userVolumes) => {});
|
|
285
285
|
```
|
|
286
286
|
|
|
287
287
|
## 浏览器端支持
|
|
@@ -302,17 +302,16 @@ yarn add trtc-js-sdk
|
|
|
302
302
|
使用方式:
|
|
303
303
|
|
|
304
304
|
```tsx
|
|
305
|
-
import { createLive } from '@realsee/live'
|
|
306
|
-
import { BrowserRTC } from '@realsee/live/RTC/BrowserRTC'
|
|
305
|
+
import { createLive, BrowserRTC } from '@realsee/live';
|
|
307
306
|
|
|
308
307
|
const rtcInstance = new VRWebViewRTC({
|
|
309
308
|
getVoiceSign: () => {},
|
|
310
|
-
})
|
|
309
|
+
});
|
|
311
310
|
|
|
312
311
|
const live = createLive({
|
|
313
312
|
rtc: rtcInstance,
|
|
314
313
|
getTicket: async () => '',
|
|
315
|
-
})
|
|
314
|
+
});
|
|
316
315
|
```
|
|
317
316
|
|
|
318
317
|
### Chime
|
|
@@ -327,17 +326,16 @@ yarn add amazon-chime-sdk-js
|
|
|
327
326
|
使用方式:
|
|
328
327
|
|
|
329
328
|
```tsx
|
|
330
|
-
import { createLive } from '@realsee/live'
|
|
331
|
-
import { BrowserRTC4Chime } from '@realsee/live/RTC/BrowserRTC4Chime'
|
|
329
|
+
import { createLive, BrowserRTC4Chime } from '@realsee/live';
|
|
332
330
|
|
|
333
331
|
const rtcInstance = new BrowserRTC4Chime({
|
|
334
332
|
getVoiceSign: () => {},
|
|
335
|
-
})
|
|
333
|
+
});
|
|
336
334
|
|
|
337
335
|
const live = createLive({
|
|
338
336
|
rtc: rtcInstance,
|
|
339
337
|
getTicket: async () => '',
|
|
340
|
-
})
|
|
338
|
+
});
|
|
341
339
|
```
|
|
342
340
|
|
|
343
341
|
## TypeScript & React 支持
|
|
@@ -350,57 +348,57 @@ const live = createLive({
|
|
|
350
348
|
步骤一:新建文件 `LiveReact.ts` 并创建您自己的 `LiveReact` 实例。
|
|
351
349
|
|
|
352
350
|
```tsx
|
|
353
|
-
import { createLiveReact } from '@realsee/live'
|
|
351
|
+
import { createLiveReact } from '@realsee/live';
|
|
354
352
|
|
|
355
353
|
/** 定义帧数据快照结构 */
|
|
356
354
|
interface Snapshot {
|
|
357
355
|
/** 以 Five 状态快照为例 */
|
|
358
356
|
five: {
|
|
359
|
-
panoIndex: number
|
|
360
|
-
fov: number
|
|
361
|
-
mode: 'Panorama' | 'Model'
|
|
362
|
-
latitude: number
|
|
363
|
-
longitude: number
|
|
364
|
-
}
|
|
357
|
+
panoIndex: number;
|
|
358
|
+
fov: number;
|
|
359
|
+
mode: 'Panorama' | 'Model';
|
|
360
|
+
latitude: number;
|
|
361
|
+
longitude: number;
|
|
362
|
+
};
|
|
365
363
|
}
|
|
366
364
|
|
|
367
365
|
/** 通过 `createLiveReact()` 函数创建实例*/
|
|
368
366
|
|
|
369
367
|
const LiveReact = createLiveReact<Snapshot>({
|
|
370
368
|
getTicket: async () => '' /* 必须提供 */,
|
|
371
|
-
})
|
|
369
|
+
});
|
|
372
370
|
|
|
373
|
-
export default LiveReact
|
|
371
|
+
export default LiveReact;
|
|
374
372
|
|
|
375
373
|
/** 如果您不喜欢 `LiveReact.LiveProvider` 这类编程习惯,可以将需要的函数"抛"出来 */
|
|
376
|
-
export const LiveProvider = LiveReact.LiveProvider
|
|
377
|
-
export const useConnect = LiveReact.useConnect
|
|
378
|
-
export const useKeyframe = LiveReact.useKeyframe
|
|
374
|
+
export const LiveProvider = LiveReact.LiveProvider;
|
|
375
|
+
export const useConnect = LiveReact.useConnect;
|
|
376
|
+
export const useKeyframe = LiveReact.useKeyframe;
|
|
379
377
|
// export ..
|
|
380
378
|
```
|
|
381
379
|
|
|
382
380
|
步骤二:通过 `LiveProvider` 将 `live` 实例集成到 `React` 的 [Context](https://reactjs.org/docs/context.html) 上下文环境中。
|
|
383
381
|
|
|
384
382
|
```jsx
|
|
385
|
-
import { LiveProvider } from './LiveReact'
|
|
383
|
+
import { LiveProvider } from './LiveReact';
|
|
386
384
|
|
|
387
385
|
ReactDOM.render(
|
|
388
386
|
<LiveProvider>
|
|
389
387
|
<RootApp />
|
|
390
388
|
</LiveProvider>,
|
|
391
|
-
containter
|
|
392
|
-
)
|
|
389
|
+
containter,
|
|
390
|
+
);
|
|
393
391
|
```
|
|
394
392
|
|
|
395
393
|
步骤三:在您的 `React` 函数组件中使用相关 `Hooks` 函数。
|
|
396
394
|
|
|
397
395
|
```jsx
|
|
398
|
-
import { useConnect } from './LiveReact'
|
|
396
|
+
import { useConnect } from './LiveReact';
|
|
399
397
|
|
|
400
398
|
function ReconnectBtn() {
|
|
401
|
-
const connect = useConnect()
|
|
399
|
+
const connect = useConnect();
|
|
402
400
|
|
|
403
|
-
return <button onClick={() => connect()}>重新连接</button
|
|
401
|
+
return <button onClick={() => connect()}>重新连接</button>;
|
|
404
402
|
}
|
|
405
403
|
```
|
|
406
404
|
|
|
@@ -2,12 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
+
var JSBridge = require('@realsee/jsbridge-x');
|
|
5
6
|
var amazonChimeSdkJs = require('amazon-chime-sdk-js');
|
|
6
7
|
var TRTC = require('trtc-js-sdk');
|
|
7
8
|
var React = require('react');
|
|
8
9
|
|
|
9
10
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
10
11
|
|
|
12
|
+
var JSBridge__default = /*#__PURE__*/_interopDefaultLegacy(JSBridge);
|
|
11
13
|
var TRTC__default = /*#__PURE__*/_interopDefaultLegacy(TRTC);
|
|
12
14
|
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
13
15
|
|
|
@@ -137,7 +139,12 @@ exports.RTCType = void 0;
|
|
|
137
139
|
RTCType["RealseeBrowserRTC"] = "RealseeBrowserRTC";
|
|
138
140
|
RTCType["RealseeVRWebViewRTC"] = "RealseeVRWebViewRTC";
|
|
139
141
|
RTCType["RealseeBrowserChimeRTC"] = "RealseeBrowserChimeRTC";
|
|
140
|
-
})(exports.RTCType || (exports.RTCType = {}));
|
|
142
|
+
})(exports.RTCType || (exports.RTCType = {}));
|
|
143
|
+
exports.BuiltInRTCType = void 0;
|
|
144
|
+
(function (BuiltInRTCType) {
|
|
145
|
+
BuiltInRTCType["RealseeXTRTC"] = "trtc";
|
|
146
|
+
BuiltInRTCType["RealseeXChimeRTC"] = "chime";
|
|
147
|
+
})(exports.BuiltInRTCType || (exports.BuiltInRTCType = {}));
|
|
141
148
|
|
|
142
149
|
// uuid
|
|
143
150
|
function S4() {
|
|
@@ -888,6 +895,12 @@ function appendUri(uri, query) {
|
|
|
888
895
|
return uri + newQuery;
|
|
889
896
|
}
|
|
890
897
|
|
|
898
|
+
const userAgent = globalThis.navigator.userAgent;
|
|
899
|
+
const isAndroid = /android/gi.test(userAgent);
|
|
900
|
+
const isIOS = /iPhone|iPad\s+OS/gi.test(userAgent);
|
|
901
|
+
const isWxMiniProgram = /MicroMessenger/gi.test(userAgent) && /miniProgram/gi.test(userAgent);
|
|
902
|
+
const isRealseeVRWebview = /realsee/gi.test(userAgent);
|
|
903
|
+
|
|
891
904
|
/**
|
|
892
905
|
* 判断是否是真实的对象类型
|
|
893
906
|
* @param value
|
|
@@ -1252,7 +1265,7 @@ function createLive(options) {
|
|
|
1252
1265
|
};
|
|
1253
1266
|
class LiveTpl extends Subscribe {
|
|
1254
1267
|
constructor() {
|
|
1255
|
-
var _a;
|
|
1268
|
+
var _a, _b, _c;
|
|
1256
1269
|
super();
|
|
1257
1270
|
this.keyframes = new Subscribe();
|
|
1258
1271
|
// 没有传rtc实例时
|
|
@@ -1295,6 +1308,34 @@ function createLive(options) {
|
|
|
1295
1308
|
}
|
|
1296
1309
|
}
|
|
1297
1310
|
}
|
|
1311
|
+
// 都不满足时取内置
|
|
1312
|
+
if (options.useBuiltInRTC) {
|
|
1313
|
+
if (!options.getVoiceSign) {
|
|
1314
|
+
throw new Error('GetVoiceSign method must be passed when using built-in RTC instances');
|
|
1315
|
+
}
|
|
1316
|
+
const getVoiceSign = (_b = options.getVoiceSign) !== null && _b !== void 0 ? _b : unimplementedGetVoiceSign;
|
|
1317
|
+
const jsBridge = ((_c = options.jsBridge) !== null && _c !== void 0 ? _c : options.useBuiltInJsBridge)
|
|
1318
|
+
? new JSBridge__default["default"]()
|
|
1319
|
+
: null;
|
|
1320
|
+
if (!jsBridge) {
|
|
1321
|
+
throw new Error('jsBridge instance must be passed when using built-in RTC instances');
|
|
1322
|
+
}
|
|
1323
|
+
options.jsBridge = jsBridge;
|
|
1324
|
+
// vrwebview 默认
|
|
1325
|
+
if ((isRealseeVRWebview && (isAndroid || isIOS)) || isWxMiniProgram) {
|
|
1326
|
+
liveController.options.rtc = new VRWebViewRTC({
|
|
1327
|
+
jsBridge,
|
|
1328
|
+
getVoiceSign,
|
|
1329
|
+
});
|
|
1330
|
+
}
|
|
1331
|
+
else {
|
|
1332
|
+
// 其它终端使用
|
|
1333
|
+
liveController.options.rtc =
|
|
1334
|
+
options.builtInRTCType === exports.BuiltInRTCType.RealseeXChimeRTC
|
|
1335
|
+
? new BrowserRTC4Chime({ getVoiceSign })
|
|
1336
|
+
: new BrowserRTC({ getVoiceSign });
|
|
1337
|
+
}
|
|
1338
|
+
}
|
|
1298
1339
|
}
|
|
1299
1340
|
if (!liveController.options.rtc) {
|
|
1300
1341
|
console.warn('unused rtc');
|
|
@@ -1342,6 +1383,9 @@ function createLive(options) {
|
|
|
1342
1383
|
get $RTC() {
|
|
1343
1384
|
return liveController.options.rtc;
|
|
1344
1385
|
}
|
|
1386
|
+
get jsBridge() {
|
|
1387
|
+
return liveController.options.jsBridge;
|
|
1388
|
+
}
|
|
1345
1389
|
async setSelfInfo(userInfo) {
|
|
1346
1390
|
if (this.readyState !== exports.WebSocketState.OPEN) {
|
|
1347
1391
|
return new Error('The connection is not open and ready to communicate.');
|