Skip to content

Commit abebfcd

Browse files
authored
feat(tizen-remote): unset if the request got timeout in remote mode (#688)
* fix: fix condtiion of this.isTokenSupportedDevice with appium:resetRcToken * feat: add token unset for the ms.channel.timeOut * tweak the error message
1 parent 0905cee commit abebfcd

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

packages/tizen-remote/lib/tizen-remote.js

+22-1
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,13 @@ export const constants = /** @type {const} */ ({
9393
*/
9494
COMMAND_METHOD: 'ms.remote.control',
9595

96+
/**
97+
* The `timeout` property in msg payload when sending commands to the Tizen device
98+
*
99+
* This could occur when the given api token was valid but needs a fresh token?
100+
*/
101+
COMMAND_TIMEOUT: 'ms.channel.timeOut',
102+
96103
/**
97104
* The `Event` property in msg payload when requesting a token
98105
*
@@ -189,6 +196,16 @@ function isTokenMessage(msg) {
189196
return Boolean(msg?.event === constants.TOKEN_EVENT && msg?.data?.token);
190197
}
191198

199+
/**
200+
* Type guard for incoming messages
201+
* @internal
202+
* @param {any} msg
203+
* @returns {msg is NewTokenMessage}
204+
*/
205+
function isCommandTimeout(msg) {
206+
return Boolean(msg?.event === constants.COMMAND_TIMEOUT);
207+
}
208+
192209
/**
193210
* Represents a connection to a Tizen web socket server.
194211
*/
@@ -613,7 +630,7 @@ export class TizenRemote extends createdTypedEmitterClass() {
613630
*/
614631
#listenWs(event, listener, {context, once = false} = {}) {
615632
if (!this.#ws) {
616-
throw new Error('Not connected');
633+
throw new Error('Failed to establish the websocket connection to the TV device. The rcToken was invalid or might need to be refreshed.');
617634
}
618635

619636
const method = once ? this.#ws.once : this.#ws.on;
@@ -956,6 +973,10 @@ export class TizenRemote extends createdTypedEmitterClass() {
956973
} else {
957974
this.#debug('Warning: received token update, but token (%s) is unchanged', this.#token);
958975
}
976+
} else if (isCommandTimeout(msg)) {
977+
this.#debug('Received ms.channel.timeOut message. The token (%s) might need a fresh one. ' +
978+
'Unset the token to start from a fresh token. Please complete the device paring if needed.', this.#token);
979+
this.unsetToken();
959980
}
960981
} catch (err) {
961982
this.#debug('Warning: could not parse message: %s', err);

0 commit comments

Comments
 (0)