chore: fix the android ws sender/receiver (#13641)

This commit is contained in:
Pavel Feldman 2022-04-19 12:28:05 -08:00 committed by GitHub
parent cde7c5df44
commit 06645b0a1f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 4 deletions

View File

@ -54,6 +54,9 @@ export { SocksProxyAgent } from 'socks-proxy-agent';
import StackUtilsLibrary from 'stack-utils'; import StackUtilsLibrary from 'stack-utils';
export const StackUtils = StackUtilsLibrary; export const StackUtils = StackUtilsLibrary;
import wsLibrary, { WebSocketServer } from 'ws'; // @ts-ignore
import wsLibrary, { WebSocketServer, Receiver, Sender } from 'ws';
export const ws = wsLibrary; export const ws = wsLibrary;
export const wsServer = WebSocketServer; export const wsServer = WebSocketServer;
export const wsReceiver = Receiver;
export const wsSender = Sender;

View File

@ -21,7 +21,7 @@ import fs from 'fs';
import os from 'os'; import os from 'os';
import path from 'path'; import path from 'path';
import type * as stream from 'stream'; import type * as stream from 'stream';
import { ws } from '../../utilsBundle'; import { wsReceiver, wsSender } from '../../utilsBundle';
import { createGuid, makeWaitForNextTask, isUnderTest } from '../../utils'; import { createGuid, makeWaitForNextTask, isUnderTest } from '../../utils';
import { removeFolders } from '../../utils/fileUtils'; import { removeFolders } from '../../utils/fileUtils';
import type { BrowserOptions, BrowserProcess, PlaywrightOptions } from '../browser'; import type { BrowserOptions, BrowserProcess, PlaywrightOptions } from '../browser';
@ -418,7 +418,7 @@ class AndroidBrowser extends EventEmitter {
this.onclose(); this.onclose();
}); });
}); });
this._receiver = new (ws as any).Receiver() as stream.Writable; this._receiver = new wsReceiver() as stream.Writable;
this._receiver.on('message', message => { this._receiver.on('message', message => {
this._waitForNextTask(() => { this._waitForNextTask(() => {
if (this.onmessage) if (this.onmessage)
@ -452,7 +452,7 @@ Sec-WebSocket-Version: 13\r
} }
function encodeWebFrame(data: string): Buffer { function encodeWebFrame(data: string): Buffer {
return (ws as any).Sender.frame(Buffer.from(data), { return wsSender.frame(Buffer.from(data), {
opcode: 1, opcode: 1,
mask: true, mask: true,
fin: true, fin: true,

View File

@ -31,5 +31,7 @@ export const SocksProxyAgent: typeof import('../bundles/utils/node_modules/socks
export const StackUtils: typeof import('../bundles/utils/node_modules/@types/stack-utils') = require('./utilsBundleImpl').StackUtils; export const StackUtils: typeof import('../bundles/utils/node_modules/@types/stack-utils') = require('./utilsBundleImpl').StackUtils;
export const ws: typeof import('../bundles/utils/node_modules/@types/ws') = require('./utilsBundleImpl').ws; export const ws: typeof import('../bundles/utils/node_modules/@types/ws') = require('./utilsBundleImpl').ws;
export const wsServer: typeof import('../bundles/utils/node_modules/@types/ws').WebSocketServer = require('./utilsBundleImpl').wsServer; export const wsServer: typeof import('../bundles/utils/node_modules/@types/ws').WebSocketServer = require('./utilsBundleImpl').wsServer;
export const wsReceiver = require('./utilsBundleImpl').wsReceiver;
export const wsSender = require('./utilsBundleImpl').wsSender;
export type { Command } from '../bundles/utils/node_modules/commander'; export type { Command } from '../bundles/utils/node_modules/commander';
export type { WebSocket, WebSocketServer, RawData as WebSocketRawData, EventEmitter as WebSocketEventEmitter } from '../bundles/utils/node_modules/@types/ws'; export type { WebSocket, WebSocketServer, RawData as WebSocketRawData, EventEmitter as WebSocketEventEmitter } from '../bundles/utils/node_modules/@types/ws';