android-emulator-webrtc 1.0.16 → 1.0.17

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.
Files changed (31) hide show
  1. package/.vscode/settings.json +3 -0
  2. package/api_descriptor.pb +0 -0
  3. package/dist/components/emulator/emulator.js +43 -56
  4. package/dist/components/emulator/net/emulator_status.js +15 -23
  5. package/dist/components/emulator/net/jsep_protocol_driver.js +54 -104
  6. package/dist/components/emulator/net/logcat.js +34 -34
  7. package/dist/components/emulator/views/event_handler.js +57 -75
  8. package/dist/components/emulator/views/resizing_component.js +86 -0
  9. package/dist/components/emulator/views/simple_png_view.js +90 -206
  10. package/dist/components/emulator/views/webrtc_view.js +110 -174
  11. package/dist/index.js +4 -8
  12. package/dist/proto/emulator_controller_grpc_web_pb.js +454 -634
  13. package/dist/proto/emulator_controller_pb.js +4620 -3945
  14. package/dist/proto/emulator_web_client.js +26 -56
  15. package/dist/proto/rtc_service_grpc_web_pb.js +35 -101
  16. package/dist/proto/rtc_service_pb.js +31 -88
  17. package/package.json +25 -21
  18. package/proto/README.MD +1 -1
  19. package/proto/emulator_controller.proto +1090 -804
  20. package/protoc-plugin/grpc_generator.cc +661 -549
  21. package/src/components/emulator/emulator.js +3 -10
  22. package/src/components/emulator/net/jsep_protocol_driver.js +0 -2
  23. package/src/components/emulator/views/resizing_component.js +65 -0
  24. package/src/components/emulator/views/simple_png_view.js +81 -134
  25. package/src/components/emulator/views/webrtc_view.js +87 -95
  26. package/test/emulator.test.js +7 -7
  27. package/test/event_handler.test.js +3 -0
  28. package/test/jsep_protocol_driver.test.js +3 -0
  29. package/test/resizing_component.test.js +37 -0
  30. package/test/simple_png_view.test.js +54 -42
  31. package/test/touch_event_handler.test.js +3 -1
@@ -1,227 +1,111 @@
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
  var Proto = _interopRequireWildcard(require("../../../proto/emulator_controller_pb"));
31
-
32
- var _reactResizeObserver = _interopRequireDefault(require("react-resize-observer"));
33
-
34
13
  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); }
35
-
36
14
  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; }
37
-
38
- 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); }; }
39
-
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
-
42
- /**
43
- * A view on the emulator that is generated by streaming a series of screenshots.
44
- *
45
- * Note: This is very expensive when running remote, and does not support audio.
46
- */
47
- var EmulatorPngView = /*#__PURE__*/function (_Component) {
48
- (0, _inherits2["default"])(EmulatorPngView, _Component);
49
-
50
- var _super = _createSuper(EmulatorPngView);
51
-
52
- function EmulatorPngView() {
53
- var _this;
54
-
55
- (0, _classCallCheck2["default"])(this, EmulatorPngView);
56
-
57
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
58
- args[_key] = arguments[_key];
59
- }
60
-
61
- _this = _super.call.apply(_super, [this].concat(args));
62
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "state", {
63
- /** Currently displayed image, retrieved from the emulator. */
64
- png: "",
65
- width: null,
66
- height: null,
67
- connect: "connecting"
68
- });
69
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "preventDragHandler", function (e) {
70
- e.preventDefault();
71
- });
72
- return _this;
73
- }
74
-
75
- (0, _createClass2["default"])(EmulatorPngView, [{
76
- key: "broadcastState",
77
- value: function broadcastState() {
78
- var onStateChange = this.props.onStateChange;
79
-
80
- if (onStateChange) {
81
- onStateChange(this.state.connect);
15
+ var EmulatorPngView = function EmulatorPngView(_ref) {
16
+ var emulator = _ref.emulator,
17
+ onStateChange = _ref.onStateChange,
18
+ poll = _ref.poll,
19
+ width = _ref.width,
20
+ height = _ref.height,
21
+ dataTestId = _ref["data-testid"];
22
+ var _useState = (0, _react.useState)(""),
23
+ _useState2 = (0, _slicedToArray2["default"])(_useState, 2),
24
+ png = _useState2[0],
25
+ setPng = _useState2[1];
26
+ var _useState3 = (0, _react.useState)("connecting"),
27
+ _useState4 = (0, _slicedToArray2["default"])(_useState3, 2),
28
+ connect = _useState4[0],
29
+ setConnect = _useState4[1];
30
+ var screenShot = null;
31
+ (0, _react.useEffect)(function () {
32
+ startStream();
33
+ return function () {
34
+ setConnect("disconnected");
35
+ if (screenShot) {
36
+ screenShot.cancel();
82
37
  }
38
+ };
39
+ }, [width, height]);
40
+ (0, _react.useEffect)(function () {
41
+ console.log("Png state changed to: " + connect);
42
+ if (onStateChange) {
43
+ onStateChange(connect);
83
44
  }
84
- }, {
85
- key: "componentDidMount",
86
- value: function componentDidMount() {
87
- this.setState({
88
- connect: "connecting"
89
- }, this.broadcastState);
90
- this.startStream();
45
+ }, [connect]);
46
+ var startStream = function startStream() {
47
+ setConnect("connecting");
48
+ var request = new Proto.ImageFormat();
49
+ if (!isNaN(width)) {
50
+ request.setWidth(Math.floor(width));
91
51
  }
92
- }, {
93
- key: "componentWillUnmount",
94
- value: function componentWillUnmount() {
95
- this.setState({
96
- connect: "disconnected"
97
- }, this.broadcastState);
98
-
99
- if (this.screen) {
100
- this.screen.cancel();
101
- }
52
+ if (!isNaN(height)) {
53
+ request.setWidth(Math.floor(height));
102
54
  }
103
- }, {
104
- key: "startStream",
105
- value: function startStream() {
106
- var _this2 = this;
107
-
108
- var _this$state = this.state,
109
- width = _this$state.width,
110
- height = _this$state.height,
111
- connect = _this$state.connect;
112
-
113
- if (this.screen) {
114
- this.screen.cancel();
115
- }
116
-
117
- var request = new Proto.ImageFormat();
118
-
119
- if (!isNaN(width)) {
120
- request.setWidth(Math.floor(width));
121
- request.setHeight(Math.floor(height));
122
- }
123
-
124
- var self = this;
125
- var _this$props = this.props,
126
- emulator = _this$props.emulator,
127
- poll = _this$props.poll;
128
-
129
- if (poll && connect !== "disconnected") {
130
- emulator.getScreenshot(request, {}, function (err, response) {
131
- _this2.setState({
132
- connect: "connected"
133
- }, _this2.broadcastState); // Update the image with the one we just received.
134
-
135
-
136
- self.setState({
137
- png: "data:image/jpeg;base64," + response.getImage_asB64()
138
- }, _this2.startStream);
139
- });
140
- } else {
141
- this.screen = emulator.streamScreenshot(request);
142
- this.screen.on("data", function (response) {
143
- self.setState({
144
- connect: "connected"
145
- }, _this2.broadcastState); // Update the image with the one we just received.
146
-
147
- self.setState({
148
- png: "data:image/jpeg;base64," + response.getImage_asB64()
149
- });
150
- });
151
- this.screen.on("error", function (e) {
152
- console.warn("Screenshot stream broken", e);
153
- var connect = _this2.state.connect;
154
-
155
- if (connect === "connected") {
156
- console.log("Reconnecting..");
157
- self.setState({
158
- connect: "connecting"
159
- }, _this2.startStream);
160
- } else {
161
- self.setState({
162
- connect: "disconnected"
163
- }, _this2.broadcastState);
164
- }
165
- });
166
- }
167
- }
168
- }, {
169
- key: "render",
170
- value: function render() {
171
- var width = this.props.width;
172
- var self = this;
173
- return /*#__PURE__*/_react["default"].createElement("div", {
174
- width: width,
175
- style: {
176
- display: "block",
177
- position: "relative",
178
- height: "100%",
179
- objectFit: "contain",
180
- objectPosition: "center"
181
- },
182
- onDragStart: this.preventDragHandler
183
- }, /*#__PURE__*/_react["default"].createElement(_reactResizeObserver["default"], {
184
- onReflow: function onReflow(rect) {
185
- self.setState({
186
- width: rect.width,
187
- height: rect.height
188
- }, self.startStream);
189
- }
190
- }), /*#__PURE__*/_react["default"].createElement("img", {
191
- src: this.state.png,
192
- width: "100%",
193
- draggable: "false",
194
- style: {
195
- pointerEvents: "none"
55
+ if (poll && connect !== "disconnected") {
56
+ emulator.getScreenshot(request, {}, function (err, response) {
57
+ setConnect("connected");
58
+ setPng("data:image/jpeg;base64," + response.getImage_asB64());
59
+ startStream();
60
+ });
61
+ } else {
62
+ var receivedImage = false;
63
+ screenShot = emulator.streamScreenshot(request);
64
+ screenShot.on("data", function (response) {
65
+ receivedImage = true;
66
+ setConnect("connected");
67
+ setPng("data:image/jpeg;base64," + response.getImage_asB64());
68
+ });
69
+ screenShot.on("error", function (e) {
70
+ console.warn("Screenshot stream broken", e);
71
+ if (receivedImage) {
72
+ setConnect("connecting");
73
+ startStream();
74
+ } else {
75
+ setConnect("disconnected");
196
76
  }
197
- }));
77
+ });
198
78
  }
199
- }]);
200
- return EmulatorPngView;
201
- }(_react.Component);
202
-
203
- exports["default"] = EmulatorPngView;
204
- (0, _defineProperty2["default"])(EmulatorPngView, "propTypes", {
205
- /** Emulator service used to retrieve screenshots. */
79
+ };
80
+ var preventDragHandler = function preventDragHandler(e) {
81
+ e.preventDefault();
82
+ };
83
+ return /*#__PURE__*/_react["default"].createElement("div", {
84
+ width: width,
85
+ style: {
86
+ display: "block",
87
+ position: "relative",
88
+ height: "100%",
89
+ objectFit: "contain",
90
+ objectPosition: "center"
91
+ },
92
+ onDragStart: preventDragHandler
93
+ }, /*#__PURE__*/_react["default"].createElement("img", {
94
+ src: png,
95
+ width: "100%",
96
+ draggable: "false",
97
+ style: {
98
+ pointerEvents: "none"
99
+ }
100
+ }));
101
+ };
102
+ EmulatorPngView.propTypes = {
206
103
  emulator: _propTypes["default"].object,
207
-
208
- /** The width of the component */
209
- width: _propTypes["default"].number,
210
-
211
- /** Function called when the state of the emulator changes,
212
- *
213
- * The state will be one of:
214
- *
215
- * - "connecting"
216
- * - "connected"
217
- * - "disconnected"
218
- *
219
- * The png view only supports streaming of images, and not audio.
220
- */
221
104
  onStateChange: _propTypes["default"].func,
222
-
223
- /** True if polling should be used, only set this to true if you are using the gowebrpc proxy.
224
- * Note: Deprecated, setting this to true results in poor performance.
225
- */
226
- poll: _propTypes["default"].bool
227
- });
105
+ poll: _propTypes["default"].bool,
106
+ width: _propTypes["default"].number,
107
+ height: _propTypes["default"].number,
108
+ "data-testid": _propTypes["default"].string
109
+ };
110
+ var _default = EmulatorPngView;
111
+ exports["default"] = _default;
@@ -1,201 +1,135 @@
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
+ console.log("Webrtc state changed to: " + connect);
48
+ if (onStateChange) {
49
+ onStateChange(connect);
131
50
  }
132
- }, {
133
- key: "componentWillUnmount",
134
- value: function componentWillUnmount() {
135
- this.props.jsep.disconnect();
51
+ }, [connect]);
52
+ (0, _react.useEffect)(function () {
53
+ console.log("Webrtc audio state changed to: " + audio);
54
+ if (onAudioStateChange) {
55
+ onAudioStateChange(audio);
136
56
  }
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
- });
57
+ }, [audio]);
58
+ var onDisconnect = function onDisconnect() {
59
+ setConnect("disconnected");
60
+ setAudio(false);
61
+ };
62
+ var onConnect = function onConnect(track) {
63
+ setConnect("connected");
64
+ var video = videoRef.current;
65
+ if (!video) {
66
+ // Component was unmounted.
67
+ return;
68
+ }
69
+ if (!video.srcObject) {
70
+ video.srcObject = new MediaStream();
71
+ }
72
+ video.srcObject.addTrack(track);
73
+ if (track.kind === "audio") {
74
+ setAudio(true);
151
75
  }
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
76
+ };
77
+ var safePlay = function safePlay() {
78
+ var video = videoRef.current;
79
+ if (!video) {
80
+ // Component was unmounted.
81
+ return;
82
+ }
83
+ var possiblePromise = video.play();
84
+ if (possiblePromise) {
85
+ possiblePromise.then(function (_) {
86
+ console.debug("Automatic playback started!");
87
+ })["catch"](function (error) {
88
+ // Notify listeners that we cannot start.
89
+ onError(error);
172
90
  });
173
91
  }
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. */
92
+ };
93
+ var onCanPlay = function onCanPlay() {
94
+ safePlay();
95
+ };
96
+ var onContextMenu = function onContextMenu(e) {
97
+ e.preventDefault();
98
+ };
99
+ (0, _react.useEffect)(function () {
100
+ jsep.on("connected", onConnect);
101
+ jsep.on("disconnected", onDisconnect);
102
+ jsep.startStream();
103
+ setConnect("connecting");
104
+ return function () {
105
+ jsep.disconnect();
106
+ };
107
+ }, []);
108
+ return /*#__PURE__*/_react["default"].createElement("video", {
109
+ ref: videoRef,
110
+ style: {
111
+ display: "block",
112
+ position: "relative",
113
+ width: "100%",
114
+ height: "100%",
115
+ objectFit: "contain",
116
+ objectPosition: "center"
117
+ },
118
+ volume: volume,
119
+ muted: muted,
120
+ onContextMenu: onContextMenu,
121
+ onCanPlay: onCanPlay
122
+ });
123
+ };
124
+ EmulatorWebrtcView.propTypes = {
181
125
  jsep: _propTypes["default"].object,
182
-
183
- /** Function called when the connection state of the emulator changes */
184
126
  onStateChange: _propTypes["default"].func,
185
-
186
- /** Function called when the audio track becomes available */
187
127
  onAudioStateChange: _propTypes["default"].func,
188
-
189
- /** True if you wish to mute the audio */
190
128
  muted: _propTypes["default"].bool,
191
-
192
- /** Volume of the video element, value between 0 and 1. */
193
129
  volume: _propTypes["default"].number,
194
-
195
- /** Function called when an error arises, like play failures due to muting */
196
130
  onError: _propTypes["default"].func
197
- });
198
- (0, _defineProperty2["default"])(EmulatorWebrtcView, "defaultProps", {
131
+ };
132
+ EmulatorWebrtcView.defaultProps = {
199
133
  muted: true,
200
134
  volume: 1.0,
201
135
  onError: function onError(e) {
@@ -204,4 +138,6 @@ exports["default"] = EmulatorWebrtcView;
204
138
  onAudioStateChange: function onAudioStateChange(e) {
205
139
  return console.log("Webrtc audio became available: " + e);
206
140
  }
207
- });
141
+ };
142
+ var _default = EmulatorWebrtcView;
143
+ 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"));