@webex/media-helpers 3.0.0-beta.87
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 +2 -0
- package/README.md +34 -0
- package/dist/index.js +68 -0
- package/dist/index.js.map +1 -0
- package/dist/webrtc-core.js +185 -0
- package/dist/webrtc-core.js.map +1 -0
- package/package.json +30 -0
- package/src/index.ts +14 -0
- package/src/webrtc-core.ts +119 -0
- package/test/unit/spec/webrtc-core.js +115 -0
package/LICENSE
ADDED
package/README.md
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# @webex/media-helpers
|
|
2
|
+
|
|
3
|
+
[](https://github.com/RichardLitt/standard-readme)
|
|
4
|
+
|
|
5
|
+
> Media helpers
|
|
6
|
+
|
|
7
|
+
This is an internal Cisco Webex plugin. As such, it does not strictly adhere to semantic versioning. Use at your own risk. If you're not working on one of our first party clients, please look at our [developer api](https://developer.webex.com/) and stick to our public plugins.
|
|
8
|
+
|
|
9
|
+
- [@webex/media-helpers](#webexmedia-helpers)
|
|
10
|
+
- [Install](#install)
|
|
11
|
+
- [Usage](#usage)
|
|
12
|
+
- [Maintainers](#maintainers)
|
|
13
|
+
- [Contribute](#contribute)
|
|
14
|
+
- [License](#license)
|
|
15
|
+
|
|
16
|
+
## Install
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install --save @webex/media-helpers
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
## Maintainers
|
|
25
|
+
|
|
26
|
+
This package is maintained by [Cisco Webex for Developers](https://developer.webex.com/).
|
|
27
|
+
|
|
28
|
+
## Contribute
|
|
29
|
+
|
|
30
|
+
Pull requests welcome. Please see [CONTRIBUTING.md](https://github.com/webex/webex-js-sdk/blob/master/CONTRIBUTING.md) for more details.
|
|
31
|
+
|
|
32
|
+
## License
|
|
33
|
+
|
|
34
|
+
© 2016-2022 Cisco and/or its affiliates. All Rights Reserved.
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _Object$defineProperty = require("@babel/runtime-corejs2/core-js/object/define-property");
|
|
4
|
+
_Object$defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
_Object$defineProperty(exports, "LocalCameraTrack", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function get() {
|
|
10
|
+
return _webrtcCore.LocalCameraTrack;
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
_Object$defineProperty(exports, "LocalCameraTrackEvents", {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
get: function get() {
|
|
16
|
+
return _webrtcCore.LocalCameraTrackEvents;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
_Object$defineProperty(exports, "LocalDisplayTrack", {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
get: function get() {
|
|
22
|
+
return _webrtcCore.LocalDisplayTrack;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
_Object$defineProperty(exports, "LocalMicrophoneTrack", {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
get: function get() {
|
|
28
|
+
return _webrtcCore.LocalMicrophoneTrack;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
_Object$defineProperty(exports, "LocalMicrophoneTrackEvents", {
|
|
32
|
+
enumerable: true,
|
|
33
|
+
get: function get() {
|
|
34
|
+
return _webrtcCore.LocalMicrophoneTrackEvents;
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
_Object$defineProperty(exports, "LocalTrack", {
|
|
38
|
+
enumerable: true,
|
|
39
|
+
get: function get() {
|
|
40
|
+
return _webrtcCore.LocalTrack;
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
_Object$defineProperty(exports, "LocalTrackEvents", {
|
|
44
|
+
enumerable: true,
|
|
45
|
+
get: function get() {
|
|
46
|
+
return _webrtcCore.LocalTrackEvents;
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
_Object$defineProperty(exports, "createCameraTrack", {
|
|
50
|
+
enumerable: true,
|
|
51
|
+
get: function get() {
|
|
52
|
+
return _webrtcCore.createCameraTrack;
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
_Object$defineProperty(exports, "createDisplayTrack", {
|
|
56
|
+
enumerable: true,
|
|
57
|
+
get: function get() {
|
|
58
|
+
return _webrtcCore.createDisplayTrack;
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
_Object$defineProperty(exports, "createMicrophoneTrack", {
|
|
62
|
+
enumerable: true,
|
|
63
|
+
get: function get() {
|
|
64
|
+
return _webrtcCore.createMicrophoneTrack;
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
var _webrtcCore = require("./webrtc-core");
|
|
68
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export {\n LocalTrack,\n LocalDisplayTrack,\n LocalTrackEvents,\n type TrackMuteEvent,\n type ServerMuteReason,\n LocalMicrophoneTrackEvents,\n LocalCameraTrackEvents,\n LocalMicrophoneTrack,\n LocalCameraTrack,\n createMicrophoneTrack,\n createCameraTrack,\n createDisplayTrack,\n} from './webrtc-core';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA"}
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _Reflect$construct = require("@babel/runtime-corejs2/core-js/reflect/construct");
|
|
4
|
+
var _Object$defineProperty = require("@babel/runtime-corejs2/core-js/object/define-property");
|
|
5
|
+
var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");
|
|
6
|
+
_Object$defineProperty(exports, "__esModule", {
|
|
7
|
+
value: true
|
|
8
|
+
});
|
|
9
|
+
exports.LocalCameraTrackEvents = exports.LocalCameraTrack = void 0;
|
|
10
|
+
_Object$defineProperty(exports, "LocalDisplayTrack", {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function get() {
|
|
13
|
+
return _internalMediaCore.LocalDisplayTrack;
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
exports.LocalMicrophoneTrackEvents = exports.LocalMicrophoneTrack = void 0;
|
|
17
|
+
_Object$defineProperty(exports, "LocalTrack", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: function get() {
|
|
20
|
+
return _internalMediaCore.LocalTrack;
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
_Object$defineProperty(exports, "LocalTrackEvents", {
|
|
24
|
+
enumerable: true,
|
|
25
|
+
get: function get() {
|
|
26
|
+
return _internalMediaCore.LocalTrackEvents;
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
exports.createMicrophoneTrack = exports.createDisplayTrack = exports.createCameraTrack = void 0;
|
|
30
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/classCallCheck"));
|
|
31
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/createClass"));
|
|
32
|
+
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/assertThisInitialized"));
|
|
33
|
+
var _get2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/get"));
|
|
34
|
+
var _inherits2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/inherits"));
|
|
35
|
+
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/possibleConstructorReturn"));
|
|
36
|
+
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/getPrototypeOf"));
|
|
37
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/defineProperty"));
|
|
38
|
+
var _internalMediaCore = require("@webex/internal-media-core");
|
|
39
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = _Reflect$construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
|
|
40
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !_Reflect$construct) return false; if (_Reflect$construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(_Reflect$construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
41
|
+
// server forced the client to be unmuted
|
|
42
|
+
// these events are in addition to WCME events. This will be properly typed once webrtc-core event types inheritance is fixed
|
|
43
|
+
var LocalMicrophoneTrackEvents; // these events are in addition to WCME events. This will be properly typed once webrtc-core event types inheritance is fixed
|
|
44
|
+
exports.LocalMicrophoneTrackEvents = LocalMicrophoneTrackEvents;
|
|
45
|
+
(function (LocalMicrophoneTrackEvents) {
|
|
46
|
+
LocalMicrophoneTrackEvents["ServerMuted"] = "muted:byServer";
|
|
47
|
+
})(LocalMicrophoneTrackEvents || (exports.LocalMicrophoneTrackEvents = LocalMicrophoneTrackEvents = {}));
|
|
48
|
+
var LocalCameraTrackEvents;
|
|
49
|
+
exports.LocalCameraTrackEvents = LocalCameraTrackEvents;
|
|
50
|
+
(function (LocalCameraTrackEvents) {
|
|
51
|
+
LocalCameraTrackEvents["ServerMuted"] = "muted:byServer";
|
|
52
|
+
})(LocalCameraTrackEvents || (exports.LocalCameraTrackEvents = LocalCameraTrackEvents = {}));
|
|
53
|
+
var LocalMicrophoneTrack = /*#__PURE__*/function (_WcmeLocalMicrophoneT) {
|
|
54
|
+
(0, _inherits2.default)(LocalMicrophoneTrack, _WcmeLocalMicrophoneT);
|
|
55
|
+
var _super = _createSuper(LocalMicrophoneTrack);
|
|
56
|
+
function LocalMicrophoneTrack() {
|
|
57
|
+
var _this;
|
|
58
|
+
(0, _classCallCheck2.default)(this, LocalMicrophoneTrack);
|
|
59
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
60
|
+
args[_key] = arguments[_key];
|
|
61
|
+
}
|
|
62
|
+
_this = _super.call.apply(_super, [this].concat(args));
|
|
63
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "unmuteAllowed", true);
|
|
64
|
+
return _this;
|
|
65
|
+
}
|
|
66
|
+
(0, _createClass2.default)(LocalMicrophoneTrack, [{
|
|
67
|
+
key: "setUnmuteAllowed",
|
|
68
|
+
value:
|
|
69
|
+
/**
|
|
70
|
+
* @internal
|
|
71
|
+
*/
|
|
72
|
+
function setUnmuteAllowed(allowed) {
|
|
73
|
+
this.unmuteAllowed = allowed;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* @returns true if user is allowed to unmute the track, false otherwise
|
|
78
|
+
*/
|
|
79
|
+
}, {
|
|
80
|
+
key: "isUnmuteAllowed",
|
|
81
|
+
value: function isUnmuteAllowed() {
|
|
82
|
+
return this.unmuteAllowed;
|
|
83
|
+
}
|
|
84
|
+
}, {
|
|
85
|
+
key: "setMuted",
|
|
86
|
+
value: function setMuted(muted) {
|
|
87
|
+
if (!muted) {
|
|
88
|
+
if (!this.isUnmuteAllowed()) {
|
|
89
|
+
throw new Error('Unmute is not allowed');
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return (0, _get2.default)((0, _getPrototypeOf2.default)(LocalMicrophoneTrack.prototype), "setMuted", this).call(this, muted);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* @internal
|
|
97
|
+
*/
|
|
98
|
+
}, {
|
|
99
|
+
key: "setServerMuted",
|
|
100
|
+
value: function setServerMuted(muted, reason) {
|
|
101
|
+
if (muted !== this.muted) {
|
|
102
|
+
this.setMuted(muted);
|
|
103
|
+
this.emit(LocalMicrophoneTrackEvents.ServerMuted, {
|
|
104
|
+
muted: muted,
|
|
105
|
+
reason: reason
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}]);
|
|
110
|
+
return LocalMicrophoneTrack;
|
|
111
|
+
}(_internalMediaCore.LocalMicrophoneTrack);
|
|
112
|
+
exports.LocalMicrophoneTrack = LocalMicrophoneTrack;
|
|
113
|
+
var LocalCameraTrack = /*#__PURE__*/function (_WcmeLocalCameraTrack) {
|
|
114
|
+
(0, _inherits2.default)(LocalCameraTrack, _WcmeLocalCameraTrack);
|
|
115
|
+
var _super2 = _createSuper(LocalCameraTrack);
|
|
116
|
+
function LocalCameraTrack() {
|
|
117
|
+
var _this2;
|
|
118
|
+
(0, _classCallCheck2.default)(this, LocalCameraTrack);
|
|
119
|
+
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
120
|
+
args[_key2] = arguments[_key2];
|
|
121
|
+
}
|
|
122
|
+
_this2 = _super2.call.apply(_super2, [this].concat(args));
|
|
123
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this2), "unmuteAllowed", true);
|
|
124
|
+
return _this2;
|
|
125
|
+
}
|
|
126
|
+
(0, _createClass2.default)(LocalCameraTrack, [{
|
|
127
|
+
key: "setUnmuteAllowed",
|
|
128
|
+
value:
|
|
129
|
+
/**
|
|
130
|
+
* @internal
|
|
131
|
+
*/
|
|
132
|
+
function setUnmuteAllowed(allowed) {
|
|
133
|
+
this.unmuteAllowed = allowed;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* @returns true if user is allowed to unmute the track, false otherwise
|
|
138
|
+
*/
|
|
139
|
+
}, {
|
|
140
|
+
key: "isUnmuteAllowed",
|
|
141
|
+
value: function isUnmuteAllowed() {
|
|
142
|
+
return this.unmuteAllowed;
|
|
143
|
+
}
|
|
144
|
+
}, {
|
|
145
|
+
key: "setMuted",
|
|
146
|
+
value: function setMuted(muted) {
|
|
147
|
+
if (!muted) {
|
|
148
|
+
if (!this.isUnmuteAllowed()) {
|
|
149
|
+
throw new Error('Unmute is not allowed');
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return (0, _get2.default)((0, _getPrototypeOf2.default)(LocalCameraTrack.prototype), "setMuted", this).call(this, muted);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* @internal
|
|
157
|
+
*/
|
|
158
|
+
}, {
|
|
159
|
+
key: "setServerMuted",
|
|
160
|
+
value: function setServerMuted(muted, reason) {
|
|
161
|
+
if (muted !== this.muted) {
|
|
162
|
+
this.setMuted(muted);
|
|
163
|
+
this.emit(LocalCameraTrackEvents.ServerMuted, {
|
|
164
|
+
muted: muted,
|
|
165
|
+
reason: reason
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}]);
|
|
170
|
+
return LocalCameraTrack;
|
|
171
|
+
}(_internalMediaCore.LocalCameraTrack);
|
|
172
|
+
exports.LocalCameraTrack = LocalCameraTrack;
|
|
173
|
+
var createMicrophoneTrack = function createMicrophoneTrack(constraints) {
|
|
174
|
+
return (0, _internalMediaCore.createMicrophoneTrack)(LocalMicrophoneTrack, constraints);
|
|
175
|
+
};
|
|
176
|
+
exports.createMicrophoneTrack = createMicrophoneTrack;
|
|
177
|
+
var createCameraTrack = function createCameraTrack(constraints) {
|
|
178
|
+
return (0, _internalMediaCore.createCameraTrack)(LocalCameraTrack, constraints);
|
|
179
|
+
};
|
|
180
|
+
exports.createCameraTrack = createCameraTrack;
|
|
181
|
+
var createDisplayTrack = function createDisplayTrack() {
|
|
182
|
+
return (0, _internalMediaCore.createDisplayTrack)(_internalMediaCore.LocalDisplayTrack);
|
|
183
|
+
};
|
|
184
|
+
exports.createDisplayTrack = createDisplayTrack;
|
|
185
|
+
//# sourceMappingURL=webrtc-core.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["LocalMicrophoneTrackEvents","LocalCameraTrackEvents","LocalMicrophoneTrack","allowed","unmuteAllowed","muted","isUnmuteAllowed","Error","reason","setMuted","emit","ServerMuted","WcmeLocalMicrophoneTrack","LocalCameraTrack","WcmeLocalCameraTrack","createMicrophoneTrack","constraints","wcmeCreateMicrophoneTrack","createCameraTrack","wcmeCreateCameraTrack","createDisplayTrack","wcmeCreateDisplayTrack","LocalDisplayTrack"],"sources":["webrtc-core.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-misused-new */\n/* eslint-disable valid-jsdoc */\n/* eslint-disable require-jsdoc */\nimport {\n AudioDeviceConstraints,\n createCameraTrack as wcmeCreateCameraTrack,\n createDisplayTrack as wcmeCreateDisplayTrack,\n createMicrophoneTrack as wcmeCreateMicrophoneTrack,\n LocalDisplayTrack,\n LocalMicrophoneTrack as WcmeLocalMicrophoneTrack,\n LocalCameraTrack as WcmeLocalCameraTrack,\n VideoDeviceConstraints,\n} from '@webex/internal-media-core';\n\nexport {\n LocalTrack,\n LocalDisplayTrack,\n LocalTrackEvents,\n type TrackMuteEvent,\n} from '@webex/internal-media-core';\n\nexport type ServerMuteReason =\n | 'remotelyMuted' // other user has remotely muted us\n | 'clientRequestFailed' // client called setMuted() but server request failed\n | 'localUnmuteRequired'; // server forced the client to be unmuted\n\n// these events are in addition to WCME events. This will be properly typed once webrtc-core event types inheritance is fixed\nexport enum LocalMicrophoneTrackEvents {\n ServerMuted = 'muted:byServer',\n}\n\n// these events are in addition to WCME events. This will be properly typed once webrtc-core event types inheritance is fixed\nexport enum LocalCameraTrackEvents {\n ServerMuted = 'muted:byServer',\n}\n\nexport class LocalMicrophoneTrack extends WcmeLocalMicrophoneTrack {\n private unmuteAllowed = true;\n\n /**\n * @internal\n */\n setUnmuteAllowed(allowed) {\n this.unmuteAllowed = allowed;\n }\n\n /**\n * @returns true if user is allowed to unmute the track, false otherwise\n */\n isUnmuteAllowed() {\n return this.unmuteAllowed;\n }\n\n setMuted(muted: boolean): void {\n if (!muted) {\n if (!this.isUnmuteAllowed()) {\n throw new Error('Unmute is not allowed');\n }\n }\n\n return super.setMuted(muted);\n }\n\n /**\n * @internal\n */\n setServerMuted(muted: boolean, reason: ServerMuteReason) {\n if (muted !== this.muted) {\n this.setMuted(muted);\n this.emit(LocalMicrophoneTrackEvents.ServerMuted, {muted, reason});\n }\n }\n}\n\nexport class LocalCameraTrack extends WcmeLocalCameraTrack {\n private unmuteAllowed = true;\n\n /**\n * @internal\n */\n setUnmuteAllowed(allowed) {\n this.unmuteAllowed = allowed;\n }\n\n /**\n * @returns true if user is allowed to unmute the track, false otherwise\n */\n isUnmuteAllowed() {\n return this.unmuteAllowed;\n }\n\n setMuted(muted: boolean): void {\n if (!muted) {\n if (!this.isUnmuteAllowed()) {\n throw new Error('Unmute is not allowed');\n }\n }\n\n return super.setMuted(muted);\n }\n\n /**\n * @internal\n */\n setServerMuted(muted: boolean, reason: ServerMuteReason) {\n if (muted !== this.muted) {\n this.setMuted(muted);\n this.emit(LocalCameraTrackEvents.ServerMuted, {muted, reason});\n }\n }\n}\n\nexport const createMicrophoneTrack = (constraints?: AudioDeviceConstraints) =>\n wcmeCreateMicrophoneTrack(LocalMicrophoneTrack, constraints);\n\nexport const createCameraTrack = (constraints?: VideoDeviceConstraints) =>\n wcmeCreateCameraTrack(LocalCameraTrack, constraints);\n\nexport const createDisplayTrack = () => wcmeCreateDisplayTrack(LocalDisplayTrack);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA;AASoC;AAAA;AAYT;AAE3B;AAAA,IACYA,0BAA0B,EAItC;AAAA;AAAA,WAJYA,0BAA0B;EAA1BA,0BAA0B;AAAA,GAA1BA,0BAA0B,0CAA1BA,0BAA0B;AAAA,IAK1BC,sBAAsB;AAAA;AAAA,WAAtBA,sBAAsB;EAAtBA,sBAAsB;AAAA,GAAtBA,sBAAsB,sCAAtBA,sBAAsB;AAAA,IAIrBC,oBAAoB;EAAA;EAAA;EAAA;IAAA;IAAA;IAAA;MAAA;IAAA;IAAA;IAAA,4FACP,IAAI;IAAA;EAAA;EAAA;IAAA;IAAA;IAE5B;AACF;AACA;IACE,0BAAiBC,OAAO,EAAE;MACxB,IAAI,CAACC,aAAa,GAAGD,OAAO;IAC9B;;IAEA;AACF;AACA;EAFE;IAAA;IAAA,OAGA,2BAAkB;MAChB,OAAO,IAAI,CAACC,aAAa;IAC3B;EAAC;IAAA;IAAA,OAED,kBAASC,KAAc,EAAQ;MAC7B,IAAI,CAACA,KAAK,EAAE;QACV,IAAI,CAAC,IAAI,CAACC,eAAe,EAAE,EAAE;UAC3B,MAAM,IAAIC,KAAK,CAAC,uBAAuB,CAAC;QAC1C;MACF;MAEA,sHAAsBF,KAAK;IAC7B;;IAEA;AACF;AACA;EAFE;IAAA;IAAA,OAGA,wBAAeA,KAAc,EAAEG,MAAwB,EAAE;MACvD,IAAIH,KAAK,KAAK,IAAI,CAACA,KAAK,EAAE;QACxB,IAAI,CAACI,QAAQ,CAACJ,KAAK,CAAC;QACpB,IAAI,CAACK,IAAI,CAACV,0BAA0B,CAACW,WAAW,EAAE;UAACN,KAAK,EAALA,KAAK;UAAEG,MAAM,EAANA;QAAM,CAAC,CAAC;MACpE;IACF;EAAC;EAAA;AAAA,EAnCuCI,uCAAwB;AAAA;AAAA,IAsCrDC,gBAAgB;EAAA;EAAA;EAAA;IAAA;IAAA;IAAA;MAAA;IAAA;IAAA;IAAA,6FACH,IAAI;IAAA;EAAA;EAAA;IAAA;IAAA;IAE5B;AACF;AACA;IACE,0BAAiBV,OAAO,EAAE;MACxB,IAAI,CAACC,aAAa,GAAGD,OAAO;IAC9B;;IAEA;AACF;AACA;EAFE;IAAA;IAAA,OAGA,2BAAkB;MAChB,OAAO,IAAI,CAACC,aAAa;IAC3B;EAAC;IAAA;IAAA,OAED,kBAASC,KAAc,EAAQ;MAC7B,IAAI,CAACA,KAAK,EAAE;QACV,IAAI,CAAC,IAAI,CAACC,eAAe,EAAE,EAAE;UAC3B,MAAM,IAAIC,KAAK,CAAC,uBAAuB,CAAC;QAC1C;MACF;MAEA,kHAAsBF,KAAK;IAC7B;;IAEA;AACF;AACA;EAFE;IAAA;IAAA,OAGA,wBAAeA,KAAc,EAAEG,MAAwB,EAAE;MACvD,IAAIH,KAAK,KAAK,IAAI,CAACA,KAAK,EAAE;QACxB,IAAI,CAACI,QAAQ,CAACJ,KAAK,CAAC;QACpB,IAAI,CAACK,IAAI,CAACT,sBAAsB,CAACU,WAAW,EAAE;UAACN,KAAK,EAALA,KAAK;UAAEG,MAAM,EAANA;QAAM,CAAC,CAAC;MAChE;IACF;EAAC;EAAA;AAAA,EAnCmCM,mCAAoB;AAAA;AAsCnD,IAAMC,qBAAqB,GAAG,SAAxBA,qBAAqB,CAAIC,WAAoC;EAAA,OACxE,IAAAC,wCAAyB,EAACf,oBAAoB,EAAEc,WAAW,CAAC;AAAA;AAAC;AAExD,IAAME,iBAAiB,GAAG,SAApBA,iBAAiB,CAAIF,WAAoC;EAAA,OACpE,IAAAG,oCAAqB,EAACN,gBAAgB,EAAEG,WAAW,CAAC;AAAA;AAAC;AAEhD,IAAMI,kBAAkB,GAAG,SAArBA,kBAAkB;EAAA,OAAS,IAAAC,qCAAsB,EAACC,oCAAiB,CAAC;AAAA;AAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@webex/media-helpers",
|
|
3
|
+
"version": "3.0.0-beta.87",
|
|
4
|
+
"description": "",
|
|
5
|
+
"license": "Cisco EULA (https://www.cisco.com/c/en/us/products/end-user-license-agreement.html)",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"devMain": "src/index.ts",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/webex/webex-js-sdk.git",
|
|
11
|
+
"directory": "packages/@webex/media-helpers"
|
|
12
|
+
},
|
|
13
|
+
"engines": {
|
|
14
|
+
"node": ">=16"
|
|
15
|
+
},
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@webex/internal-media-core": "1.36.0"
|
|
18
|
+
},
|
|
19
|
+
"browserify": {
|
|
20
|
+
"transform": [
|
|
21
|
+
"babelify",
|
|
22
|
+
"envify"
|
|
23
|
+
]
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@webex/test-helper-chai": "3.0.0-beta.87",
|
|
27
|
+
"@webex/test-helper-mock-webex": "3.0.0-beta.87",
|
|
28
|
+
"sinon": "^9.2.4"
|
|
29
|
+
}
|
|
30
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export {
|
|
2
|
+
LocalTrack,
|
|
3
|
+
LocalDisplayTrack,
|
|
4
|
+
LocalTrackEvents,
|
|
5
|
+
type TrackMuteEvent,
|
|
6
|
+
type ServerMuteReason,
|
|
7
|
+
LocalMicrophoneTrackEvents,
|
|
8
|
+
LocalCameraTrackEvents,
|
|
9
|
+
LocalMicrophoneTrack,
|
|
10
|
+
LocalCameraTrack,
|
|
11
|
+
createMicrophoneTrack,
|
|
12
|
+
createCameraTrack,
|
|
13
|
+
createDisplayTrack,
|
|
14
|
+
} from './webrtc-core';
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-misused-new */
|
|
2
|
+
/* eslint-disable valid-jsdoc */
|
|
3
|
+
/* eslint-disable require-jsdoc */
|
|
4
|
+
import {
|
|
5
|
+
AudioDeviceConstraints,
|
|
6
|
+
createCameraTrack as wcmeCreateCameraTrack,
|
|
7
|
+
createDisplayTrack as wcmeCreateDisplayTrack,
|
|
8
|
+
createMicrophoneTrack as wcmeCreateMicrophoneTrack,
|
|
9
|
+
LocalDisplayTrack,
|
|
10
|
+
LocalMicrophoneTrack as WcmeLocalMicrophoneTrack,
|
|
11
|
+
LocalCameraTrack as WcmeLocalCameraTrack,
|
|
12
|
+
VideoDeviceConstraints,
|
|
13
|
+
} from '@webex/internal-media-core';
|
|
14
|
+
|
|
15
|
+
export {
|
|
16
|
+
LocalTrack,
|
|
17
|
+
LocalDisplayTrack,
|
|
18
|
+
LocalTrackEvents,
|
|
19
|
+
type TrackMuteEvent,
|
|
20
|
+
} from '@webex/internal-media-core';
|
|
21
|
+
|
|
22
|
+
export type ServerMuteReason =
|
|
23
|
+
| 'remotelyMuted' // other user has remotely muted us
|
|
24
|
+
| 'clientRequestFailed' // client called setMuted() but server request failed
|
|
25
|
+
| 'localUnmuteRequired'; // server forced the client to be unmuted
|
|
26
|
+
|
|
27
|
+
// these events are in addition to WCME events. This will be properly typed once webrtc-core event types inheritance is fixed
|
|
28
|
+
export enum LocalMicrophoneTrackEvents {
|
|
29
|
+
ServerMuted = 'muted:byServer',
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// these events are in addition to WCME events. This will be properly typed once webrtc-core event types inheritance is fixed
|
|
33
|
+
export enum LocalCameraTrackEvents {
|
|
34
|
+
ServerMuted = 'muted:byServer',
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export class LocalMicrophoneTrack extends WcmeLocalMicrophoneTrack {
|
|
38
|
+
private unmuteAllowed = true;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* @internal
|
|
42
|
+
*/
|
|
43
|
+
setUnmuteAllowed(allowed) {
|
|
44
|
+
this.unmuteAllowed = allowed;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* @returns true if user is allowed to unmute the track, false otherwise
|
|
49
|
+
*/
|
|
50
|
+
isUnmuteAllowed() {
|
|
51
|
+
return this.unmuteAllowed;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
setMuted(muted: boolean): void {
|
|
55
|
+
if (!muted) {
|
|
56
|
+
if (!this.isUnmuteAllowed()) {
|
|
57
|
+
throw new Error('Unmute is not allowed');
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return super.setMuted(muted);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* @internal
|
|
66
|
+
*/
|
|
67
|
+
setServerMuted(muted: boolean, reason: ServerMuteReason) {
|
|
68
|
+
if (muted !== this.muted) {
|
|
69
|
+
this.setMuted(muted);
|
|
70
|
+
this.emit(LocalMicrophoneTrackEvents.ServerMuted, {muted, reason});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export class LocalCameraTrack extends WcmeLocalCameraTrack {
|
|
76
|
+
private unmuteAllowed = true;
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* @internal
|
|
80
|
+
*/
|
|
81
|
+
setUnmuteAllowed(allowed) {
|
|
82
|
+
this.unmuteAllowed = allowed;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* @returns true if user is allowed to unmute the track, false otherwise
|
|
87
|
+
*/
|
|
88
|
+
isUnmuteAllowed() {
|
|
89
|
+
return this.unmuteAllowed;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
setMuted(muted: boolean): void {
|
|
93
|
+
if (!muted) {
|
|
94
|
+
if (!this.isUnmuteAllowed()) {
|
|
95
|
+
throw new Error('Unmute is not allowed');
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return super.setMuted(muted);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* @internal
|
|
104
|
+
*/
|
|
105
|
+
setServerMuted(muted: boolean, reason: ServerMuteReason) {
|
|
106
|
+
if (muted !== this.muted) {
|
|
107
|
+
this.setMuted(muted);
|
|
108
|
+
this.emit(LocalCameraTrackEvents.ServerMuted, {muted, reason});
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export const createMicrophoneTrack = (constraints?: AudioDeviceConstraints) =>
|
|
114
|
+
wcmeCreateMicrophoneTrack(LocalMicrophoneTrack, constraints);
|
|
115
|
+
|
|
116
|
+
export const createCameraTrack = (constraints?: VideoDeviceConstraints) =>
|
|
117
|
+
wcmeCreateCameraTrack(LocalCameraTrack, constraints);
|
|
118
|
+
|
|
119
|
+
export const createDisplayTrack = () => wcmeCreateDisplayTrack(LocalDisplayTrack);
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import {assert, expect} from '@webex/test-helper-chai';
|
|
2
|
+
import sinon from 'sinon';
|
|
3
|
+
import {LocalCameraTrack, LocalMicrophoneTrack, LocalMicrophoneTrackEvents, LocalCameraTrackEvents, LocalDisplayTrack, createCameraTrack, createMicrophoneTrack, createDisplayTrack} from '@webex/media-helpers';
|
|
4
|
+
import * as wcmetracks from '@webex/internal-media-core';
|
|
5
|
+
|
|
6
|
+
describe('media-helpers', () => {
|
|
7
|
+
describe('webrtc-core', () => {
|
|
8
|
+
|
|
9
|
+
const classesToTest = [
|
|
10
|
+
{className: LocalCameraTrack, title: 'LocalCameraTrack', event: LocalCameraTrackEvents, createFn: createCameraTrack, spyFn: 'createCameraTrack'},
|
|
11
|
+
{className: LocalMicrophoneTrack, title: 'LocalMicrophoneTrack', event: LocalMicrophoneTrackEvents, createFn: createMicrophoneTrack, spyFn: 'createMicrophoneTrack'},
|
|
12
|
+
];
|
|
13
|
+
|
|
14
|
+
classesToTest.forEach(({className, title, event, createFn, spyFn}) =>
|
|
15
|
+
describe(title, () => {
|
|
16
|
+
const fakeStream = {
|
|
17
|
+
getTracks: sinon.stub().returns([{
|
|
18
|
+
label: 'fake track',
|
|
19
|
+
id: 'fake track id',
|
|
20
|
+
enabled: true,
|
|
21
|
+
}])
|
|
22
|
+
};
|
|
23
|
+
const track = new className(fakeStream);
|
|
24
|
+
|
|
25
|
+
afterEach(() => {
|
|
26
|
+
sinon.restore();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('by default allows unmuting', async () => {
|
|
30
|
+
assert.equal(track.isUnmuteAllowed(), true);
|
|
31
|
+
await track.setMuted(false);
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
it('rejects setMute(false) if unmute is not allowed', async () => {
|
|
35
|
+
track.setUnmuteAllowed(false);
|
|
36
|
+
|
|
37
|
+
assert.equal(track.isUnmuteAllowed(), false);
|
|
38
|
+
const fn = () => track.setMuted(false);
|
|
39
|
+
expect(fn).to.throw(/Unmute is not allowed/);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('resolves setMute(false) if unmute is allowed', async () => {
|
|
43
|
+
track.setUnmuteAllowed(true);
|
|
44
|
+
|
|
45
|
+
assert.equal(track.isUnmuteAllowed(), true);
|
|
46
|
+
await track.setMuted(false);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
describe('#setServerMuted', () => {
|
|
50
|
+
|
|
51
|
+
afterEach(() => {
|
|
52
|
+
sinon.restore();
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
const checkSetServerMuted = async (startMute, setMute, expectedCalled) => {
|
|
56
|
+
await track.setMuted(startMute);
|
|
57
|
+
|
|
58
|
+
assert.equal(track.muted, startMute);
|
|
59
|
+
|
|
60
|
+
const handler = sinon.fake();
|
|
61
|
+
track.on(event.ServerMuted, handler);
|
|
62
|
+
|
|
63
|
+
await track.setServerMuted(setMute, 'remotelyMuted');
|
|
64
|
+
|
|
65
|
+
assert.equal(track.muted, setMute);
|
|
66
|
+
if (expectedCalled) {
|
|
67
|
+
assert.calledOnceWithExactly(handler, {muted: setMute, reason: 'remotelyMuted'});
|
|
68
|
+
} else {
|
|
69
|
+
assert.notCalled(handler);
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
it('tests true to false', async () => {
|
|
74
|
+
await checkSetServerMuted(true, false, true);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('tests false to true', async () => {
|
|
78
|
+
await checkSetServerMuted(false, true, true);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('tests true to true', async () => {
|
|
82
|
+
await checkSetServerMuted(true, true, false);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it('tests false to false', async () => {
|
|
86
|
+
await checkSetServerMuted(false, false, false);
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
describe('#wcmeCreateMicrophoneTrack, #wcmeCreateCameraTrack', () => {
|
|
91
|
+
it('checks creating tracks', async () => {
|
|
92
|
+
const constraints = {devideId: 'abc'};
|
|
93
|
+
|
|
94
|
+
const spy = sinon.stub(wcmetracks, spyFn).returns('something');
|
|
95
|
+
const result = createFn(constraints);
|
|
96
|
+
|
|
97
|
+
assert.equal(result, 'something');
|
|
98
|
+
assert.calledOnceWithExactly(spy, className, constraints);
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
})
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
describe('createDisplayTrack', () => {
|
|
106
|
+
it('checks createDisplayTrack', async () => {
|
|
107
|
+
const spy = sinon.stub(wcmetracks, 'createDisplayTrack').returns('something');
|
|
108
|
+
const result = createDisplayTrack();
|
|
109
|
+
assert.equal(result, 'something');
|
|
110
|
+
assert.calledOnceWithExactly(spy, LocalDisplayTrack);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
});
|