@@ -93,6 +93,13 @@ export const constants = /** @type {const} */ ({
93
93
*/
94
94
COMMAND_METHOD : 'ms.remote.control' ,
95
95
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
+
96
103
/**
97
104
* The `Event` property in msg payload when requesting a token
98
105
*
@@ -189,6 +196,16 @@ function isTokenMessage(msg) {
189
196
return Boolean ( msg ?. event === constants . TOKEN_EVENT && msg ?. data ?. token ) ;
190
197
}
191
198
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
+
192
209
/**
193
210
* Represents a connection to a Tizen web socket server.
194
211
*/
@@ -613,7 +630,7 @@ export class TizenRemote extends createdTypedEmitterClass() {
613
630
*/
614
631
#listenWs( event , listener , { context, once = false } = { } ) {
615
632
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. ' ) ;
617
634
}
618
635
619
636
const method = once ? this . #ws. once : this . #ws. on ;
@@ -956,6 +973,10 @@ export class TizenRemote extends createdTypedEmitterClass() {
956
973
} else {
957
974
this . #debug( 'Warning: received token update, but token (%s) is unchanged' , this . #token) ;
958
975
}
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 ( ) ;
959
980
}
960
981
} catch ( err ) {
961
982
this . #debug( 'Warning: could not parse message: %s' , err ) ;
0 commit comments