android-emulator-webrtc 1.0.18 → 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 (69) 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 -20
  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 -17
  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/simple_png_view.js +0 -110
  43. package/dist/proto/emulator_controller_grpc_web_pb.js +0 -1601
  44. package/dist/proto/emulator_web_client.js +0 -176
  45. package/dist/proto/rtc_service_grpc_web_pb.js +0 -231
  46. package/dist/proto/rtc_service_pb.js +0 -338
  47. package/emulator/index.js +0 -1
  48. package/eslint_prefix.py +0 -37
  49. package/gen_md_doc.js +0 -40
  50. package/npmrc.enc +0 -0
  51. package/proto/rtc_service.proto +0 -117
  52. package/protoc-plugin/Makefile +0 -31
  53. package/protoc-plugin/grpc_generator.cc +0 -1755
  54. package/src/components/emulator/emulator.js +0 -217
  55. package/src/components/emulator/net/emulator_status.js +0 -94
  56. package/src/components/emulator/net/jsep_protocol_driver.js +0 -364
  57. package/src/components/emulator/net/logcat.js +0 -155
  58. package/src/components/emulator/views/event_handler.js +0 -268
  59. package/src/components/emulator/views/simple_png_view.js +0 -105
  60. package/src/components/emulator/views/webrtc_view.js +0 -142
  61. package/src/index.js +0 -20
  62. package/src/proto/emulator_web_client.js +0 -140
  63. package/test/cloudbuild.yaml +0 -41
  64. package/test/emulator.test.js +0 -125
  65. package/test/event_handler.test.js +0 -91
  66. package/test/fake_events.js +0 -50
  67. package/test/jsep_protocol_driver.test.js +0 -228
  68. package/test/simple_png_view.test.js +0 -145
  69. package/test/touch_event_handler.test.js +0 -118
@@ -1,145 +0,0 @@
1
- /**
2
- * @jest-environment jsdom
3
- */
4
- /*
5
- * Copyright 2021 The Android Open Source Project
6
- *
7
- * Licensed under the Apache License, Version 2.0 (the "License")
8
- * you may not use this file except in compliance with the License.
9
- * You may obtain a copy of the License at
10
- *
11
- * http://www.apache.org/licenses/LICENSE-2.0
12
- *
13
- * Unless required by applicable law or agreed to in writing, software
14
- * distributed under the License is distributed on an "AS IS" BASIS,
15
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
- * See the License for the specific language governing permissions and
17
- * limitations under the License.
18
- */
19
- import { jest } from "@jest/globals";
20
- import "regenerator-runtime/runtime"; // Somehow needed for jest to be happy with ES6
21
-
22
- import * as Proto from "../src/proto/emulator_controller_pb";
23
- import React from "react";
24
- import EmulatorPngView from "../src/components/emulator/views/simple_png_view";
25
- import { resize } from "./fake_events";
26
- import {
27
- act,
28
- fireEvent,
29
- getByTestId,
30
- render,
31
- screen,
32
- waitFor,
33
- } from "@testing-library/react";
34
- import { EmulatorControllerService } from "../src/proto/emulator_web_client";
35
- import { EventEmitter } from "events";
36
- import { flushSync } from "react-dom";
37
-
38
- jest.mock("../src/proto/emulator_web_client");
39
-
40
- const googleLogo =
41
- "iVBORw0KGgoAAAANSUhEUgAAAJwAAACcCAYAAACKuMJNAAAQG0lEQVR42uydfWydVR3HD/Tert2YvOiGwQHTAAMyB905py/Lwu3znNsyZEiGqxGViUowwOJLMiIakym9ZQP+IAgxAUEmCGunZLjJ5npbmxBCpm4zghhfcEOg63Oe51K63tv1bfb4/MpissfLVtZ7n+e55/y+yTdpuv7R5Xx6zvm9nN8lKEJUW1uVZ7ElUvBVrs1vc222UQr2U0fwXb73+/6btPi//X9zXcHzjkWPORb/j2vxMUfQYdeiOf/7b/rfO+DatMexaZcU/CFX0O/INLvJFayufzWdS1Dm6a3GxlpP0GYfqm/7kPzMEWyfD8ZR/2tVTvvQTvlgHpQW2+nDnPFsdsPhVVcvICi99I9Vl8xx0ywlBf+hD9dL0uLjAEBsbPF/+QA+4drsC/0p+jGCqjwNpunZ0mK3+JD9upS7Vxi7oLT4H2Sa3+OmGy4lqPjKW7FivhT16+DICuxilWuLvyoFu1um+McJKh6SVv1V0uaPwWXet9LR00GKzX4D9z61kZxJUGFHlVd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08j+xBaaydAFtr6VmN7CYoZOZPG/e6WZNjjQ9gMQ2pcH+MbuRRSJlia45KmdMZGkKFG8WoEzd7IYWg8qftPM4Wboju8r1IOVev5EGTykPmWESlba0qcImDZ90otYPNX3MjLD6PV4s7WYXQXLouk5im4EUJDMzHOqI7rhjSwoioVXMP8sJoreuduPoEHvJ7OLQe+4K9VN8gN4KJnErMN3Spiqr8UGZXixxEj0VaIlkEuGBphRyKvaZXTQxdqEFaaeYiXw2k4iuvu5GJfFvphdRRHQ1Y3eQM5D1qDxR3a9g4qUUVctEDaK8ZzYBsTukx2jLOGV2gYE30oTrqIPfwiQSW+BprXG/QE/0V2Y9o9HXpbZq5REmkVxgG6Fg5jLNnI60JJrOiVNopb+HSaQWMAImESGATOL7K42EdpQeqHcxN45JiAnkCTEIGwdpDI8xWqAW4SDibHk2M6ijgeAnppyTMb/A6ieawHDdOrIBJLKRmWtc3ZhE+gB9FhAgGfhV4nKUSRGvJOtGRBLV9+jdpa9v0PcDnt5UdB+TMN3FVW0wcsuqugbTmISJWA1pO/6YRPL5jelQh3A5CsUBz8I5wexgBFmxWuJiEvr98wjV0M8O0la+G6O6UHpFZ6+38f/oXDkI1zSZvkqD8C+ip2n51/dBhAAAAABJRU5ErkJggg==";
42
- const googleImage = new Proto.Image();
43
- googleImage.setImage(Uint8Array.from(atob(googleLogo), (c) => c.charCodeAt(0)));
44
-
45
- const stream = new EventEmitter();
46
- describe("A simple png view", () => {
47
- EmulatorControllerService.mockImplementation(() => {
48
- let count = 0;
49
- return {
50
- getScreenshot: jest.fn((a, b, response) => {
51
- count++;
52
- if (count < 2) response(null, googleImage);
53
- }),
54
- streamScreenshot: jest.fn((request) => {
55
- stream.removeAllListeners();
56
- return {
57
- on: (name, fn) => {
58
- stream.on(name, fn);
59
- },
60
- cancel: jest.fn(),
61
- };
62
- }),
63
- getStatus: jest.fn(() => {}),
64
- };
65
- });
66
-
67
- beforeEach(() => {
68
- stream.removeAllListeners();
69
- });
70
-
71
- it("stream actually starts", () => {
72
- const emulatorServiceInstance = new EmulatorControllerService("http://foo");
73
- const { container } = render(
74
- <div style={{ width: "200px", height: "200px" }}>
75
- <EmulatorPngView emulator={emulatorServiceInstance} />
76
- </div>
77
- );
78
-
79
- expect(emulatorServiceInstance.streamScreenshot).toHaveBeenCalledTimes(1);
80
- });
81
-
82
- it("Get screenshot renders an image.", () => {
83
- const emulatorServiceInstance = new EmulatorControllerService("http://foo");
84
- const { container } = render(
85
- <EmulatorPngView emulator={emulatorServiceInstance} poll={true} />
86
- );
87
- const pngView = container.querySelector("img");
88
- expect(pngView.src).toBe("data:image/jpeg;base64," + googleLogo);
89
- });
90
-
91
- it("Has a connected state after the first image arrives", () => {
92
- const emulatorServiceInstance = new EmulatorControllerService("http://foo");
93
- const changeState = jest.fn();
94
- render(
95
- <EmulatorPngView
96
- emulator={emulatorServiceInstance}
97
- onStateChange={changeState}
98
- />
99
- );
100
- expect(changeState).toHaveBeenCalledWith("connecting");
101
- act(() => stream.emit("data", googleImage));
102
- expect(changeState).toHaveBeenCalledWith("connected");
103
- });
104
-
105
- it("Attempts to reconnect if the server disconnects", async () => {
106
- const emulatorServiceInstance = new EmulatorControllerService("http://foo");
107
- const changeState = jest.fn();
108
- render(
109
- <EmulatorPngView
110
- emulator={emulatorServiceInstance}
111
- onStateChange={changeState}
112
- />
113
- );
114
- expect(emulatorServiceInstance.streamScreenshot).toHaveBeenCalledTimes(1);
115
- stream.emit("data", googleImage);
116
- waitFor(() => expect(changeState).toHaveBeenCalledWith("connected"));
117
- stream.emit("error", "fda");
118
- expect(emulatorServiceInstance.streamScreenshot).toHaveBeenCalledTimes(2);
119
- });
120
-
121
- it("Gives up on the second failure.", () => {
122
- const emulatorServiceInstance = new EmulatorControllerService("http://foo");
123
- const changeState = jest.fn();
124
- render(
125
- <EmulatorPngView
126
- emulator={emulatorServiceInstance}
127
- onStateChange={changeState}
128
- />
129
- );
130
- expect(emulatorServiceInstance.streamScreenshot).toHaveBeenCalledTimes(1);
131
-
132
- // Connect
133
- stream.emit("data", googleImage);
134
- waitFor(() => expect(changeState).toHaveBeenCalledWith("connected"));
135
-
136
- // First break, we attempt a reconnect.
137
- stream.emit("error", "fda");
138
- expect(emulatorServiceInstance.streamScreenshot).toHaveBeenCalledTimes(2);
139
- expect(changeState).not.toHaveBeenCalledWith("disconnected");
140
-
141
- // We could not reconnect, so we fail.
142
- stream.emit("error", "fda");
143
- waitFor(() => expect(changeState).toHaveBeenCalledWith("disconnected"));
144
- });
145
- });
@@ -1,118 +0,0 @@
1
- /**
2
- * @jest-environment jsdom
3
- */
4
- /*
5
- * Copyright 2021 The Android Open Source Project
6
- *
7
- * Licensed under the Apache License, Version 2.0 (the "License")
8
- * you may not use this file except in compliance with the License.
9
- * You may obtain a copy of the License at
10
- *
11
- * http://www.apache.org/licenses/LICENSE-2.0
12
- *
13
- * Unless required by applicable law or agreed to in writing, software
14
- * distributed under the License is distributed on an "AS IS" BASIS,
15
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
- * See the License for the specific language governing permissions and
17
- * limitations under the License.
18
- */
19
- import "@testing-library/jest-dom";
20
-
21
- import React from "react";
22
- import { render, fireEvent, screen } from "@testing-library/react";
23
- import withMouseKeyHandler from "../src/components/emulator/views/event_handler";
24
- import * as Proto from "../src/proto/emulator_controller_pb";
25
- import * as Rtc from "../src/proto/rtc_service_pb";
26
-
27
- import JsepProtocol from "../src/components/emulator/net/jsep_protocol_driver";
28
- import {
29
- RtcService,
30
- EmulatorControllerService,
31
- } from "../src/proto/emulator_web_client";
32
-
33
- jest.mock("../src/proto/emulator_web_client");
34
- jest.mock("../src/components/emulator/net/jsep_protocol_driver");
35
-
36
- class FakeEmulator extends React.Component {
37
- render() {
38
- return (
39
- <div
40
- data-testid="fake"
41
- style={{ height: "200px", width: "200px", backgroundColor: "#555" }}
42
- ></div>
43
- );
44
- }
45
- }
46
-
47
-
48
-
49
- const fakeTouchEvent = (tp, x, y, force, props = {}) => {
50
- const event = new TouchEvent(tp, {
51
- bubbles: true,
52
- cancelable: true,
53
- ...props,
54
- });
55
-
56
- Object.defineProperty(event, "changedTouches", {
57
- get: () => [
58
- { clientX: x, clientY: y, radiusX: 4, radiusY: 4, force: force },
59
- ],
60
- });
61
- return event;
62
- };
63
-
64
- const TestView = withMouseKeyHandler(FakeEmulator);
65
- describe("The event handler", () => {
66
- const rtcServiceInstance = new RtcService("http://foo");
67
- const emulatorServiceInstance = new EmulatorControllerService("http://foo");
68
- let jsep, fakeScreen;
69
-
70
- beforeEach(() => {
71
- jsep = new JsepProtocol(emulatorServiceInstance, rtcServiceInstance, true);
72
-
73
- render(<TestView emulator={emulatorServiceInstance} jsep={jsep} />);
74
- fakeScreen = screen.getByTestId("fake").parentElement;
75
- Object.defineProperty(fakeScreen, "clientWidth", { get: () => 200 });
76
- Object.defineProperty(fakeScreen, "clientHeight", { get: () => 200 });
77
-
78
- expect(fakeScreen).toBeInTheDocument();
79
- });
80
-
81
- test("Normalizes touch pressure of 1.0 to EV_MAX", () => {
82
- fireEvent(fakeScreen, fakeTouchEvent("touchstart", 10, 10, 1.0));
83
-
84
- // EV_MAX = 0x7fff
85
- expect(jsep.send.mock.calls[0][1]["array"].flat(3)[3]).toBe(0x7fff);
86
- });
87
-
88
-
89
- test("Normalizes touch pressure >1.0 to EV_MAX", () => {
90
- fireEvent(fakeScreen, fakeTouchEvent("touchstart", 10, 10, 10.0));
91
-
92
- // EV_MAX = 0x7fff
93
- expect(jsep.send.mock.calls[0][1]["array"].flat(3)[3]).toBe(0x7fff);
94
- });
95
-
96
- test("A touch start event has a minimum value >0.01", () => {
97
- fireEvent(fakeScreen, fakeTouchEvent("touchstart", 10, 10, 0.0));
98
-
99
- // Some browsers do no set the force property, which could be mistaken for
100
- // lift event in the emulator. We now make sure we always have a minimum
101
- // value.
102
- expect(jsep.send.mock.calls[0][1]["array"].flat(3)[3]).toBeGreaterThanOrEqual(327);
103
- });
104
-
105
- test("Normalizes touch end event to a pressure of 0.0 to EV_MIN", () => {
106
- fireEvent(fakeScreen, fakeTouchEvent("touchend", 10, 10, 0.0));
107
-
108
- // So the result we test against is a protobuf message. Protobuf
109
- // is optimized to not ship the value 0 and will set it to "null".
110
- expect(jsep.send.mock.calls[0][1]["array"].flat(3)[3]).toBe(null);
111
- });
112
-
113
- test("Normalizes touch pressure of 0.5 to an integer of of +/- EV_MAX", () => {
114
- fireEvent(fakeScreen, fakeTouchEvent("touchstart", 10, 10, 0.5));
115
- expect(jsep.send.mock.calls[0][1]["array"].flat(3)[3]).toBeGreaterThan(16380);
116
- expect(jsep.send.mock.calls[0][1]["array"].flat(3)[3]).toBeLessThan(16387);
117
- });
118
- });