Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#21 [LG 2022 Model] Error: socket hang up #33

Merged
merged 4 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ package in your `package.json`)
|`appium:debuggerPort`|[Optional; default `9998`] The port on the device exposed for remote Chromium debugging.|
|`appium:chromedriverExecutable`|[Optional] Most LG TVs run a very old version of Chrome. Because this driver uses Chromedriver under the hood, you'll need to have a very old version of Chromedriver handy that works with the version of Chrome backing the apps on your TV. In our testing, we've found Chromedriver 2.36 to work with most TVs. You need to tell the driver where you've installed this version of Chromedriver using the `appium:chromedriverExecutable` capability, passing in an absolute path to the Chromedriver binary.|
|`appium:websocketPort`|[Optional; default `3000`] The websocket port on the device exposed for remote control|
|`appium:websocketPortSecure`|[Optional; default `3001`] The secure websocket port on the device exposed for remote control|
|`appium:websocketSecure`|[Optional; default `false`] Flag that enables use of `websocketPortSecure` port, also starts WebSocket over https instead. **DISCLAMER** Enabling this flag, it is required to set environment variable `export NODE_TLS_REJECT_UNAUTHORIZED=0`, which can be a potential security risk.|
precali1996 marked this conversation as resolved.
Show resolved Hide resolved
|`appium:autoExtendDevMode`|[Optional; default `true`] Whether you want Appium to extend the dev mode timer on the device whenever a new session starts.|
|`appium:appLaunchParams`|[Optional; default `{}`] A key/value object of app launch param to be passed to `ares-launch`|
|`appium:appLaunchCooldown`|[Optional; default `3000`] How many ms to wait after triggering app launch to attempt to connect to it via Chromedriver.|
Expand Down
8 changes: 8 additions & 0 deletions lib/constraints.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ export const CAP_CONSTRAINTS = Object.freeze(
websocketPort: {
isNumber: true,
},
websocketPortSecure: {
isNumber: true,
},
websocketSecure: {
isBoolean: true,
},
chromedriverExecutable: {
isString: true,
//presence: true
Expand Down Expand Up @@ -55,6 +61,8 @@ export const CAP_CONSTRAINTS = Object.freeze(
export const DEFAULT_CAPS = Object.freeze(/** @type {const} */({
'appium:debuggerPort': 9998,
'appium:websocketPort': 3000,
'appium:websocketPortSecure': 3001,
'appium:websocketSecure': false,
'appium:autoExtendDevMode': true,
'appium:appLaunchCooldown': 3000,
'appium:keyCooldown': 750,
Expand Down
4 changes: 4 additions & 0 deletions lib/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ export class WebOSDriver extends BaseDriver {
appLaunchCooldown,
remoteOnly,
websocketPort,
websocketPortSecure,
websocketSecure,
keyCooldown,
} = caps;

Expand Down Expand Up @@ -138,6 +140,8 @@ export class WebOSDriver extends BaseDriver {
valueBox: this.valueBox,
deviceName,
url: `ws://${deviceHost}:${websocketPort}`,
urlSecure: `wss://${deviceHost}:${websocketPortSecure}`,
websocketSecure,
remoteKeyCooldown: keyCooldown,
});
log.info(`Connecting remote; address any prompts on screen now!`);
Expand Down
16 changes: 15 additions & 1 deletion lib/remote/lg-socket-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,18 @@ export class LGWSClient {
/** @type {string} */
#url;

/** @type {string} */
#urlSecure;

/** @type {WebSocket|undefined} */
#ws;

/** @type {boolean} */
#saveClientKey;

/** @type {boolean} */
#websocketSecure;

#cmdNum = 0;

/** @type {import('@appium/types').AppiumLogger} */
Expand Down Expand Up @@ -58,6 +64,8 @@ export class LGWSClient {
*/
constructor({
url,
urlSecure,
websocketSecure,
valueBox,
deviceName,
log = logger.getLogger('LGWsClient'),
Expand All @@ -66,6 +74,8 @@ export class LGWSClient {
}) {
this.#valueBox = valueBox;
this.#url = url;
this.#urlSecure = urlSecure;
this.#websocketSecure = websocketSecure;
this.#log = log;
this.#saveClientKey = saveClientKey;
this.#remoteKeyCooldown = remoteKeyCooldown;
Expand All @@ -88,7 +98,11 @@ export class LGWSClient {
ws.removeListener(WsEvent.OPEN, onOpen);
rej(err);
};
ws = new WebSocket(this.#url).once(WsEvent.OPEN, onOpen).once(WsEvent.ERROR, onError);
if (this.#websocketSecure) {
ws = new WebSocket(this.#urlSecure, {rejectUnauthorized: false}).once(WsEvent.OPEN, onOpen).once(WsEvent.ERROR, onError);
} else {
ws = new WebSocket(this.#url).once(WsEvent.OPEN, onOpen).once(WsEvent.ERROR, onError);
}
this.#ws = ws;
});
}
Expand Down
2 changes: 2 additions & 0 deletions lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ export interface PressKeyOptions {
export interface LGSocketClientOpts {
deviceName: string;
url: string;
urlSecure: string;
websocketSecure: boolean;
valueBox: ValueBox;
clientKey?: string;
log?: AppiumLogger;
Expand Down