@sprucelabs/heartwood-view-controllers 119.3.0 → 119.3.1
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.
|
@@ -2,10 +2,13 @@ import MockRtcPeerConnection from '../tests/MockRtcPeerConnection';
|
|
|
2
2
|
import { WebRtcStreamer } from './WebRtcStreamer';
|
|
3
3
|
export default class WebRtcConnectionImpl implements WebRtcConnection {
|
|
4
4
|
static Class?: new () => WebRtcConnection;
|
|
5
|
+
private log;
|
|
6
|
+
private rtcPeerConnection?;
|
|
5
7
|
static get RTCPeerConnection(): new (config: RTCConfiguration) => RTCPeerConnection | MockRtcPeerConnection;
|
|
6
8
|
static set RTCPeerConnection(value: new (config: RTCConfiguration) => RTCPeerConnection | MockRtcPeerConnection);
|
|
7
9
|
private stateChangeListeners;
|
|
8
10
|
static Connection(): WebRtcConnection;
|
|
11
|
+
getRtcPeerConnection(): RTCPeerConnection;
|
|
9
12
|
createOffer(options: WebRtcVcPluginCreateOfferOptions): Promise<WebRtcCreateOfferResponse>;
|
|
10
13
|
private emitStateChange;
|
|
11
14
|
onStateChange(cb: WebRtcStateChangeHandler): void;
|
|
@@ -23,8 +26,10 @@ export interface WebRtcConnection {
|
|
|
23
26
|
offStateChange(listener: WebRtcStateChangeHandler): void;
|
|
24
27
|
createOffer(options: WebRtcVcPluginCreateOfferOptions): Promise<WebRtcCreateOfferResponse>;
|
|
25
28
|
onStateChange(cb: WebRtcStateChangeHandler): void;
|
|
29
|
+
getRtcPeerConnection(): RTCPeerConnection;
|
|
26
30
|
}
|
|
27
31
|
export interface WebRtcCreateOfferResponse {
|
|
28
32
|
offerSdp: RTCSessionDescriptionInit;
|
|
29
33
|
streamer: WebRtcStreamer;
|
|
34
|
+
rtcPeerConnection: RTCPeerConnection;
|
|
30
35
|
}
|
|
@@ -8,9 +8,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { assertOptions } from '@sprucelabs/schema';
|
|
11
|
+
import { buildLog } from '@sprucelabs/spruce-skill-utils';
|
|
12
|
+
import SpruceError from '../errors/SpruceError.js';
|
|
11
13
|
import WebRtcStreamerImpl from './WebRtcStreamer.js';
|
|
12
14
|
export default class WebRtcConnectionImpl {
|
|
13
15
|
constructor() {
|
|
16
|
+
this.log = buildLog('WebRtcConnectionImpl');
|
|
14
17
|
this.stateChangeListeners = [];
|
|
15
18
|
}
|
|
16
19
|
static get RTCPeerConnection() {
|
|
@@ -23,6 +26,15 @@ export default class WebRtcConnectionImpl {
|
|
|
23
26
|
var _a;
|
|
24
27
|
return new ((_a = this.Class) !== null && _a !== void 0 ? _a : this)();
|
|
25
28
|
}
|
|
29
|
+
getRtcPeerConnection() {
|
|
30
|
+
if (!this.rtcPeerConnection) {
|
|
31
|
+
throw new SpruceError({
|
|
32
|
+
code: 'DID_NOT_GENERATE_OFFER',
|
|
33
|
+
friendlyMessage: 'You must create an offer before getting the peer connection!',
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
return this.rtcPeerConnection;
|
|
37
|
+
}
|
|
26
38
|
createOffer(options) {
|
|
27
39
|
return __awaiter(this, void 0, void 0, function* () {
|
|
28
40
|
const { offerOptions } = assertOptions(options, ['offerOptions']);
|
|
@@ -31,6 +43,10 @@ export default class WebRtcConnectionImpl {
|
|
|
31
43
|
sdpSemantics: 'unified-plan',
|
|
32
44
|
iceServers: [],
|
|
33
45
|
});
|
|
46
|
+
this.rtcPeerConnection = connection;
|
|
47
|
+
connection.addEventListener('connectionstatechange', () => {
|
|
48
|
+
this.log.info('connectionstatechange', connection.connectionState);
|
|
49
|
+
});
|
|
34
50
|
const { offerToReceiveAudio, offerToReceiveVideo } = offerOptions;
|
|
35
51
|
if (offerToReceiveAudio) {
|
|
36
52
|
connection.addTransceiver('audio', { direction: 'recvonly' });
|
|
@@ -49,6 +65,7 @@ export default class WebRtcConnectionImpl {
|
|
|
49
65
|
});
|
|
50
66
|
return {
|
|
51
67
|
offerSdp: offer,
|
|
68
|
+
rtcPeerConnection: connection,
|
|
52
69
|
streamer: WebRtcStreamerImpl.Streamer(connection, (status) => __awaiter(this, void 0, void 0, function* () {
|
|
53
70
|
yield this.emitStateChange(status);
|
|
54
71
|
})),
|
|
@@ -2,10 +2,13 @@ import MockRtcPeerConnection from '../tests/MockRtcPeerConnection';
|
|
|
2
2
|
import { WebRtcStreamer } from './WebRtcStreamer';
|
|
3
3
|
export default class WebRtcConnectionImpl implements WebRtcConnection {
|
|
4
4
|
static Class?: new () => WebRtcConnection;
|
|
5
|
+
private log;
|
|
6
|
+
private rtcPeerConnection?;
|
|
5
7
|
static get RTCPeerConnection(): new (config: RTCConfiguration) => RTCPeerConnection | MockRtcPeerConnection;
|
|
6
8
|
static set RTCPeerConnection(value: new (config: RTCConfiguration) => RTCPeerConnection | MockRtcPeerConnection);
|
|
7
9
|
private stateChangeListeners;
|
|
8
10
|
static Connection(): WebRtcConnection;
|
|
11
|
+
getRtcPeerConnection(): RTCPeerConnection;
|
|
9
12
|
createOffer(options: WebRtcVcPluginCreateOfferOptions): Promise<WebRtcCreateOfferResponse>;
|
|
10
13
|
private emitStateChange;
|
|
11
14
|
onStateChange(cb: WebRtcStateChangeHandler): void;
|
|
@@ -23,8 +26,10 @@ export interface WebRtcConnection {
|
|
|
23
26
|
offStateChange(listener: WebRtcStateChangeHandler): void;
|
|
24
27
|
createOffer(options: WebRtcVcPluginCreateOfferOptions): Promise<WebRtcCreateOfferResponse>;
|
|
25
28
|
onStateChange(cb: WebRtcStateChangeHandler): void;
|
|
29
|
+
getRtcPeerConnection(): RTCPeerConnection;
|
|
26
30
|
}
|
|
27
31
|
export interface WebRtcCreateOfferResponse {
|
|
28
32
|
offerSdp: RTCSessionDescriptionInit;
|
|
29
33
|
streamer: WebRtcStreamer;
|
|
34
|
+
rtcPeerConnection: RTCPeerConnection;
|
|
30
35
|
}
|
|
@@ -4,9 +4,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const schema_1 = require("@sprucelabs/schema");
|
|
7
|
+
const spruce_skill_utils_1 = require("@sprucelabs/spruce-skill-utils");
|
|
8
|
+
const SpruceError_1 = __importDefault(require("../errors/SpruceError"));
|
|
7
9
|
const WebRtcStreamer_1 = __importDefault(require("./WebRtcStreamer"));
|
|
8
10
|
class WebRtcConnectionImpl {
|
|
9
11
|
constructor() {
|
|
12
|
+
this.log = (0, spruce_skill_utils_1.buildLog)('WebRtcConnectionImpl');
|
|
10
13
|
this.stateChangeListeners = [];
|
|
11
14
|
}
|
|
12
15
|
static get RTCPeerConnection() {
|
|
@@ -18,6 +21,15 @@ class WebRtcConnectionImpl {
|
|
|
18
21
|
static Connection() {
|
|
19
22
|
return new (this.Class ?? this)();
|
|
20
23
|
}
|
|
24
|
+
getRtcPeerConnection() {
|
|
25
|
+
if (!this.rtcPeerConnection) {
|
|
26
|
+
throw new SpruceError_1.default({
|
|
27
|
+
code: 'DID_NOT_GENERATE_OFFER',
|
|
28
|
+
friendlyMessage: 'You must create an offer before getting the peer connection!',
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
return this.rtcPeerConnection;
|
|
32
|
+
}
|
|
21
33
|
async createOffer(options) {
|
|
22
34
|
const { offerOptions } = (0, schema_1.assertOptions)(options, ['offerOptions']);
|
|
23
35
|
const connection = new WebRtcConnectionImpl.RTCPeerConnection({
|
|
@@ -25,6 +37,10 @@ class WebRtcConnectionImpl {
|
|
|
25
37
|
sdpSemantics: 'unified-plan',
|
|
26
38
|
iceServers: [],
|
|
27
39
|
});
|
|
40
|
+
this.rtcPeerConnection = connection;
|
|
41
|
+
connection.addEventListener('connectionstatechange', () => {
|
|
42
|
+
this.log.info('connectionstatechange', connection.connectionState);
|
|
43
|
+
});
|
|
28
44
|
const { offerToReceiveAudio, offerToReceiveVideo } = offerOptions;
|
|
29
45
|
if (offerToReceiveAudio) {
|
|
30
46
|
connection.addTransceiver('audio', { direction: 'recvonly' });
|
|
@@ -43,6 +59,7 @@ class WebRtcConnectionImpl {
|
|
|
43
59
|
});
|
|
44
60
|
return {
|
|
45
61
|
offerSdp: offer,
|
|
62
|
+
rtcPeerConnection: connection,
|
|
46
63
|
streamer: WebRtcStreamer_1.default.Streamer(connection, async (status) => {
|
|
47
64
|
await this.emitStateChange(status);
|
|
48
65
|
}),
|
package/package.json
CHANGED