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,228 +0,0 @@
1
- /**
2
- * @jest-environment jsdom
3
- */
4
- /*
5
- * Copyright 2020 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 * as Rtc from "../src/proto/rtc_service_pb";
24
- import JsepProtocol from "../src/components/emulator/net/jsep_protocol_driver.js";
25
- import {
26
- RtcService,
27
- EmulatorControllerService,
28
- } from "../src/proto/emulator_web_client";
29
-
30
- jest.mock("../src/proto/emulator_web_client");
31
-
32
- const jsepMessage = (object, uid) => {
33
- const guid = new Rtc.RtcId();
34
- guid.setGuid(uid);
35
-
36
- const jsepMsg = new Rtc.JsepMsg();
37
- jsepMsg.setId(guid);
38
- jsepMsg.setMessage(JSON.stringify(object));
39
- return jsepMsg;
40
- };
41
-
42
- const requestRtcStream = jest.fn((request, metadata, callback) => {
43
- const guid = new Rtc.RtcId();
44
- guid.setGuid("abcde");
45
-
46
- callback(null, guid);
47
- });
48
-
49
- const receiveJsepMessage = (message) => {
50
- const jsepMsg = jsepMessage(message);
51
- return jest.fn((request, metadata, callback) => {
52
- callback(null, jsepMsg);
53
- });
54
- };
55
-
56
- const RTCPeerConnectionMock = jest.fn().mockImplementation((cfg) => ({
57
- ondatachannel: jest.fn(),
58
- createAnswer: jest.fn(),
59
- addEventListener: jest.fn(),
60
- addIceCandidate: jest.fn(),
61
- dispatchEvent: jest.fn(),
62
- setRemoteDescription: jest.fn(),
63
- setLocalDescription: jest.fn(),
64
- close: jest.fn(),
65
- }));
66
-
67
- Object.defineProperty(window, "RTCPeerConnection", {
68
- writable: true,
69
- value: jest.fn().mockImplementation((cfg) => {
70
- let sdp = null;
71
- let signal = null;
72
- let state = null;
73
- return {
74
- ondatachannel: jest.fn(),
75
- createAnswer: jest.fn(() => {
76
- return new Promise((resolve) => {
77
- return { answer: "fake-answer" };
78
- });
79
- }),
80
- addEventListener: jest.fn(),
81
- addIceCandidate: jest.fn(),
82
- dispatchEvent: jest.fn(),
83
- setRemoteDescription: (desc) => {
84
- sdp = desc;
85
- state = "have-remote-offer";
86
- if (signal) signal();
87
- },
88
- setLocalDescription: jest.fn(),
89
- get currentRemoteDescription() {
90
- return sdp;
91
- },
92
- set onsignalingstatechange(fn) {
93
- signal = fn;
94
- },
95
- get signalingState() {
96
- return state;
97
- },
98
- close: jest.fn(),
99
- };
100
- }),
101
- });
102
-
103
- Object.defineProperty(window, "RTCIceCandidate", {
104
- writable: true,
105
- value: jest.fn().mockImplementation((cfg) => ({})),
106
- });
107
-
108
- Object.defineProperty(window, "RTCSessionDescription", {
109
- writable: true,
110
- value: jest.fn().mockImplementation((desc) => {
111
- return { sdp: desc };
112
- }),
113
- });
114
-
115
- const sdp = {
116
- sdp: "fakesdp1",
117
- type: "offer",
118
- };
119
-
120
- const sdp2 = {
121
- sdp: "fakesdp2",
122
- type: "offer",
123
- };
124
- const candidates_and_sdp = [
125
- {
126
- candidate:
127
- "candidate:4205781435 1 udp 2122260223 10.146.0.6 37608 typ host generation 0 ufrag Er9W network-id 1 network-cost 50",
128
- sdpMLineIndex: 1,
129
- sdpMid: "1",
130
- },
131
- {
132
- candidate:
133
- "candidate:3022839115 1 tcp 1518280447 10.146.0.6 36959 typ host tcptype passive generation 0 ufrag Er9W network-id 1 network-cost 50",
134
- sdpMLineIndex: 0,
135
- sdpMid: "0",
136
- },
137
- sdp,
138
- ];
139
-
140
- const jsepProtocol = (messages) => {
141
- RtcService.mockClear();
142
- EmulatorControllerService.mockClear();
143
-
144
- let receive = jest.fn();
145
- for (var i = 0; i < messages.length; i++) {
146
- receive.mockImplementationOnce(receiveJsepMessage(messages[i]));
147
- }
148
- RtcService.mockImplementation(() => {
149
- return {
150
- requestRtcStream: requestRtcStream,
151
- receiveJsepMessage: receive,
152
- sendJsepMessage: jest.fn((msg) => {
153
- console.log("Sending " + msg);
154
- }),
155
- };
156
- });
157
- const rtcServiceInstance = new RtcService("http://foo");
158
- const emulatorServiceInstance = new EmulatorControllerService("http://foo");
159
- return {
160
- rtc: rtcServiceInstance,
161
- jsep: new JsepProtocol(emulatorServiceInstance, rtcServiceInstance, true),
162
- };
163
- };
164
-
165
- describe("Basic jsep protocol with polling.", () => {
166
- it("calls request rtc stream", () => {
167
- const { rtc, jsep } = jsepProtocol([{ bye: "we're done" }]);
168
- jsep.startStream();
169
- expect(rtc.requestRtcStream.mock.calls.length).toBe(1);
170
- expect(rtc.receiveJsepMessage.mock.calls.length).toBe(1);
171
- });
172
-
173
- it("Notifies listeners of a disconnect", () => {
174
- const { jsep } = jsepProtocol([{ bye: "we're done" }]);
175
-
176
- const disconnect = jest.fn();
177
- jsep.on("disconnected", disconnect);
178
- jsep.startStream();
179
- expect(disconnect).toHaveBeenCalledTimes(1);
180
- });
181
-
182
- it("Does not process messages before start", () => {
183
- const { jsep } = jsepProtocol(candidates_and_sdp);
184
-
185
- jsep.startStream();
186
- // All candidates are queued.
187
- expect(jsep.old_emu_patch.candidates.length).toBe(2);
188
- expect(jsep.old_emu_patch.sdp).not.toBeNull();
189
- });
190
-
191
- it("Flush message queue after bye", () => {
192
- let msg = Array.from(candidates_and_sdp);
193
- msg.push({ bye: "we're done" });
194
- const { jsep } = jsepProtocol(msg);
195
-
196
- jsep.startStream();
197
- expect(jsep.old_emu_patch.candidates.length).toBe(0);
198
- expect(jsep.old_emu_patch.sdp).toBe(null);
199
- expect(jsep.peerConnection).toBe(null);
200
- });
201
-
202
- it("Out of order messages handled after start", () => {
203
- let msg = Array.from(candidates_and_sdp);
204
- msg.push({ start: { foo: "bar" } });
205
- const { jsep } = jsepProtocol(msg);
206
-
207
- jsep.startStream();
208
- expect(jsep.old_emu_patch.candidates.length).toBe(0);
209
- expect(jsep.peerConnection).not.toBeNull();
210
- expect(jsep.peerConnection.currentRemoteDescription).not.toBeNull();
211
- // Peer connection was initialized with rtc config
212
- expect(RTCPeerConnection.mock.calls[0][0]).toStrictEqual({ foo: "bar" });
213
- });
214
-
215
- it.skip("Never handles sdp twice / (async problem)", async () => {
216
- // 2nd jsep gets dropped.
217
- let { rtc, jsep } = jsepProtocol([sdp, sdp2, { start: { foo: "bar" } }]);
218
- jsep.startStream();
219
- expect(jsep.old_emu_patch.candidates.length).toBe(0);
220
- expect(jsep.old_emu_patch.sdp).toBeNull();
221
- expect(jsep.old_emu_patch.answer).toBe(true);
222
- expect(jsep.peerConnection).not.toBeNull();
223
- expect(jsep.peerConnection.currentRemoteDescription.sdp.sdp).toBe(sdp.sdp);
224
- // Peer connection was initialized with rtc config
225
- expect(RTCPeerConnection.mock.calls[0][0]).toStrictEqual({ foo: "bar" });
226
- expect(rtc.sendJsepMessage.mock.calls[0]).toBe(1);
227
- });
228
- });
@@ -1,37 +0,0 @@
1
-
2
- /**
3
- * @jest-environment jsdom
4
- */
5
- /*
6
- * Copyright 2023 The Android Open Source Project
7
- *
8
- * Licensed under the Apache License, Version 2.0 (the "License")
9
- * you may not use this file except in compliance with the License.
10
- * You may obtain a copy of the License at
11
- *
12
- * http://www.apache.org/licenses/LICENSE-2.0
13
- *
14
- * Unless required by applicable law or agreed to in writing, software
15
- * distributed under the License is distributed on an "AS IS" BASIS,
16
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
- * See the License for the specific language governing permissions and
18
- * limitations under the License.
19
- */
20
- import React from "react";
21
- import { render, act, waitFor, fireEvent, getByText } from "@testing-library/react";
22
- import ResizingComponent from "../src/components/emulator/views/resizing_component"
23
- import { toBeInTheDocument, toHaveBeenCalledWith } from '@testing-library/jest-dom';
24
-
25
-
26
-
27
- describe("ResizingComponent", () => {
28
- it("renders children", () => {
29
- const { getByText } = render(
30
- <ResizingComponent>
31
- <p>Hello, world!</p>
32
- </ResizingComponent>
33
- );
34
- expect(getByText("Hello, world!")).toBeInTheDocument();
35
- });
36
-
37
- });
@@ -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+DatMexaZ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TwKqQZoKmUiw+5QJZje2OPRwZ0UltkC9JlkuZCICh2VpbHHoWDWLQid/xOuV7sZwHCYiUFViURWf2Q0t1hY7mectOBjjuS1wanBJsBsTGRhAQ+GEjWY3tEi0+0ZS6GRLtIILUrwt0yDj2qe0o5hUndkNLRqfXbGAF8y9ENH0ShLbYGYkoDQdgwXNbmTxQifTKHRyrNXuKxLbKGZEIG8oVzrxaFdHU+hkd0srW4g80snMyPDWetvSm/zE7EYWkc6PViJ08j+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
- });