android-emulator-webrtc 1.0.16 → 1.0.18

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.
@@ -1,207 +1,138 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  var _typeof = require("@babel/runtime/helpers/typeof");
6
-
7
5
  Object.defineProperty(exports, "__esModule", {
8
6
  value: true
9
7
  });
10
8
  exports["default"] = void 0;
11
-
12
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
13
-
14
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
15
-
16
- var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
17
-
18
- var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
19
-
20
- var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
21
-
22
- var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
23
-
24
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
25
-
9
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
26
10
  var _propTypes = _interopRequireDefault(require("prop-types"));
27
-
28
11
  var _react = _interopRequireWildcard(require("react"));
29
-
30
12
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
31
-
32
13
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
33
-
34
- 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); }; }
35
-
36
- 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; } }
37
-
38
- /**
39
- * A view on the emulator that is using WebRTC. It will use the Jsep protocol over gRPC to
40
- * establish the video streams.
14
+ /*
15
+ * Copyright 2019 The Android Open Source Project
16
+ *
17
+ * Licensed under the Apache License, Version 2.0 (the "License");
18
+ * you may not use this file except in compliance with the License.
19
+ * You may obtain a copy of the License at
20
+ *
21
+ * http://www.apache.org/licenses/LICENSE-2.0
22
+ *
23
+ * Unless required by applicable law or agreed to in writing, software
24
+ * distributed under the License is distributed on an "AS IS" BASIS,
25
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
26
+ * See the License for the specific language governing permissions and
27
+ * limitations under the License.
41
28
  */
42
- var EmulatorWebrtcView = /*#__PURE__*/function (_Component) {
43
- (0, _inherits2["default"])(EmulatorWebrtcView, _Component);
44
-
45
- var _super = _createSuper(EmulatorWebrtcView);
46
-
47
- function EmulatorWebrtcView(props) {
48
- var _this;
49
-
50
- (0, _classCallCheck2["default"])(this, EmulatorWebrtcView);
51
- _this = _super.call(this, props);
52
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "state", {
53
- audio: false
54
- });
55
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onDisconnect", function () {
56
- _this.setState({
57
- connect: "disconnected"
58
- }, _this.broadcastState);
59
-
60
- _this.setState({
61
- audio: false
62
- }, function () {
63
- _this.props.onAudioStateChange(false);
64
- });
65
- });
66
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onConnect", function (track) {
67
- _this.setState({
68
- connect: "connected"
69
- }, _this.broadcastState);
70
-
71
- var video = _this.video.current;
72
-
73
- if (!video) {
74
- // Component was unmounted.
75
- return;
76
- }
77
29
 
78
- if (!video.srcObject) {
79
- video.srcObject = new MediaStream();
80
- }
81
-
82
- video.srcObject.addTrack(track);
83
-
84
- if (track.kind === "audio") {
85
- _this.setState({
86
- audio: true
87
- }, function () {
88
- _this.props.onAudioStateChange(true);
89
- });
90
- }
91
- });
92
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "safePlay", function () {
93
- var video = _this.video.current;
94
- var self = (0, _assertThisInitialized2["default"])(_this);
95
-
96
- if (!video) {
97
- // Component was unmounted.
98
- return;
99
- } // See https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/play
100
-
101
-
102
- var possiblePromise = video.play();
103
-
104
- if (possiblePromise) {
105
- possiblePromise.then(function (_) {
106
- console.debug("Automatic playback started!");
107
- })["catch"](function (error) {
108
- // Notify listeners that we cannot start.
109
- self.onError(error);
110
- });
111
- }
112
- });
113
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onCanPlay", function (e) {
114
- _this.safePlay();
115
- });
116
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onContextMenu", function (e) {
117
- e.preventDefault();
118
- });
119
- _this.video = /*#__PURE__*/_react["default"].createRef();
120
- return _this;
121
- }
122
-
123
- (0, _createClass2["default"])(EmulatorWebrtcView, [{
124
- key: "broadcastState",
125
- value: function broadcastState() {
126
- var onStateChange = this.props.onStateChange;
127
-
128
- if (onStateChange) {
129
- onStateChange(this.state.connect);
130
- }
30
+ var EmulatorWebrtcView = function EmulatorWebrtcView(_ref) {
31
+ var jsep = _ref.jsep,
32
+ onStateChange = _ref.onStateChange,
33
+ onAudioStateChange = _ref.onAudioStateChange,
34
+ muted = _ref.muted,
35
+ volume = _ref.volume,
36
+ onError = _ref.onError;
37
+ var _useState = (0, _react.useState)(false),
38
+ _useState2 = (0, _slicedToArray2["default"])(_useState, 2),
39
+ audio = _useState2[0],
40
+ setAudio = _useState2[1];
41
+ var videoRef = (0, _react.useRef)(null);
42
+ var _useState3 = (0, _react.useState)("connecting"),
43
+ _useState4 = (0, _slicedToArray2["default"])(_useState3, 2),
44
+ connect = _useState4[0],
45
+ setConnect = _useState4[1];
46
+ (0, _react.useEffect)(function () {
47
+ if (onStateChange) {
48
+ onStateChange(connect);
131
49
  }
132
- }, {
133
- key: "componentWillUnmount",
134
- value: function componentWillUnmount() {
135
- this.props.jsep.disconnect();
50
+ }, [connect]);
51
+ (0, _react.useEffect)(function () {
52
+ if (onAudioStateChange) {
53
+ onAudioStateChange(audio);
136
54
  }
137
- }, {
138
- key: "componentDidMount",
139
- value: function componentDidMount() {
140
- var _this2 = this;
141
-
142
- this.props.jsep.on("connected", this.onConnect);
143
- this.props.jsep.on("disconnected", this.onDisconnect);
144
- this.setState({
145
- connect: "connecting"
146
- }, function () {
147
- _this2.props.jsep.startStream();
148
-
149
- _this2.broadcastState();
150
- });
55
+ }, [audio]);
56
+ var onDisconnect = function onDisconnect() {
57
+ setConnect("disconnected");
58
+ setAudio(false);
59
+ };
60
+ var onConnect = function onConnect(track) {
61
+ setConnect("connected");
62
+ var video = videoRef.current;
63
+ if (!video) {
64
+ // Component was unmounted.
65
+ return;
66
+ }
67
+ if (!video.srcObject) {
68
+ video.srcObject = new MediaStream();
69
+ }
70
+ video.srcObject.addTrack(track);
71
+ if (track.kind === "audio") {
72
+ setAudio(true);
151
73
  }
152
- }, {
153
- key: "render",
154
- value: function render() {
155
- var _this$props = this.props,
156
- muted = _this$props.muted,
157
- volume = _this$props.volume;
158
- return /*#__PURE__*/_react["default"].createElement("video", {
159
- ref: this.video,
160
- style: {
161
- display: "block",
162
- position: "relative",
163
- width: "100%",
164
- height: "100%",
165
- objectFit: "contain",
166
- objectPosition: "center"
167
- },
168
- volume: volume,
169
- muted: muted,
170
- onContextMenu: this.onContextMenu,
171
- onCanPlay: this.onCanPlay
74
+ };
75
+ var safePlay = function safePlay() {
76
+ var video = videoRef.current;
77
+ if (!video) {
78
+ // Component was unmounted.
79
+ return;
80
+ }
81
+ var possiblePromise = video.play();
82
+ if (possiblePromise) {
83
+ possiblePromise.then(function (_) {
84
+ console.debug("Automatic playback started!");
85
+ })["catch"](function (error) {
86
+ // Notify listeners that we cannot start.
87
+ onError(error);
172
88
  });
173
89
  }
174
- }]);
175
- return EmulatorWebrtcView;
176
- }(_react.Component);
177
-
178
- exports["default"] = EmulatorWebrtcView;
179
- (0, _defineProperty2["default"])(EmulatorWebrtcView, "propTypes", {
180
- /** Jsep protocol driver, used to establish the video stream. */
90
+ };
91
+ var onCanPlay = function onCanPlay() {
92
+ safePlay();
93
+ };
94
+ var onContextMenu = function onContextMenu(e) {
95
+ e.preventDefault();
96
+ };
97
+ (0, _react.useEffect)(function () {
98
+ jsep.on("connected", onConnect);
99
+ jsep.on("disconnected", onDisconnect);
100
+ jsep.startStream();
101
+ setConnect("connecting");
102
+ return function () {
103
+ jsep.disconnect();
104
+ };
105
+ }, []);
106
+ return /*#__PURE__*/_react["default"].createElement("video", {
107
+ ref: videoRef,
108
+ style: {
109
+ display: "block",
110
+ position: "relative",
111
+ width: "100%",
112
+ height: "100%",
113
+ objectFit: "contain",
114
+ objectPosition: "center"
115
+ },
116
+ volume: volume,
117
+ muted: muted,
118
+ onContextMenu: onContextMenu,
119
+ onCanPlay: onCanPlay
120
+ });
121
+ };
122
+ EmulatorWebrtcView.propTypes = {
181
123
  jsep: _propTypes["default"].object,
182
-
183
- /** Function called when the connection state of the emulator changes */
184
124
  onStateChange: _propTypes["default"].func,
185
-
186
- /** Function called when the audio track becomes available */
187
125
  onAudioStateChange: _propTypes["default"].func,
188
-
189
- /** True if you wish to mute the audio */
190
126
  muted: _propTypes["default"].bool,
191
-
192
- /** Volume of the video element, value between 0 and 1. */
193
127
  volume: _propTypes["default"].number,
194
-
195
- /** Function called when an error arises, like play failures due to muting */
196
128
  onError: _propTypes["default"].func
197
- });
198
- (0, _defineProperty2["default"])(EmulatorWebrtcView, "defaultProps", {
129
+ };
130
+ EmulatorWebrtcView.defaultProps = {
199
131
  muted: true,
200
132
  volume: 1.0,
201
133
  onError: function onError(e) {
202
134
  return console.error("WebRTC error: " + e);
203
- },
204
- onAudioStateChange: function onAudioStateChange(e) {
205
- return console.log("Webrtc audio became available: " + e);
206
135
  }
207
- });
136
+ };
137
+ var _default = EmulatorWebrtcView;
138
+ exports["default"] = _default;
package/dist/index.js CHANGED
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
@@ -11,21 +10,18 @@ Object.defineProperty(exports, "Emulator", {
11
10
  return _emulator["default"];
12
11
  }
13
12
  });
14
- Object.defineProperty(exports, "Logcat", {
13
+ Object.defineProperty(exports, "EmulatorStatus", {
15
14
  enumerable: true,
16
15
  get: function get() {
17
- return _logcat["default"];
16
+ return _emulator_status["default"];
18
17
  }
19
18
  });
20
- Object.defineProperty(exports, "EmulatorStatus", {
19
+ Object.defineProperty(exports, "Logcat", {
21
20
  enumerable: true,
22
21
  get: function get() {
23
- return _emulator_status["default"];
22
+ return _logcat["default"];
24
23
  }
25
24
  });
26
-
27
25
  var _emulator = _interopRequireDefault(require("./components/emulator/emulator"));
28
-
29
26
  var _logcat = _interopRequireDefault(require("./components/emulator/net/logcat"));
30
-
31
27
  var _emulator_status = _interopRequireDefault(require("./components/emulator/net/emulator_status"));