@webex/media-helpers 3.0.0-next.2 → 3.0.0-next.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/LICENSE +1 -1
- package/README.md +106 -106
- package/babel.config.json +12 -12
- package/dist/constants.d.ts +13 -13
- package/dist/constants.js +59 -0
- package/dist/constants.js.map +1 -0
- package/dist/index.d.ts +4 -4
- package/dist/index.js +124 -0
- package/dist/index.js.map +1 -0
- package/dist/webrtc-core.d.ts +48 -48
- package/dist/webrtc-core.js +213 -0
- package/dist/webrtc-core.js.map +1 -0
- package/package.json +9 -9
- package/src/constants.ts +29 -29
- package/src/index.ts +25 -25
- package/src/webrtc-core.ts +136 -136
- package/test/unit/spec/webrtc-core.js +145 -145
- package/tsconfig.json +5 -5
|
@@ -1,145 +1,145 @@
|
|
|
1
|
-
import {assert, expect} from '@webex/test-helper-chai';
|
|
2
|
-
import sinon from 'sinon';
|
|
3
|
-
import {
|
|
4
|
-
LocalCameraStream,
|
|
5
|
-
LocalMicrophoneStream,
|
|
6
|
-
LocalMicrophoneStreamEventNames,
|
|
7
|
-
LocalCameraStreamEventNames,
|
|
8
|
-
LocalDisplayStream,
|
|
9
|
-
LocalSystemAudioStream,
|
|
10
|
-
createCameraStream,
|
|
11
|
-
createMicrophoneStream,
|
|
12
|
-
createDisplayStream,
|
|
13
|
-
createDisplayStreamWithAudio,
|
|
14
|
-
} from '../../../src/webrtc-core';
|
|
15
|
-
import * as wcmeStreams from '@webex/internal-media-core';
|
|
16
|
-
|
|
17
|
-
describe('media-helpers', () => {
|
|
18
|
-
describe('webrtc-core', () => {
|
|
19
|
-
const classesToTest = [
|
|
20
|
-
{
|
|
21
|
-
className: LocalCameraStream,
|
|
22
|
-
title: 'LocalCameraStream',
|
|
23
|
-
event: LocalCameraStreamEventNames,
|
|
24
|
-
createFn: createCameraStream,
|
|
25
|
-
spyFn: 'createCameraStream',
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
className: LocalMicrophoneStream,
|
|
29
|
-
title: 'LocalMicrophoneStream',
|
|
30
|
-
event: LocalMicrophoneStreamEventNames,
|
|
31
|
-
createFn: createMicrophoneStream,
|
|
32
|
-
spyFn: 'createMicrophoneStream',
|
|
33
|
-
},
|
|
34
|
-
];
|
|
35
|
-
|
|
36
|
-
classesToTest.forEach(({className, title, event, createFn, spyFn}) =>
|
|
37
|
-
describe(title, () => {
|
|
38
|
-
const fakeStream = {
|
|
39
|
-
getStreams: sinon.stub().returns([
|
|
40
|
-
{
|
|
41
|
-
label: 'fake Stream',
|
|
42
|
-
id: 'fake Stream id',
|
|
43
|
-
enabled: true,
|
|
44
|
-
},
|
|
45
|
-
]),
|
|
46
|
-
};
|
|
47
|
-
const stream = new className(fakeStream);
|
|
48
|
-
|
|
49
|
-
afterEach(() => {
|
|
50
|
-
sinon.restore();
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
it('by default allows unmuting', async () => {
|
|
54
|
-
assert.equal(stream.isUnmuteAllowed(), true);
|
|
55
|
-
await stream.setMuted(false);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it('rejects setMute(false) if unmute is not allowed', async () => {
|
|
59
|
-
stream.setUnmuteAllowed(false);
|
|
60
|
-
|
|
61
|
-
assert.equal(stream.isUnmuteAllowed(), false);
|
|
62
|
-
const fn = () => stream.setMuted(false);
|
|
63
|
-
expect(fn).to.throw(/Unmute is not allowed/);
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
it('resolves setMute(false) if unmute is allowed', async () => {
|
|
67
|
-
stream.setUnmuteAllowed(true);
|
|
68
|
-
|
|
69
|
-
assert.equal(stream.isUnmuteAllowed(), true);
|
|
70
|
-
await stream.setMuted(false);
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
describe('#setServerMuted', () => {
|
|
74
|
-
afterEach(() => {
|
|
75
|
-
sinon.restore();
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
const checkSetServerMuted = async (startMute, setMute, expectedCalled) => {
|
|
79
|
-
await stream.setMuted(startMute);
|
|
80
|
-
|
|
81
|
-
assert.equal(stream.muted, startMute);
|
|
82
|
-
|
|
83
|
-
const handler = sinon.fake();
|
|
84
|
-
stream.on(event.ServerMuted, handler);
|
|
85
|
-
|
|
86
|
-
await stream.setServerMuted(setMute, 'remotelyMuted');
|
|
87
|
-
|
|
88
|
-
assert.equal(stream.muted, setMute);
|
|
89
|
-
if (expectedCalled) {
|
|
90
|
-
assert.calledOnceWithExactly(handler, {muted: setMute, reason: 'remotelyMuted'});
|
|
91
|
-
} else {
|
|
92
|
-
assert.notCalled(handler);
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
it('tests true to false', async () => {
|
|
97
|
-
await checkSetServerMuted(true, false, true);
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
it('tests false to true', async () => {
|
|
101
|
-
await checkSetServerMuted(false, true, true);
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
it('tests true to true', async () => {
|
|
105
|
-
await checkSetServerMuted(true, true, false);
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
it('tests false to false', async () => {
|
|
109
|
-
await checkSetServerMuted(false, false, false);
|
|
110
|
-
});
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
describe('#wcmeCreateMicrophoneStream, #wcmeCreateCameraStream', () => {
|
|
114
|
-
it('checks creating Streams', async () => {
|
|
115
|
-
const constraints = {devideId: 'abc'};
|
|
116
|
-
|
|
117
|
-
const spy = sinon.stub(wcmeStreams, spyFn).returns('something');
|
|
118
|
-
const result = createFn(constraints);
|
|
119
|
-
|
|
120
|
-
assert.equal(result, 'something');
|
|
121
|
-
assert.calledOnceWithExactly(spy, className, constraints);
|
|
122
|
-
});
|
|
123
|
-
});
|
|
124
|
-
})
|
|
125
|
-
);
|
|
126
|
-
|
|
127
|
-
describe('createDisplayStream', () => {
|
|
128
|
-
it('checks createDisplayStream', async () => {
|
|
129
|
-
const spy = sinon.stub(wcmeStreams, 'createDisplayStream').returns('something');
|
|
130
|
-
const result = createDisplayStream();
|
|
131
|
-
assert.equal(result, 'something');
|
|
132
|
-
assert.calledOnceWithExactly(spy, LocalDisplayStream);
|
|
133
|
-
});
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
describe('createDisplayStreamWithAudio', () => {
|
|
137
|
-
it('checks createDisplayStreamWithAudio', async () => {
|
|
138
|
-
const spy = sinon.stub(wcmeStreams, 'createDisplayStreamWithAudio').returns('something');
|
|
139
|
-
const result = createDisplayStreamWithAudio();
|
|
140
|
-
assert.equal(result, 'something');
|
|
141
|
-
assert.calledOnceWithExactly(spy, LocalDisplayStream, LocalSystemAudioStream);
|
|
142
|
-
});
|
|
143
|
-
});
|
|
144
|
-
});
|
|
145
|
-
});
|
|
1
|
+
import {assert, expect} from '@webex/test-helper-chai';
|
|
2
|
+
import sinon from 'sinon';
|
|
3
|
+
import {
|
|
4
|
+
LocalCameraStream,
|
|
5
|
+
LocalMicrophoneStream,
|
|
6
|
+
LocalMicrophoneStreamEventNames,
|
|
7
|
+
LocalCameraStreamEventNames,
|
|
8
|
+
LocalDisplayStream,
|
|
9
|
+
LocalSystemAudioStream,
|
|
10
|
+
createCameraStream,
|
|
11
|
+
createMicrophoneStream,
|
|
12
|
+
createDisplayStream,
|
|
13
|
+
createDisplayStreamWithAudio,
|
|
14
|
+
} from '../../../src/webrtc-core';
|
|
15
|
+
import * as wcmeStreams from '@webex/internal-media-core';
|
|
16
|
+
|
|
17
|
+
describe('media-helpers', () => {
|
|
18
|
+
describe('webrtc-core', () => {
|
|
19
|
+
const classesToTest = [
|
|
20
|
+
{
|
|
21
|
+
className: LocalCameraStream,
|
|
22
|
+
title: 'LocalCameraStream',
|
|
23
|
+
event: LocalCameraStreamEventNames,
|
|
24
|
+
createFn: createCameraStream,
|
|
25
|
+
spyFn: 'createCameraStream',
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
className: LocalMicrophoneStream,
|
|
29
|
+
title: 'LocalMicrophoneStream',
|
|
30
|
+
event: LocalMicrophoneStreamEventNames,
|
|
31
|
+
createFn: createMicrophoneStream,
|
|
32
|
+
spyFn: 'createMicrophoneStream',
|
|
33
|
+
},
|
|
34
|
+
];
|
|
35
|
+
|
|
36
|
+
classesToTest.forEach(({className, title, event, createFn, spyFn}) =>
|
|
37
|
+
describe(title, () => {
|
|
38
|
+
const fakeStream = {
|
|
39
|
+
getStreams: sinon.stub().returns([
|
|
40
|
+
{
|
|
41
|
+
label: 'fake Stream',
|
|
42
|
+
id: 'fake Stream id',
|
|
43
|
+
enabled: true,
|
|
44
|
+
},
|
|
45
|
+
]),
|
|
46
|
+
};
|
|
47
|
+
const stream = new className(fakeStream);
|
|
48
|
+
|
|
49
|
+
afterEach(() => {
|
|
50
|
+
sinon.restore();
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('by default allows unmuting', async () => {
|
|
54
|
+
assert.equal(stream.isUnmuteAllowed(), true);
|
|
55
|
+
await stream.setMuted(false);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('rejects setMute(false) if unmute is not allowed', async () => {
|
|
59
|
+
stream.setUnmuteAllowed(false);
|
|
60
|
+
|
|
61
|
+
assert.equal(stream.isUnmuteAllowed(), false);
|
|
62
|
+
const fn = () => stream.setMuted(false);
|
|
63
|
+
expect(fn).to.throw(/Unmute is not allowed/);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('resolves setMute(false) if unmute is allowed', async () => {
|
|
67
|
+
stream.setUnmuteAllowed(true);
|
|
68
|
+
|
|
69
|
+
assert.equal(stream.isUnmuteAllowed(), true);
|
|
70
|
+
await stream.setMuted(false);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
describe('#setServerMuted', () => {
|
|
74
|
+
afterEach(() => {
|
|
75
|
+
sinon.restore();
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
const checkSetServerMuted = async (startMute, setMute, expectedCalled) => {
|
|
79
|
+
await stream.setMuted(startMute);
|
|
80
|
+
|
|
81
|
+
assert.equal(stream.muted, startMute);
|
|
82
|
+
|
|
83
|
+
const handler = sinon.fake();
|
|
84
|
+
stream.on(event.ServerMuted, handler);
|
|
85
|
+
|
|
86
|
+
await stream.setServerMuted(setMute, 'remotelyMuted');
|
|
87
|
+
|
|
88
|
+
assert.equal(stream.muted, setMute);
|
|
89
|
+
if (expectedCalled) {
|
|
90
|
+
assert.calledOnceWithExactly(handler, {muted: setMute, reason: 'remotelyMuted'});
|
|
91
|
+
} else {
|
|
92
|
+
assert.notCalled(handler);
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
it('tests true to false', async () => {
|
|
97
|
+
await checkSetServerMuted(true, false, true);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it('tests false to true', async () => {
|
|
101
|
+
await checkSetServerMuted(false, true, true);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it('tests true to true', async () => {
|
|
105
|
+
await checkSetServerMuted(true, true, false);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it('tests false to false', async () => {
|
|
109
|
+
await checkSetServerMuted(false, false, false);
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
describe('#wcmeCreateMicrophoneStream, #wcmeCreateCameraStream', () => {
|
|
114
|
+
it('checks creating Streams', async () => {
|
|
115
|
+
const constraints = {devideId: 'abc'};
|
|
116
|
+
|
|
117
|
+
const spy = sinon.stub(wcmeStreams, spyFn).returns('something');
|
|
118
|
+
const result = createFn(constraints);
|
|
119
|
+
|
|
120
|
+
assert.equal(result, 'something');
|
|
121
|
+
assert.calledOnceWithExactly(spy, className, constraints);
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
})
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
describe('createDisplayStream', () => {
|
|
128
|
+
it('checks createDisplayStream', async () => {
|
|
129
|
+
const spy = sinon.stub(wcmeStreams, 'createDisplayStream').returns('something');
|
|
130
|
+
const result = createDisplayStream();
|
|
131
|
+
assert.equal(result, 'something');
|
|
132
|
+
assert.calledOnceWithExactly(spy, LocalDisplayStream);
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
describe('createDisplayStreamWithAudio', () => {
|
|
137
|
+
it('checks createDisplayStreamWithAudio', async () => {
|
|
138
|
+
const spy = sinon.stub(wcmeStreams, 'createDisplayStreamWithAudio').returns('something');
|
|
139
|
+
const result = createDisplayStreamWithAudio();
|
|
140
|
+
assert.equal(result, 'something');
|
|
141
|
+
assert.calledOnceWithExactly(spy, LocalDisplayStream, LocalSystemAudioStream);
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
});
|
package/tsconfig.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "../../../tsconfig.json",
|
|
3
|
-
"include": [
|
|
4
|
-
"src"
|
|
5
|
-
],
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../../tsconfig.json",
|
|
3
|
+
"include": [
|
|
4
|
+
"src"
|
|
5
|
+
],
|
|
6
6
|
}
|