android-emulator-webrtc 1.0.17 → 2.0.1

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 (72) hide show
  1. package/README.md +93 -204
  2. package/dist/components/emulator/emulator.d.ts +64 -0
  3. package/dist/components/emulator/emulator.js +161 -173
  4. package/dist/components/emulator/net/emulator_status.d.ts +45 -0
  5. package/dist/components/emulator/net/emulator_status.js +35 -42
  6. package/dist/components/emulator/net/logcat.js +37 -54
  7. package/dist/components/emulator/net/logger.d.ts +7 -0
  8. package/dist/components/emulator/net/logger.js +20 -0
  9. package/dist/components/emulator/net/ws_jsep_protocol_driver.d.ts +213 -0
  10. package/dist/components/emulator/net/ws_jsep_protocol_driver.js +640 -0
  11. package/dist/components/emulator/views/event_handler.d.ts +37 -0
  12. package/dist/components/emulator/views/event_handler.js +274 -260
  13. package/dist/components/emulator/views/webrtc_view.d.ts +27 -0
  14. package/dist/components/emulator/views/webrtc_view.js +42 -25
  15. package/dist/index.d.ts +8 -0
  16. package/dist/index.js +0 -7
  17. package/dist/proto/emulator_controller_pb.d.ts +1 -0
  18. package/dist/proto/emulator_controller_pb.js +146 -287
  19. package/dist/src/components/emulator/emulator.d.ts +64 -0
  20. package/dist/src/components/emulator/net/emulator_status.d.ts +45 -0
  21. package/dist/src/components/emulator/net/logger.d.ts +7 -0
  22. package/dist/src/components/emulator/net/ws_jsep_protocol_driver.d.ts +213 -0
  23. package/dist/src/components/emulator/views/event_handler.d.ts +37 -0
  24. package/dist/src/components/emulator/views/webrtc_view.d.ts +27 -0
  25. package/dist/src/index.d.ts +8 -0
  26. package/dist/src/proto/emulator_controller_pb.d.ts +1 -0
  27. package/package.json +17 -18
  28. package/proto/emulator_controller.proto +746 -181
  29. package/.vscode/launch.json +0 -21
  30. package/.vscode/settings.json +0 -3
  31. package/CONTRIBUTING.md +0 -28
  32. package/Makefile +0 -123
  33. package/android-emulator-webrtc.code-workspace +0 -7
  34. package/api_descriptor.pb +0 -0
  35. package/babel.config.js +0 -16
  36. package/cloudbuild.yaml +0 -41
  37. package/cloudbuilders/.gcloudignore +0 -1
  38. package/cloudbuilders/Dockerfile +0 -20
  39. package/cloudbuilders/README.md +0 -29
  40. package/cloudbuilders/cloudbuild.yaml +0 -19
  41. package/dist/components/emulator/net/jsep_protocol_driver.js +0 -365
  42. package/dist/components/emulator/views/resizing_component.js +0 -86
  43. package/dist/components/emulator/views/simple_png_view.js +0 -111
  44. package/dist/proto/emulator_controller_grpc_web_pb.js +0 -1601
  45. package/dist/proto/emulator_web_client.js +0 -176
  46. package/dist/proto/rtc_service_grpc_web_pb.js +0 -231
  47. package/dist/proto/rtc_service_pb.js +0 -338
  48. package/emulator/index.js +0 -1
  49. package/eslint_prefix.py +0 -37
  50. package/gen_md_doc.js +0 -40
  51. package/npmrc.enc +0 -0
  52. package/proto/rtc_service.proto +0 -117
  53. package/protoc-plugin/Makefile +0 -31
  54. package/protoc-plugin/grpc_generator.cc +0 -1755
  55. package/src/components/emulator/emulator.js +0 -217
  56. package/src/components/emulator/net/emulator_status.js +0 -94
  57. package/src/components/emulator/net/jsep_protocol_driver.js +0 -364
  58. package/src/components/emulator/net/logcat.js +0 -155
  59. package/src/components/emulator/views/event_handler.js +0 -268
  60. package/src/components/emulator/views/resizing_component.js +0 -65
  61. package/src/components/emulator/views/simple_png_view.js +0 -106
  62. package/src/components/emulator/views/webrtc_view.js +0 -146
  63. package/src/index.js +0 -20
  64. package/src/proto/emulator_web_client.js +0 -140
  65. package/test/cloudbuild.yaml +0 -41
  66. package/test/emulator.test.js +0 -125
  67. package/test/event_handler.test.js +0 -91
  68. package/test/fake_events.js +0 -50
  69. package/test/jsep_protocol_driver.test.js +0 -228
  70. package/test/resizing_component.test.js +0 -37
  71. package/test/simple_png_view.test.js +0 -145
  72. package/test/touch_event_handler.test.js +0 -118
@@ -1,21 +0,0 @@
1
- {
2
- // Use IntelliSense to learn about possible attributes.
3
- // Hover to view descriptions of existing attributes.
4
- // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5
- "version": "0.2.0",
6
- "configurations": [
7
- {
8
- "type": "node",
9
- "name": "vscode-jest-tests",
10
- "request": "launch",
11
- "args": [
12
- "--runInBand"
13
- ],
14
- "cwd": "${workspaceFolder}",
15
- "console": "integratedTerminal",
16
- "internalConsoleOptions": "neverOpen",
17
- "disableOptimisticBPs": true,
18
- "program": "${workspaceFolder}/node_modules/jest/bin/jest"
19
- }
20
- ]
21
- }
@@ -1,3 +0,0 @@
1
- {
2
- "C_Cpp.default.configurationProvider": "ms-vscode.makefile-tools"
3
- }
package/CONTRIBUTING.md DELETED
@@ -1,28 +0,0 @@
1
- # How to Contribute
2
-
3
- We'd love to accept your patches and contributions to this project. There are
4
- just a few small guidelines you need to follow.
5
-
6
- ## Contributor License Agreement
7
-
8
- Contributions to this project must be accompanied by a Contributor License
9
- Agreement. You (or your employer) retain the copyright to your contribution;
10
- this simply gives us permission to use and redistribute your contributions as
11
- part of the project. Head over to <https://cla.developers.google.com/> to see
12
- your current agreements on file or to sign a new one.
13
-
14
- You generally only need to submit a CLA once, so if you've already submitted one
15
- (even if it was for a different project), you probably don't need to do it
16
- again.
17
-
18
- ## Code reviews
19
-
20
- All submissions, including submissions by project members, require review. We
21
- use GitHub pull requests for this purpose. Consult
22
- [GitHub Help](https://help.github.com/articles/about-pull-requests/) for more
23
- information on using pull requests.
24
-
25
- ## Community Guidelines
26
-
27
- This project follows
28
- [Google's Open Source Community Guidelines](https://opensource.google.com/conduct/).
package/Makefile DELETED
@@ -1,123 +0,0 @@
1
- # Copyright (C) 2019 The Android Open Source Project
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
- #
15
- PROTOC = protoc
16
- PROTOC_CMD = which $(PROTOC)
17
- PYTHON = python
18
-
19
- # Check that the minimum protocol version >3.6
20
- PROTOHEADER = $(shell pkg-config --variable prefix protobuf)/include
21
- PROTOLIB = $(shell pkg-config --variable prefix protobuf)/lib
22
-
23
- HAS_PROTOC = $(shell $(PROTOC_CMD) > /dev/null && echo true || echo false)
24
- HAS_DEP = $(shell which $(DEP) > /dev/null && echo true || echo false)
25
-
26
- # Prefixing works differently on mac vs linux, so let us account for that.
27
-
28
- UNAME_S := $(shell uname -s)
29
- PREFIX_ESLINT = $(PYTHON) eslint_prefix.py
30
-
31
- ifeq ($(HAS_PROTOC),true)
32
- ifneq (,$(wildcard $(PROTOHEADER)/google/protobuf/compiler/code_generator.h))
33
- HAS_VALID_PROTOC := true
34
- else
35
- HAS_VALID_PROTOC := false
36
- endif
37
- endif
38
-
39
- SYSTEM_OK = false
40
- ifeq ($(HAS_VALID_PROTOC),true)
41
- SYSTEM_OK = true
42
- endif
43
-
44
- MAKEFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
45
- CURRENT_DIR := $(abspath $(MAKEFILE_PATH)/..)
46
- # Protobuf settings. If you are running this in the AOSP tree you will want to run ninja install first.
47
- PROTODIR := $(CURRENT_DIR)/src/proto/
48
- PROTOSRCDIR := $(CURRENT_DIR)/proto
49
- PROTO_SRC := $(wildcard $(PROTOSRCDIR)/*.proto)
50
- PROTO_OBJS := $(addprefix $(PROTODIR)/, $(notdir $(PROTO_SRC:.proto=_pb.js)))
51
- PROXY_OBJS := $(addprefix $(PROTODIR)/, $(notdir $(PROTO_SRC:.proto=_grpc_web_pb.js)))
52
-
53
-
54
- CXX = g++
55
- CPPFLAGS += -I$(PROTOHEADER) -pthread
56
- CXXFLAGS += -std=c++11
57
- LDFLAGS += -L$(PROTOLIB) -lprotoc -lprotobuf -lpthread -ldl
58
-
59
- .PHONY: build-release run-release develop stop
60
-
61
- all: check
62
-
63
- clean:
64
- rm -rf $(PROTODIR)/*pb.js
65
-
66
- $(PROTODIR):
67
- @mkdir -p $(PROTODIR)
68
-
69
- # Protobuf --> js (note technically this produces 2 files.) which is not
70
- # the way you are supposed to do things in gnumake
71
- # https://www.gnu.org/software/automake/manual/html_node/Multiple-Outputs.html
72
- # Use sed to insert the /* eslint-disable */ at the start of the file
73
- # \`$$`\n` forces a real newline char, because make.
74
- $(PROTODIR)/%_pb.js : $(PROTOSRCDIR)/%.proto $(PROTODIR) protoc-gen-grpc-web
75
- $(PROTOC) \
76
- -I/usr/local/include -I$(PROTODIR) -I$(PROTOSRCDIR) \
77
- --plugin=protoc-gen-grpc-web=$(CURRENT_DIR)/protoc-gen-grpc-web \
78
- --js_out=import_style=commonjs,binary:$(PROTODIR) \
79
- --grpc-web_out=import_style=commonjs,mode=grpcwebtext:$(PROTODIR) \
80
- $<
81
- $(PREFIX_ESLINT) $@
82
-
83
- # Fix up the proxies _grpc_web files by prefixing /* eslint-disable */
84
- # Not evey source produces a _grpc_web, so we onle do the replace if them file exists, otherwise it is a nop.
85
- $(PROTODIR)/%_grpc_web_pb.js : $(PROTODIR)/%_pb.js
86
- @test -f $@ && $(PREFIX_ESLINT) $@ || true
87
-
88
- protoc: $(PROTO_OBJS) $(PROXY_OBJS)
89
-
90
- protoc-gen-grpc-web: protoc-plugin/grpc_generator.o
91
- $(CXX) $^ $(LDFLAGS) -o $@
92
-
93
- deps: system-check protoc
94
- @npm install
95
-
96
- build: deps
97
- @npm run build
98
-
99
- check: build
100
- @npm run test
101
-
102
- system-check:
103
- ifneq ($(HAS_VALID_PROTOC),true)
104
- @echo " DEPENDENCY ERROR"
105
- @echo
106
- @echo "You don't have protoc 3.6.0 > installed in your path."
107
- @echo "Please install Google protocol buffers 3.6.0> and its compiler."
108
- @echo "You can find it here:"
109
- @echo
110
- @echo " https://github.com/google/protobuf/releases/tag/v3.6.0"
111
- @echo " or try $ brew install protobuf"
112
- @echo " or sudo apt-get install libprotoc-dev protobuf-compiler"
113
- @echo
114
- @echo "Here is what I get when trying to evaluate your version of protoc:"
115
- @echo
116
- -$(PROTOC) --version
117
- @echo
118
- @echo "And here is where I am looking for the headers: $(PROTOHEADER)/google/protobuf"
119
- @echo
120
- endif
121
- ifneq ($(SYSTEM_OK),true)
122
- @false
123
- endif
@@ -1,7 +0,0 @@
1
- {
2
- "folders": [
3
- {
4
- "path": "."
5
- }
6
- ]
7
- }
package/api_descriptor.pb DELETED
Binary file
package/babel.config.js DELETED
@@ -1,16 +0,0 @@
1
- "use strict";
2
-
3
- module.exports = {
4
- presets: [
5
- [
6
- "@babel/preset-env",
7
- {
8
- targets: {
9
- node: "current",
10
- },
11
- },
12
- ],
13
- "@babel/preset-react",
14
- ],
15
- plugins: [["@babel/transform-runtime"]],
16
- };
package/cloudbuild.yaml DELETED
@@ -1,41 +0,0 @@
1
- steps:
2
- - name: "gcr.io/cloud-builders/gcloud"
3
- args:
4
- - kms
5
- - decrypt
6
- - --ciphertext-file=npmrc.enc
7
- - --plaintext-file=/root/.npmrc
8
- - --location=global
9
- - --keyring=my-keyring
10
- - --key=npm-key
11
- volumes:
12
- - name: "home"
13
- path: /root/
14
- - name: gcr.io/emu-dev-cts/protoc
15
- args:
16
- [
17
- "--include_imports",
18
- "--include_source_info",
19
- "--proto_path",
20
- "./proto",
21
- "--descriptor_set_out",
22
- "api_descriptor.pb",
23
- "--plugin=protoc-gen-grpc-web=/protoc/bin/protoc-gen-grpc-web",
24
- "--js_out=import_style=commonjs:src/proto",
25
- "--grpc-web_out=import_style=commonjs,mode=grpcwebtext:src/proto",
26
- "./proto/emulator_controller.proto",
27
- "./proto/rtc_service.proto",
28
- ]
29
- - name: "gcr.io/cloud-builders/npm"
30
- args: ["install"]
31
- - name: "gcr.io/cloud-builders/npm"
32
- args: ["run", "build"]
33
- - name: "gcr.io/cloud-builders/npm"
34
- args: ["test"]
35
- - name: "gcr.io/cloud-builders/npm"
36
- args: ["publish"]
37
- env:
38
- - HOME=/root/
39
- volumes:
40
- - name: "home"
41
- path: /root/
@@ -1 +0,0 @@
1
- # Empty
@@ -1,20 +0,0 @@
1
- FROM debian:buster-slim
2
-
3
- ARG VERS=3.12.4
4
- ARG ARCH=linux-x86_64
5
- ARG GRPC_WEB=1.2.1
6
-
7
- RUN echo "Building protoc Cloud Builder ${VERS}-${ARCH}" && \
8
- apt-get update -y && apt-get upgrade -y && \
9
- apt-get install wget unzip -y && \
10
- apt-get clean -y && \
11
- rm -rf /var/lib/apt/lists/* && \
12
- wget "https://github.com/protocolbuffers/protobuf/releases/download/v${VERS}/protoc-${VERS}-${ARCH}.zip" && \
13
- unzip "protoc-${VERS}-${ARCH}.zip" -d protoc && \
14
- wget "https://github.com/grpc/grpc-web/releases/download/${GRPC_WEB}/protoc-gen-grpc-web-${GRPC_WEB}-${ARCH}" -O /protoc/bin/protoc-gen-grpc-web && \
15
- chmod a+x /protoc/bin/protoc-gen-grpc-web && \
16
- rm "protoc-${VERS}-${ARCH}.zip"
17
-
18
- ENV PATH=$PATH:/protoc/bin/
19
- ENTRYPOINT ["protoc"]
20
- CMD ["--help"]
@@ -1,29 +0,0 @@
1
- # protoc with grpc-web
2
-
3
- This tool defines a custom build step that allows the Cloud Build worker to run the
4
- [protocol buffer compiler](https://github.com/protocolbuffers/protobuf), `protoc`.
5
- with the protoc-gen-grpc-web plugin. You will need this builder to successfully compile
6
- the distribution in the cloud.
7
-
8
- ## Building this builder
9
-
10
- You will need to build this Builder and push it to a container registry before you may use it.
11
- To build and push to Google Container Registry, run the following command in this directory:
12
-
13
- ```bash
14
- gcloud builds submit . --config=cloudbuild.yaml
15
- ```
16
-
17
- If you wish to specify a different version or architecture for the build, run the following:
18
-
19
- ```bash
20
- gcloud builds submit . --config=cloudbuild.yaml --substitutions=_VERS=${VERS},_ARCH=${ARCH}
21
- ```
22
-
23
- Where `${VERS}` and `${ARCH}` are defined to contain values for the release and architecture as listed on:
24
-
25
- https://github.com/protocolbuffers/protobuf/releases
26
-
27
- **NB** Due to inconsistent handling of URLs for release candidates, the build will fail when
28
- referencing these ([issue](https://github.com/protocolbuffers/protobuf/issues/6522)).
29
-
@@ -1,19 +0,0 @@
1
- substitutions:
2
- _VERS: "3.12.4"
3
- _ARCH: linux-x86_64
4
-
5
- steps:
6
- - name: 'gcr.io/cloud-builders/docker'
7
- args:
8
- - build
9
- - "--build-arg=VERS=${_VERS}"
10
- - "--build-arg=ARCH=${_ARCH}"
11
- - --tag=gcr.io/${PROJECT_ID}/protoc:${_VERS}-${_ARCH}
12
- - --tag=gcr.io/${PROJECT_ID}/protoc:latest
13
- - "."
14
-
15
- images:
16
- - "gcr.io/${PROJECT_ID}/protoc:${_VERS}-${_ARCH}"
17
- - "gcr.io/${PROJECT_ID}/protoc:latest"
18
-
19
- tags: ['cloud-builders-community']
@@ -1,365 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports["default"] = void 0;
8
- var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
9
- var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
10
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
11
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
12
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
13
- var _events = require("events");
14
- var _empty_pb = require("google-protobuf/google/protobuf/empty_pb");
15
- /*
16
- * Copyright 2019 The Android Open Source Project
17
- *
18
- * Licensed under the Apache License, Version 2.0 (the "License")
19
- * you may not use this file except in compliance with the License.
20
- * You may obtain a copy of the License at
21
- *
22
- * http://www.apache.org/licenses/LICENSE-2.0
23
- *
24
- * Unless required by applicable law or agreed to in writing, software
25
- * distributed under the License is distributed on an "AS IS" BASIS,
26
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
27
- * See the License for the specific language governing permissions and
28
- * limitations under the License.
29
- */
30
- /**
31
- * This drives the jsep protocol with the emulator, and can be used to
32
- * send key/mouse/touch events to the emulator. Events will be send
33
- * over the data channel if open, otherwise they will be send via the
34
- * grpc endpoint.
35
- *
36
- * The jsep protocol is described here:
37
- * https://rtcweb-wg.github.io/jsep/.
38
- *
39
- * This class can fire two events:
40
- *
41
- * - `connected` when the stream has become available.
42
- * - `disconnected` when the stream broke down, or when we failed to establish a connection
43
- *
44
- * You usually want to start the stream after instantiating this object. Do not forget to
45
- * disconnect once you are finished to terminate the message pump.
46
- *
47
- *
48
- * @example
49
- * jsep = new JsepProtocolDriver(emulator, s => { video.srcObject = s; video.play() });
50
- * jsep.startStream();
51
- *
52
- * @export
53
- * @class JsepProtocol
54
- */
55
- var JsepProtocol = /*#__PURE__*/function () {
56
- /**
57
- * Creates an instance of JsepProtocol.
58
- * @param {EmulatorService} emulator Service used to make the gRPC calls
59
- * @param {RtcService} rtc Service used to open up the rtc calls.
60
- * @param {boolean} poll True if we should use polling
61
- * @param {callback} onConnect optional callback that is invoked when a stream is available
62
- * @param {callback} onDisconnect optional callback that is invoked when the stream is closed.
63
- * @memberof JsepProtocol
64
- */
65
- function JsepProtocol(emulator, rtc, poll, onConnect, onDisconnect) {
66
- var _this = this;
67
- (0, _classCallCheck2["default"])(this, JsepProtocol);
68
- (0, _defineProperty2["default"])(this, "on", function (name, fn) {
69
- _this.events.on(name, fn);
70
- });
71
- /**
72
- * Disconnects the stream. This will stop the message pump as well.
73
- *
74
- * @memberof JsepProtocol
75
- */
76
- (0, _defineProperty2["default"])(this, "disconnect", function () {
77
- _this.connected = false;
78
- if (_this.peerConnection) _this.peerConnection.close();
79
- if (_this.stream) {
80
- _this.stream.cancel();
81
- _this.stream = null;
82
- }
83
- _this.active = false;
84
- _this.old_emu_patch = {
85
- candidates: [],
86
- sdp: null,
87
- haveOffer: false,
88
- answer: false
89
- };
90
- _this.events.emit("disconnected", _this);
91
- });
92
- /**
93
- * Initiates the JSEP protocol.
94
- *
95
- * @memberof JsepProtocol
96
- */
97
- (0, _defineProperty2["default"])(this, "startStream", function () {
98
- var self = _this;
99
- _this.connected = false;
100
- _this.peerConnection = null;
101
- _this.active = true;
102
- _this.old_emu_patch = {
103
- candidates: [],
104
- sdp: null,
105
- haveOffer: false,
106
- answer: false
107
- };
108
- var request = new _empty_pb.Empty();
109
- _this.rtc.requestRtcStream(request, {}, function (err, response) {
110
- if (err) {
111
- console.error("Failed to configure rtc stream: " + JSON.stringify(err));
112
- _this.disconnect();
113
- return;
114
- }
115
-
116
- // Configure
117
- self.guid = response;
118
- self.connected = true;
119
- if (!_this.poll) {
120
- // Streaming envoy based.
121
- self._streamJsepMessage();
122
- } else {
123
- // Poll pump messages, go/envoy based proxy.
124
- console.debug("Polling jsep messages.");
125
- self._receiveJsepMessage();
126
- }
127
- });
128
- });
129
- (0, _defineProperty2["default"])(this, "cleanup", function () {
130
- _this.disconnect();
131
- if (_this.peerConnection) {
132
- _this.peerConnection.removeEventListener("track", _this._handlePeerConnectionTrack);
133
- _this.peerConnection.removeEventListener("icecandidate", _this._handlePeerIceCandidate);
134
- _this.peerConnection = null;
135
- }
136
- _this.event_forwarders = {};
137
- });
138
- (0, _defineProperty2["default"])(this, "_handlePeerConnectionTrack", function (e) {
139
- _this.events.emit("connected", e.track);
140
- });
141
- (0, _defineProperty2["default"])(this, "_handlePeerConnectionStateChange", function (e) {
142
- switch (_this.peerConnection.connectionState) {
143
- case "disconnected":
144
- // At least one of the ICE transports for the connection is in the "disconnected" state
145
- // and none of the other transports are in the state "failed", "connecting",
146
- // or "checking".
147
- case "failed":
148
- // One or more of the ICE transports on the connection is in the "failed" state.
149
- case "closed":
150
- //The RTCPeerConnection is closed.
151
- _this.disconnect();
152
- }
153
- });
154
- (0, _defineProperty2["default"])(this, "_handlePeerIceCandidate", function (e) {
155
- if (e.candidate === null) return;
156
- _this._sendJsep({
157
- candidate: e.candidate
158
- });
159
- });
160
- (0, _defineProperty2["default"])(this, "_handleDataChannel", function (e) {
161
- var channel = e.channel;
162
- _this.event_forwarders[channel.label] = channel;
163
- });
164
- (0, _defineProperty2["default"])(this, "_handleStart", function (signal) {
165
- _this.peerConnection = new RTCPeerConnection(signal.start);
166
- _this.peerConnection.ontrack = _this._handlePeerConnectionTrack;
167
- _this.peerConnection.onicecandidate = _this._handlePeerIceCandidate;
168
- _this.peerConnection.onconnectionstatechange = _this._handlePeerConnectionStateChange;
169
- _this.peerConnection.ondatachannel = _this._handleDataChannel;
170
- _this.peerConnection.onsignalingstatechange = _this._handlePeerState;
171
- });
172
- (0, _defineProperty2["default"])(this, "_handlePeerState", function (event) {
173
- if (!_this.peerConnection) {
174
- console.log("Peerconnection no longer available, ignoring signal state.");
175
- }
176
- switch (_this.peerConnection.signalingState) {
177
- case "have-remote-offer":
178
- _this.old_emu_patch.haveOffer = true;
179
- while (_this.old_emu_patch.candidates.length > 0) {
180
- _this._handleCandidate(_this.old_emu_patch.candidates.shift());
181
- }
182
- break;
183
- }
184
- });
185
- (0, _defineProperty2["default"])(this, "_handleSDP", /*#__PURE__*/function () {
186
- var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(signal) {
187
- var answer;
188
- return _regenerator["default"].wrap(function _callee$(_context) {
189
- while (1) switch (_context.prev = _context.next) {
190
- case 0:
191
- // We should not call this more than once..
192
- _this.old_emu_patch.sdp = null;
193
- _this.peerConnection.setRemoteDescription(new RTCSessionDescription(signal));
194
- _context.next = 4;
195
- return _this.peerConnection.createAnswer();
196
- case 4:
197
- answer = _context.sent;
198
- if (answer) {
199
- // Older emulators cannot handle multiple answers, so make sure we do not send one
200
- // again.
201
- if (!_this.old_emu_patch.answer) {
202
- _this.old_emu_patch.answer = true;
203
- _this.peerConnection.setLocalDescription(answer);
204
- _this._sendJsep({
205
- sdp: answer
206
- });
207
- }
208
- } else {
209
- _this.disconnect();
210
- }
211
- case 6:
212
- case "end":
213
- return _context.stop();
214
- }
215
- }, _callee);
216
- }));
217
- return function (_x) {
218
- return _ref.apply(this, arguments);
219
- };
220
- }());
221
- (0, _defineProperty2["default"])(this, "_handleCandidate", function (signal) {
222
- _this.peerConnection.addIceCandidate(new RTCIceCandidate(signal));
223
- });
224
- (0, _defineProperty2["default"])(this, "_handleSignal", function (signal) {
225
- if (signal.start) {
226
- _this._handleStart(signal);
227
- }
228
- if (signal.bye) {
229
- _this._handleBye();
230
- }
231
- if (signal.sdp && !_this.old_emu_patch.sdp) {
232
- _this.old_emu_patch.sdp = signal;
233
- }
234
- if (signal.candidate) {
235
- _this.old_emu_patch.candidates.push(signal);
236
- }
237
- if (!!_this.peerConnection) {
238
- // We have created a peer connection..
239
- if (_this.old_emu_patch.sdp) {
240
- _this._handleSDP(_this.old_emu_patch.sdp);
241
- }
242
- if (_this.old_emu_patch.haveOffer) {
243
- // We have a remote peer, add the candidates in.
244
- while (_this.old_emu_patch.candidates.length > 0) {
245
- _this._handleCandidate(_this.old_emu_patch.candidates.shift());
246
- }
247
- }
248
- }
249
- });
250
- (0, _defineProperty2["default"])(this, "_handleJsepMessage", function (message) {
251
- try {
252
- var signal = JSON.parse(message);
253
- _this._handleSignal(signal);
254
- } catch (e) {
255
- console.error("Failed to handle message: [" + message + "], due to: " + JSON.stringify(e));
256
- }
257
- });
258
- (0, _defineProperty2["default"])(this, "_handleBye", function () {
259
- if (_this.connected) {
260
- _this.disconnect();
261
- }
262
- });
263
- (0, _defineProperty2["default"])(this, "_sendJsep", function (jsonObject) {
264
- /* eslint-disable */
265
- var request = new proto.android.emulation.control.JsepMsg();
266
- request.setId(_this.guid);
267
- request.setMessage(JSON.stringify(jsonObject));
268
- _this.rtc.sendJsepMessage(request);
269
- });
270
- (0, _defineProperty2["default"])(this, "_streamJsepMessage", function () {
271
- if (!_this.connected) return;
272
- var self = _this;
273
- _this.stream = _this.rtc.receiveJsepMessages(_this.guid, {});
274
- _this.stream.on("data", function (response) {
275
- var msg = response.getMessage();
276
- self._handleJsepMessage(msg);
277
- });
278
- _this.stream.on("error", function (e) {
279
- console.log("Jsep message stream error:", e);
280
- if (self.connected) {
281
- console.log("Attempting to reconnect to jsep message stream.");
282
- self._streamJsepMessage();
283
- }
284
- });
285
- _this.stream.on("end", function (e) {
286
- if (self.connected) {
287
- console.log("Stream end while still connected.. Reconnecting");
288
- self._streamJsepMessage();
289
- }
290
- });
291
- });
292
- // This function is a fallback for v1 (go based proxy), that does not support streaming.
293
- (0, _defineProperty2["default"])(this, "_receiveJsepMessage", function () {
294
- if (!_this.connected) return;
295
- var self = _this;
296
-
297
- // This is a blocking call, that will return as soon as a series
298
- // of messages have been made available, or if we reach a timeout
299
- _this.rtc.receiveJsepMessage(_this.guid, {}, function (err, response) {
300
- if (err) {
301
- console.error("Failed to receive jsep message, disconnecting: " + JSON.stringify(err));
302
- _this.disconnect();
303
- }
304
- var msg = response.getMessage();
305
- // Handle only if we received a useful message.
306
- // it is possible to get nothing if the server decides
307
- // to kick us out.
308
- if (msg) {
309
- self._handleJsepMessage(response.getMessage());
310
- }
311
-
312
- // And pump messages. Note we must continue the message pump as we
313
- // can receive new ICE candidates at any point in time.
314
- if (self.active) {
315
- self._receiveJsepMessage();
316
- }
317
- });
318
- });
319
- this.emulator = emulator;
320
- this.rtc = rtc;
321
- this.events = new _events.EventEmitter();
322
-
323
- // Workaround for older emulators that send messages out of order
324
- // and do not handle all answers properly.
325
- this.old_emu_patch = {
326
- candidates: [],
327
- sdp: null,
328
- haveOffer: false,
329
- answer: false
330
- };
331
- this.poll = poll;
332
- this.guid = null;
333
- this.stream = null;
334
- this.event_forwarders = {};
335
- if (onConnect) this.events.on("connected", onConnect);
336
- if (onDisconnect) this.events.on("disconnected", onDisconnect);
337
- }
338
- (0, _createClass2["default"])(JsepProtocol, [{
339
- key: "send",
340
- value: function send(label, msg) {
341
- var bytes = msg.serializeBinary();
342
- var forwarder = this.event_forwarders[label];
343
- console.log("Send " + label + " " + JSON.stringify(msg.toObject()));
344
- // Send via data channel/gRPC bridge.
345
- if (this.connected && forwarder && forwarder.readyState == "open") {
346
- this.event_forwarders[label].send(bytes);
347
- } else {
348
- // Fallback to using the gRPC protocol
349
- switch (label) {
350
- case "mouse":
351
- this.emulator.sendMouse(msg);
352
- break;
353
- case "keyboard":
354
- this.emulator.sendKey(msg);
355
- break;
356
- case "touch":
357
- this.emulator.sendTouch(msg);
358
- break;
359
- }
360
- }
361
- }
362
- }]);
363
- return JsepProtocol;
364
- }();
365
- exports["default"] = JsepProtocol;