android-emulator-webrtc 1.0.15 → 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 +55 -105
  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 +1 -3
  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
@@ -0,0 +1,3 @@
1
+ {
2
+ "C_Cpp.default.configurationProvider": "ms-vscode.makefile-tools"
3
+ }
package/api_descriptor.pb CHANGED
Binary file
@@ -1,54 +1,47 @@
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
9
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
13
-
14
10
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
15
-
16
11
  var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
17
-
18
12
  var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
19
-
20
13
  var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
21
-
22
14
  var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
23
-
24
15
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
25
-
26
16
  var _propTypes = _interopRequireDefault(require("prop-types"));
27
-
28
17
  var _react = _interopRequireWildcard(require("react"));
29
-
30
18
  var _simple_png_view = _interopRequireDefault(require("./views/simple_png_view.js"));
31
-
32
19
  var _webrtc_view = _interopRequireDefault(require("./views/webrtc_view.js"));
33
-
34
20
  var _event_handler = _interopRequireDefault(require("./views/event_handler"));
35
-
36
21
  var _jsep_protocol_driver = _interopRequireDefault(require("./net/jsep_protocol_driver.js"));
37
-
38
22
  var Proto = _interopRequireWildcard(require("../../proto/emulator_controller_pb"));
39
-
40
23
  var _emulator_web_client = require("../../proto/emulator_web_client");
41
-
42
24
  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); }
43
-
44
25
  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; }
45
-
46
26
  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); }; }
47
-
48
- 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; } }
49
-
27
+ 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; } } /*
28
+ * Copyright 2019 The Android Open Source Project
29
+ *
30
+ * Licensed under the Apache License, Version 2.0 (the "License")
31
+ * you may not use this file except in compliance with the License.
32
+ * You may obtain a copy of the License at
33
+ *
34
+ * http://www.apache.org/licenses/LICENSE-2.0
35
+ *
36
+ * Unless required by applicable law or agreed to in writing, software
37
+ * distributed under the License is distributed on an "AS IS" BASIS,
38
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
39
+ * See the License for the specific language governing permissions and
40
+ * limitations under the License.
41
+ */
50
42
  var PngView = (0, _event_handler["default"])(_simple_png_view["default"]);
51
43
  var RtcView = (0, _event_handler["default"])(_webrtc_view["default"]);
44
+
52
45
  /**
53
46
  * A React component that displays a remote android emulator.
54
47
  *
@@ -85,15 +78,11 @@ var RtcView = (0, _event_handler["default"])(_webrtc_view["default"]);
85
78
  * "GoBack" - Open the previous screen you were looking at.
86
79
  *
87
80
  */
88
-
89
81
  var Emulator = /*#__PURE__*/function (_Component) {
90
82
  (0, _inherits2["default"])(Emulator, _Component);
91
-
92
83
  var _super = _createSuper(Emulator);
93
-
94
84
  function Emulator(props) {
95
85
  var _this;
96
-
97
86
  (0, _classCallCheck2["default"])(this, Emulator);
98
87
  _this = _super.call(this, props);
99
88
  (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "components", {
@@ -113,30 +102,40 @@ var Emulator = /*#__PURE__*/function (_Component) {
113
102
  });
114
103
  (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "updateLocation", function () {
115
104
  var gps = _this.props.gps;
116
-
117
105
  if (typeof gps === "undefined") {
118
106
  return;
119
107
  }
120
-
121
108
  var state = new Proto.GpsState();
122
109
  state.setLatitude(gps.latitude);
123
110
  state.setLongitude(gps.longitude);
124
111
  state.setAltitude(gps.altitude);
125
112
  state.setBearing(gps.heading);
126
113
  state.setSpeed(gps.speed);
127
-
128
114
  _this.emulator.setGps(state);
129
115
  });
116
+ /**
117
+ * Sends the given key to the emulator.
118
+ *
119
+ * You can use this to send physical hardware events to the emulator for example:
120
+ *
121
+ * "AudioVolumeDown" - Decreases the audio volume.
122
+ * "AudioVolumeUp" - Increases the audio volume.
123
+ * "Power" - The Power button or key, turn off the device.
124
+ * "AppSwitch" - Should bring up the application switcher dialog.
125
+ * "GoHome" - Go to the home screen.
126
+ * "GoBack" - Open the previous screen you were looking at.
127
+ *
128
+ * See https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values for
129
+ * a list of valid values you can send as well.
130
+ */
130
131
  (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "sendKey", function (key) {
131
132
  var request = new Proto.KeyboardEvent();
132
133
  request.setEventtype(Proto.KeyboardEvent.KeyEventType.KEYPRESS);
133
134
  request.setKey(key);
134
-
135
135
  _this.jsep.send("keyboard", request);
136
136
  });
137
137
  (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "_onAudioStateChange", function (s) {
138
138
  var onAudioStateChange = _this.props.onAudioStateChange;
139
-
140
139
  _this.setState({
141
140
  audio: s
142
141
  }, function () {
@@ -144,29 +143,29 @@ var Emulator = /*#__PURE__*/function (_Component) {
144
143
  });
145
144
  });
146
145
  var uri = props.uri,
147
- auth = props.auth,
148
- poll = props.poll,
149
- onError = props.onError;
146
+ auth = props.auth,
147
+ poll = props.poll,
148
+ onError = props.onError;
150
149
  _this.emulator = new _emulator_web_client.EmulatorControllerService(uri, auth, onError);
151
150
  _this.rtc = new _emulator_web_client.RtcService(uri, auth, onError);
152
151
  _this.jsep = new _jsep_protocol_driver["default"](_this.emulator, _this.rtc, poll);
153
152
  _this.view = /*#__PURE__*/_react["default"].createRef();
154
153
  return _this;
155
154
  }
156
-
157
155
  (0, _createClass2["default"])(Emulator, [{
158
156
  key: "render",
159
157
  value: function render() {
160
158
  var _this$props = this.props,
161
- width = _this$props.width,
162
- height = _this$props.height,
163
- view = _this$props.view,
164
- poll = _this$props.poll,
165
- muted = _this$props.muted,
166
- onStateChange = _this$props.onStateChange,
167
- onError = _this$props.onError,
168
- volume = _this$props.volume;
159
+ width = _this$props.width,
160
+ height = _this$props.height,
161
+ view = _this$props.view,
162
+ poll = _this$props.poll,
163
+ muted = _this$props.muted,
164
+ onStateChange = _this$props.onStateChange,
165
+ onError = _this$props.onError,
166
+ volume = _this$props.volume;
169
167
  var SpecificView = this.components[view] || RtcView;
168
+ console.log("render ".concat(width, "x").concat(height));
170
169
  return /*#__PURE__*/_react["default"].createElement(SpecificView, {
171
170
  ref: this.view,
172
171
  width: width,
@@ -192,41 +191,29 @@ var Emulator = /*#__PURE__*/function (_Component) {
192
191
  }]);
193
192
  return Emulator;
194
193
  }(_react.Component);
195
-
196
194
  (0, _defineProperty2["default"])(Emulator, "propTypes", {
197
195
  /** gRPC Endpoint where we can reach the emulator. */
198
196
  uri: _propTypes["default"].string.isRequired,
199
-
200
197
  /** The authentication service to use, or null for no authentication. */
201
198
  auth: _propTypes["default"].object,
202
-
203
199
  /** True if the audio should be disabled. This is only relevant when using the webrtc engine. */
204
200
  muted: _propTypes["default"].bool,
205
-
206
201
  /** Volume between [0, 1] when audio is enabled. 0 is muted, 1.0 is 100% */
207
202
  volume: _propTypes["default"].number,
208
-
209
203
  /** Called upon state change, one of ["connecting", "connected", "disconnected"] */
210
204
  onStateChange: _propTypes["default"].func,
211
-
212
205
  /** Called when the audio becomes (un)available. True if audio is available, false otherwise. */
213
206
  onAudioStateChange: _propTypes["default"].func,
214
-
215
207
  /** The width of the component */
216
208
  width: _propTypes["default"].number,
217
-
218
209
  /** The height of the component */
219
210
  height: _propTypes["default"].number,
220
-
221
211
  /** The underlying view used to display the emulator, one of ["webrtc", "png"] */
222
212
  view: _propTypes["default"].oneOf(["webrtc", "png"]).isRequired,
223
-
224
213
  /** A [GeolocationCoordinates](https://developer.mozilla.org/en-US/docs/Web/API/GeolocationCoordinates) like object indicating where the device is. */
225
214
  gps: _propTypes["default"].object,
226
-
227
215
  /** True if polling should be used, only set this to true if you are using the go webgrpc proxy. */
228
216
  poll: _propTypes["default"].bool,
229
-
230
217
  /** Callback that will be invoked in case of gRPC errors. */
231
218
  onError: _propTypes["default"].func
232
219
  });
@@ -1,20 +1,15 @@
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
  });
8
7
  exports["default"] = void 0;
9
-
8
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
10
9
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
11
-
12
10
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
13
-
14
11
  var _empty_pb = require("google-protobuf/google/protobuf/empty_pb");
15
-
16
12
  var _emulator_web_client = require("../../../proto/emulator_web_client");
17
-
18
13
  /*
19
14
  * Copyright 2020 The Android Open Source Project
20
15
  *
@@ -30,7 +25,6 @@ var _emulator_web_client = require("../../../proto/emulator_web_client");
30
25
  * See the License for the specific language governing permissions and
31
26
  * limitations under the License.
32
27
  */
33
-
34
28
  /**
35
29
  * Gets the status of the emulator, parsing the hardware config into something
36
30
  * easy to digest.
@@ -38,7 +32,7 @@ var _emulator_web_client = require("../../../proto/emulator_web_client");
38
32
  * @export
39
33
  * @class EmulatorStatus
40
34
  */
41
- var EmulatorStatus =
35
+ var EmulatorStatus = /*#__PURE__*/(0, _createClass2["default"])(
42
36
  /**
43
37
  * Creates an EmulatorStatus object that can retrieve the status of the running emulator.
44
38
  *
@@ -51,29 +45,36 @@ var EmulatorStatus =
51
45
  */
52
46
  function EmulatorStatus(uriOrEmulator, auth) {
53
47
  var _this = this;
54
-
55
48
  (0, _classCallCheck2["default"])(this, EmulatorStatus);
49
+ /**
50
+ * Gets the cached status.
51
+ *
52
+ * @memberof EmulatorStatus
53
+ */
56
54
  (0, _defineProperty2["default"])(this, "getStatus", function () {
57
55
  return _this.status;
58
56
  });
57
+ /**
58
+ * Retrieves the current status from the emulator.
59
+ *
60
+ * @param {Callback} fnNotify when the status is available, returns the retrieved status.
61
+ * @param {boolean} cache True if the cache can be used.
62
+ * @memberof EmulatorStatus
63
+ */
59
64
  (0, _defineProperty2["default"])(this, "updateStatus", function (fnNotify, cache) {
60
65
  var request = new _empty_pb.Empty();
61
-
62
66
  if (cache && _this.status) {
63
67
  fnNotify(_this.status);
64
68
  return _this.status;
65
69
  }
66
-
67
70
  _this.emulator.getStatus(request, {}, function (err, response) {
68
71
  var hwConfig = {};
69
72
  var entryList = response.getHardwareconfig().getEntryList();
70
-
71
73
  for (var i = 0; i < entryList.length; i++) {
72
74
  var key = entryList[i].getKey();
73
75
  var val = entryList[i].getValue();
74
76
  hwConfig[key] = val;
75
77
  }
76
-
77
78
  var vmConfig = response.getVmconfig();
78
79
  _this.status = {
79
80
  version: response.getVersion(),
@@ -89,21 +90,12 @@ function EmulatorStatus(uriOrEmulator, auth) {
89
90
  fnNotify(_this.status);
90
91
  });
91
92
  });
92
-
93
93
  if (uriOrEmulator instanceof _emulator_web_client.EmulatorControllerService) {
94
94
  this.emulator = uriOrEmulator;
95
95
  } else {
96
96
  this.emulator = new _emulator_web_client.EmulatorControllerService(uriOrEmulator, auth);
97
97
  }
98
-
99
98
  this.status = null;
100
- }
101
- /**
102
- * Gets the cached status.
103
- *
104
- * @memberof EmulatorStatus
105
- */
106
- ;
107
-
99
+ });
108
100
  var _default = EmulatorStatus;
109
101
  exports["default"] = _default;