@tvlabs/wdio-service 0.1.3 → 0.1.5
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.
- package/README.md +15 -15
- package/cjs/channel.d.ts +1 -1
- package/cjs/channel.d.ts.map +1 -1
- package/cjs/index.js +403 -20
- package/cjs/logger.d.ts +1 -0
- package/cjs/logger.d.ts.map +1 -1
- package/cjs/package.json +3 -1
- package/cjs/types.d.ts +5 -1
- package/cjs/types.d.ts.map +1 -1
- package/cjs/utils.d.ts +5 -0
- package/cjs/utils.d.ts.map +1 -0
- package/esm/channel.d.ts +1 -1
- package/esm/channel.d.ts.map +1 -1
- package/esm/index.js +380 -4
- package/esm/logger.d.ts +1 -0
- package/esm/logger.d.ts.map +1 -1
- package/esm/package.json +3 -1
- package/esm/types.d.ts +5 -1
- package/esm/types.d.ts.map +1 -1
- package/esm/utils.d.ts +5 -0
- package/esm/utils.d.ts.map +1 -0
- package/package.json +11 -8
- package/rollup.config.js +53 -0
- package/src/channel.ts +10 -6
- package/src/logger.ts +60 -3
- package/src/types.ts +6 -1
- package/src/utils.ts +17 -0
- package/cjs/channel.js +0 -184
- package/cjs/logger.js +0 -57
- package/cjs/service.js +0 -79
- package/cjs/types.js +0 -2
- package/esm/channel.js +0 -180
- package/esm/logger.js +0 -53
- package/esm/service.js +0 -76
- package/esm/types.js +0 -1
package/README.md
CHANGED
|
@@ -56,22 +56,22 @@ To use this with WebdriverIO remote but without the test runner, call the before
|
|
|
56
56
|
import { remote } from 'webdriverio';
|
|
57
57
|
import { TVLabsService } from '@tvlabs/wdio-service';
|
|
58
58
|
|
|
59
|
-
const capabilities = { ... };
|
|
60
|
-
|
|
61
|
-
const wdOpts = {
|
|
62
|
-
capabilities,
|
|
63
|
-
hostname: 'appium.tvlabs.ai',
|
|
64
|
-
port: 4723,
|
|
65
|
-
headers: {
|
|
66
|
-
Authorization: `Bearer ${process.env.TVLABS_API_TOKEN}`,
|
|
67
|
-
},
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
const serviceOpts = {
|
|
71
|
-
apiKey: process.env.TVLABS_API_TOKEN,
|
|
72
|
-
}
|
|
73
|
-
|
|
74
59
|
async function run() {
|
|
60
|
+
const capabilities = { ... };
|
|
61
|
+
|
|
62
|
+
const wdOpts = {
|
|
63
|
+
capabilities,
|
|
64
|
+
hostname: 'appium.tvlabs.ai',
|
|
65
|
+
port: 4723,
|
|
66
|
+
headers: {
|
|
67
|
+
Authorization: `Bearer ${process.env.TVLABS_API_TOKEN}`,
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const serviceOpts = {
|
|
72
|
+
apiKey: process.env.TVLABS_API_TOKEN,
|
|
73
|
+
}
|
|
74
|
+
|
|
75
75
|
const service = new TVLabsService(serviceOpts, capabilities, {})
|
|
76
76
|
|
|
77
77
|
// The TV Labs service does not use specs or a cid, pass default values.
|
package/cjs/channel.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export declare class TVLabsChannel {
|
|
|
9
9
|
private requestTopic?;
|
|
10
10
|
private log;
|
|
11
11
|
private readonly events;
|
|
12
|
-
constructor(endpoint: string, maxReconnectRetries: number, key: string, logLevel
|
|
12
|
+
constructor(endpoint: string, maxReconnectRetries: number, key: string, logLevel?: LogLevel);
|
|
13
13
|
disconnect(): Promise<void>;
|
|
14
14
|
connect(): Promise<void>;
|
|
15
15
|
newSession(capabilities: TVLabsCapabilities, maxRetries: number, retry?: number): Promise<string>;
|
package/cjs/channel.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"channel.d.ts","sourceRoot":"","sources":["../src/channel.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"channel.d.ts","sourceRoot":"","sources":["../src/channel.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACV,kBAAkB,EAIlB,QAAQ,EACT,MAAM,YAAY,CAAC;AAGpB,qBAAa,aAAa;IAgBtB,OAAO,CAAC,QAAQ;IAChB,OAAO,CAAC,mBAAmB;IAC3B,OAAO,CAAC,GAAG;IACX,OAAO,CAAC,QAAQ;IAlBlB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,UAAU,CAAU;IAC5B,OAAO,CAAC,YAAY,CAAC,CAAU;IAC/B,OAAO,CAAC,GAAG,CAAS;IAEpB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAOZ;gBAGD,QAAQ,EAAE,MAAM,EAChB,mBAAmB,EAAE,MAAM,EAC3B,GAAG,EAAE,MAAM,EACX,QAAQ,GAAE,QAAiB;IAgB/B,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAQ3B,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAiBxB,UAAU,CACd,YAAY,EAAE,kBAAkB,EAChC,UAAU,EAAE,MAAM,EAClB,KAAK,SAAI,GACR,OAAO,CAAC,MAAM,CAAC;YAWJ,WAAW;YAkBX,cAAc;IAsD5B,OAAO,CAAC,gBAAgB;YAUV,cAAc;YAuBd,IAAI;YAgBJ,IAAI;IAoBlB,OAAO,CAAC,MAAM;IAWd,OAAO,CAAC,gBAAgB;IAgBxB,OAAO,CAAC,iBAAiB;IAIzB,OAAO,CAAC,MAAM,CAAC,cAAc;CAQ9B"}
|
package/cjs/index.js
CHANGED
|
@@ -1,21 +1,404 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var webdriverio = require('webdriverio');
|
|
6
|
+
var crypto = require('crypto');
|
|
7
|
+
var ws = require('ws');
|
|
8
|
+
var phoenix = require('phoenix');
|
|
9
|
+
|
|
10
|
+
function _interopNamespaceDefault(e) {
|
|
11
|
+
var n = Object.create(null);
|
|
12
|
+
if (e) {
|
|
13
|
+
Object.keys(e).forEach(function (k) {
|
|
14
|
+
if (k !== 'default') {
|
|
15
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
16
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
get: function () { return e[k]; }
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
n.default = e;
|
|
24
|
+
return Object.freeze(n);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
var crypto__namespace = /*#__PURE__*/_interopNamespaceDefault(crypto);
|
|
28
|
+
|
|
29
|
+
const LOG_LEVELS = {
|
|
30
|
+
error: 0,
|
|
31
|
+
warn: 1,
|
|
32
|
+
info: 2,
|
|
33
|
+
debug: 3,
|
|
34
|
+
trace: 4,
|
|
35
|
+
silent: 5,
|
|
15
36
|
};
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
37
|
+
class Logger {
|
|
38
|
+
name;
|
|
39
|
+
logLevel;
|
|
40
|
+
constructor(name, logLevel = 'info') {
|
|
41
|
+
this.name = name;
|
|
42
|
+
this.logLevel = logLevel;
|
|
43
|
+
}
|
|
44
|
+
shouldLog(level) {
|
|
45
|
+
if (this.logLevel === 'silent') {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
return LOG_LEVELS[level] <= LOG_LEVELS[this.logLevel];
|
|
49
|
+
}
|
|
50
|
+
formatMessage(level, ...args) {
|
|
51
|
+
const timestamp = new Date().toISOString();
|
|
52
|
+
return `${timestamp} ${level.toUpperCase()} ${this.name}: ${args
|
|
53
|
+
.map((arg) => this.serializeArg(arg))
|
|
54
|
+
.join(' ')}`;
|
|
55
|
+
}
|
|
56
|
+
serializeArg(arg) {
|
|
57
|
+
if (typeof arg === 'string' ||
|
|
58
|
+
typeof arg === 'number' ||
|
|
59
|
+
typeof arg === 'boolean') {
|
|
60
|
+
return String(arg);
|
|
61
|
+
}
|
|
62
|
+
if (arg === null || arg === undefined) {
|
|
63
|
+
return String(arg);
|
|
64
|
+
}
|
|
65
|
+
if (arg instanceof Error) {
|
|
66
|
+
return arg.stack || `${arg.name}: ${arg.message}`;
|
|
67
|
+
}
|
|
68
|
+
if (typeof arg === 'object') {
|
|
69
|
+
try {
|
|
70
|
+
const stringified = JSON.stringify(arg, (key, value) => {
|
|
71
|
+
if (value instanceof Error) {
|
|
72
|
+
return `${value.name}: ${value.message}`;
|
|
73
|
+
}
|
|
74
|
+
return value;
|
|
75
|
+
});
|
|
76
|
+
if (stringified === '{}') {
|
|
77
|
+
const keys = Object.getOwnPropertyNames(arg);
|
|
78
|
+
if (keys.length > 0) {
|
|
79
|
+
const props = {};
|
|
80
|
+
keys.forEach((key) => {
|
|
81
|
+
try {
|
|
82
|
+
const value = arg[key];
|
|
83
|
+
if (value instanceof Error) {
|
|
84
|
+
props[key] = `${value.name}: ${value.message}`;
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
props[key] = value;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
catch {
|
|
91
|
+
props[key] = '[unable to access]';
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
return JSON.stringify(props);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return stringified;
|
|
98
|
+
}
|
|
99
|
+
catch {
|
|
100
|
+
return String(arg);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return String(arg);
|
|
104
|
+
}
|
|
105
|
+
debug(...args) {
|
|
106
|
+
if (this.shouldLog('debug')) {
|
|
107
|
+
console.log(this.formatMessage('debug', ...args));
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
info(...args) {
|
|
111
|
+
if (this.shouldLog('info')) {
|
|
112
|
+
console.log(this.formatMessage('info', ...args));
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
warn(...args) {
|
|
116
|
+
if (this.shouldLog('warn')) {
|
|
117
|
+
console.warn(this.formatMessage('warn', ...args));
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
error(...args) {
|
|
121
|
+
if (this.shouldLog('error')) {
|
|
122
|
+
console.error(this.formatMessage('error', ...args));
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
trace(...args) {
|
|
126
|
+
if (this.shouldLog('trace')) {
|
|
127
|
+
console.trace(this.formatMessage('trace', ...args));
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
var name = "@tvlabs/wdio-service";
|
|
133
|
+
var version = "0.1.5";
|
|
134
|
+
var packageJson = {
|
|
135
|
+
name: name,
|
|
136
|
+
version: version};
|
|
137
|
+
|
|
138
|
+
function getServiceInfo() {
|
|
139
|
+
return {
|
|
140
|
+
service_name: getServiceName(),
|
|
141
|
+
service_version: getServiceVersion(),
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
function getServiceVersion() {
|
|
145
|
+
return packageJson.version;
|
|
146
|
+
}
|
|
147
|
+
function getServiceName() {
|
|
148
|
+
return packageJson.name;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
class TVLabsChannel {
|
|
152
|
+
endpoint;
|
|
153
|
+
maxReconnectRetries;
|
|
154
|
+
key;
|
|
155
|
+
logLevel;
|
|
156
|
+
socket;
|
|
157
|
+
lobbyTopic;
|
|
158
|
+
requestTopic;
|
|
159
|
+
log;
|
|
160
|
+
events = {
|
|
161
|
+
SESSION_READY: 'session:ready',
|
|
162
|
+
SESSION_FAILED: 'session:failed',
|
|
163
|
+
REQUEST_CANCELED: 'request:canceled',
|
|
164
|
+
REQUEST_FAILED: 'request:failed',
|
|
165
|
+
REQUEST_FILLED: 'request:filled',
|
|
166
|
+
REQUEST_MATCHING: 'request:matching',
|
|
167
|
+
};
|
|
168
|
+
constructor(endpoint, maxReconnectRetries, key, logLevel = 'info') {
|
|
169
|
+
this.endpoint = endpoint;
|
|
170
|
+
this.maxReconnectRetries = maxReconnectRetries;
|
|
171
|
+
this.key = key;
|
|
172
|
+
this.logLevel = logLevel;
|
|
173
|
+
this.log = new Logger('@tvlabs/wdio-channel', this.logLevel);
|
|
174
|
+
this.socket = new phoenix.Socket(this.endpoint, {
|
|
175
|
+
transport: ws.WebSocket,
|
|
176
|
+
params: this.params(),
|
|
177
|
+
reconnectAfterMs: this.reconnectAfterMs.bind(this),
|
|
178
|
+
});
|
|
179
|
+
this.socket.onError((...args) => TVLabsChannel.logSocketError(this.log, ...args));
|
|
180
|
+
this.lobbyTopic = this.socket.channel('requests:lobby');
|
|
181
|
+
}
|
|
182
|
+
async disconnect() {
|
|
183
|
+
return new Promise((res, _rej) => {
|
|
184
|
+
this.lobbyTopic.leave();
|
|
185
|
+
this.requestTopic?.leave();
|
|
186
|
+
this.socket.disconnect(() => res());
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
async connect() {
|
|
190
|
+
try {
|
|
191
|
+
this.log.debug('Connecting to TV Labs...');
|
|
192
|
+
this.socket.connect();
|
|
193
|
+
await this.join(this.lobbyTopic);
|
|
194
|
+
this.log.debug('Connected to TV Labs!');
|
|
195
|
+
}
|
|
196
|
+
catch (error) {
|
|
197
|
+
this.log.error('Error connecting to TV Labs:', error);
|
|
198
|
+
throw new webdriverio.SevereServiceError('Could not connect to TV Labs, please check your connection.');
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
async newSession(capabilities, maxRetries, retry = 0) {
|
|
202
|
+
try {
|
|
203
|
+
const requestId = await this.requestSession(capabilities);
|
|
204
|
+
const sessionId = await this.observeRequest(requestId);
|
|
205
|
+
return sessionId;
|
|
206
|
+
}
|
|
207
|
+
catch {
|
|
208
|
+
return this.handleRetry(capabilities, maxRetries, retry);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
async handleRetry(capabilities, maxRetries, retry) {
|
|
212
|
+
if (retry < maxRetries) {
|
|
213
|
+
this.log.warn(`Could not create a session, retrying (${retry + 1}/${maxRetries})`);
|
|
214
|
+
return this.newSession(capabilities, maxRetries, retry + 1);
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
throw new webdriverio.SevereServiceError(`Could not create a session after ${maxRetries} attempts.`);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
async observeRequest(requestId) {
|
|
221
|
+
const cleanup = () => this.unobserveRequest();
|
|
222
|
+
return new Promise((res, rej) => {
|
|
223
|
+
this.requestTopic = this.socket.channel(`requests:${requestId}`);
|
|
224
|
+
const eventHandlers = {
|
|
225
|
+
[this.events.REQUEST_MATCHING]: ({ request_id }) => {
|
|
226
|
+
this.log.info(`Session request ${request_id} matching...`);
|
|
227
|
+
},
|
|
228
|
+
[this.events.REQUEST_FILLED]: ({ session_id, request_id }) => {
|
|
229
|
+
this.log.info(`Session request ${request_id} filled: ${this.tvlabsSessionLink(session_id)}`);
|
|
230
|
+
this.log.info('Waiting for device to be ready...');
|
|
231
|
+
},
|
|
232
|
+
[this.events.SESSION_FAILED]: ({ session_id, reason }) => {
|
|
233
|
+
this.log.error(`Session ${session_id} failed, reason: ${reason}`);
|
|
234
|
+
rej(reason);
|
|
235
|
+
},
|
|
236
|
+
[this.events.REQUEST_CANCELED]: ({ request_id, reason }) => {
|
|
237
|
+
this.log.info(`Session request ${request_id} canceled, reason: ${reason}`);
|
|
238
|
+
rej(reason);
|
|
239
|
+
},
|
|
240
|
+
[this.events.REQUEST_FAILED]: ({ request_id, reason }) => {
|
|
241
|
+
this.log.info(`Session request ${request_id} failed, reason: ${reason}`);
|
|
242
|
+
rej(reason);
|
|
243
|
+
},
|
|
244
|
+
[this.events.SESSION_READY]: ({ session_id }) => {
|
|
245
|
+
this.log.info(`Session ${session_id} ready!`);
|
|
246
|
+
res(session_id);
|
|
247
|
+
},
|
|
248
|
+
};
|
|
249
|
+
Object.entries(eventHandlers).forEach(([event, handler]) => {
|
|
250
|
+
this.requestTopic?.on(event, handler);
|
|
251
|
+
});
|
|
252
|
+
this.join(this.requestTopic).catch((err) => {
|
|
253
|
+
rej(err);
|
|
254
|
+
});
|
|
255
|
+
}).finally(cleanup);
|
|
256
|
+
}
|
|
257
|
+
unobserveRequest() {
|
|
258
|
+
Object.values(this.events).forEach((event) => {
|
|
259
|
+
this.requestTopic?.off(event);
|
|
260
|
+
});
|
|
261
|
+
this.requestTopic?.leave();
|
|
262
|
+
this.requestTopic = undefined;
|
|
263
|
+
}
|
|
264
|
+
async requestSession(capabilities) {
|
|
265
|
+
this.log.info('Requesting TV Labs session');
|
|
266
|
+
try {
|
|
267
|
+
const response = await this.push(this.lobbyTopic, 'requests:create', { capabilities });
|
|
268
|
+
this.log.info(`Received session request ID: ${response.request_id}. Waiting for a match...`);
|
|
269
|
+
return response.request_id;
|
|
270
|
+
}
|
|
271
|
+
catch (error) {
|
|
272
|
+
this.log.error('Error requesting session:', error);
|
|
273
|
+
throw error;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
async join(topic) {
|
|
277
|
+
return new Promise((res, rej) => {
|
|
278
|
+
topic
|
|
279
|
+
.join()
|
|
280
|
+
.receive('ok', (_resp) => {
|
|
281
|
+
res();
|
|
282
|
+
})
|
|
283
|
+
.receive('error', ({ response }) => {
|
|
284
|
+
rej('Failed to join topic: ' + response);
|
|
285
|
+
})
|
|
286
|
+
.receive('timeout', () => {
|
|
287
|
+
rej('timeout');
|
|
288
|
+
});
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
async push(topic, event, payload) {
|
|
292
|
+
return new Promise((res, rej) => {
|
|
293
|
+
topic
|
|
294
|
+
.push(event, payload)
|
|
295
|
+
.receive('ok', (msg) => {
|
|
296
|
+
res(msg);
|
|
297
|
+
})
|
|
298
|
+
.receive('error', (reason) => {
|
|
299
|
+
rej(reason);
|
|
300
|
+
})
|
|
301
|
+
.receive('timeout', () => {
|
|
302
|
+
rej('timeout');
|
|
303
|
+
});
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
params() {
|
|
307
|
+
const serviceInfo = getServiceInfo();
|
|
308
|
+
this.log.debug('Info:', serviceInfo);
|
|
309
|
+
return {
|
|
310
|
+
...serviceInfo,
|
|
311
|
+
api_key: this.key,
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
reconnectAfterMs(tries) {
|
|
315
|
+
if (tries > this.maxReconnectRetries) {
|
|
316
|
+
throw new webdriverio.SevereServiceError('Could not connect to TV Labs, please check your connection.');
|
|
317
|
+
}
|
|
318
|
+
const wait = [0, 1000, 3000, 5000][tries] || 10000;
|
|
319
|
+
this.log.info(`[${tries}/${this.maxReconnectRetries}] Waiting ${wait}ms before re-attempting to connect...`);
|
|
320
|
+
return wait;
|
|
321
|
+
}
|
|
322
|
+
tvlabsSessionLink(sessionId) {
|
|
323
|
+
return `https://tvlabs.ai/app/sessions/${sessionId}`;
|
|
324
|
+
}
|
|
325
|
+
static logSocketError(log, event, _transport, _establishedConnections) {
|
|
326
|
+
log.error('Socket error:', event.error);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
class TVLabsService {
|
|
331
|
+
_options;
|
|
332
|
+
_capabilities;
|
|
333
|
+
_config;
|
|
334
|
+
log;
|
|
335
|
+
constructor(_options, _capabilities, _config) {
|
|
336
|
+
this._options = _options;
|
|
337
|
+
this._capabilities = _capabilities;
|
|
338
|
+
this._config = _config;
|
|
339
|
+
this.log = new Logger('@tvlabs/wdio-server', this._config.logLevel);
|
|
340
|
+
if (this.attachRequestId()) {
|
|
341
|
+
this.setupRequestId();
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
onPrepare(_config, param) {
|
|
345
|
+
if (!Array.isArray(param)) {
|
|
346
|
+
throw new webdriverio.SevereServiceError('Multi-remote capabilities are not implemented. Contact TV Labs support if you are interested in this feature.');
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
async beforeSession(_config, capabilities, _specs, _cid) {
|
|
350
|
+
const channel = new TVLabsChannel(this.endpoint(), this.reconnectRetries(), this.apiKey(), this.logLevel());
|
|
351
|
+
await channel.connect();
|
|
352
|
+
capabilities['tvlabs:session_id'] = await channel.newSession(capabilities, this.retries());
|
|
353
|
+
await channel.disconnect();
|
|
354
|
+
}
|
|
355
|
+
setupRequestId() {
|
|
356
|
+
const originalTransformRequest = this._config.transformRequest;
|
|
357
|
+
this._config.transformRequest = (requestOptions) => {
|
|
358
|
+
const requestId = crypto__namespace.randomUUID();
|
|
359
|
+
const originalRequestOptions = typeof originalTransformRequest === 'function'
|
|
360
|
+
? originalTransformRequest(requestOptions)
|
|
361
|
+
: requestOptions;
|
|
362
|
+
if (typeof originalRequestOptions.headers === 'undefined') {
|
|
363
|
+
originalRequestOptions.headers = {};
|
|
364
|
+
}
|
|
365
|
+
this.setRequestHeader(originalRequestOptions.headers, 'x-request-id', requestId);
|
|
366
|
+
this.log.info('ATTACHED REQUEST ID', requestId);
|
|
367
|
+
return originalRequestOptions;
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
setRequestHeader(headers, header, value) {
|
|
371
|
+
if (headers instanceof Headers) {
|
|
372
|
+
headers.set(header, value);
|
|
373
|
+
}
|
|
374
|
+
else if (typeof headers === 'object') {
|
|
375
|
+
if (Array.isArray(headers)) {
|
|
376
|
+
headers.push([header, value]);
|
|
377
|
+
}
|
|
378
|
+
else {
|
|
379
|
+
headers[header] = value;
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
endpoint() {
|
|
384
|
+
return this._options.endpoint ?? 'wss://tvlabs.ai/appium';
|
|
385
|
+
}
|
|
386
|
+
retries() {
|
|
387
|
+
return this._options.retries ?? 3;
|
|
388
|
+
}
|
|
389
|
+
apiKey() {
|
|
390
|
+
return this._options.apiKey;
|
|
391
|
+
}
|
|
392
|
+
logLevel() {
|
|
393
|
+
return this._config.logLevel ?? 'info';
|
|
394
|
+
}
|
|
395
|
+
attachRequestId() {
|
|
396
|
+
return this._options.attachRequestId ?? true;
|
|
397
|
+
}
|
|
398
|
+
reconnectRetries() {
|
|
399
|
+
return this._options.reconnectRetries ?? 5;
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
exports.TVLabsService = TVLabsService;
|
|
404
|
+
exports.default = TVLabsService;
|
package/cjs/logger.d.ts
CHANGED
package/cjs/logger.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAc3C,qBAAa,MAAM;IAEf,OAAO,CAAC,IAAI;IACZ,OAAO,CAAC,QAAQ;gBADR,IAAI,EAAE,MAAM,EACZ,QAAQ,GAAE,QAAiB;IAGrC,OAAO,CAAC,SAAS;IAOjB,OAAO,CAAC,aAAa;
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAc3C,qBAAa,MAAM;IAEf,OAAO,CAAC,IAAI;IACZ,OAAO,CAAC,QAAQ;gBADR,IAAI,EAAE,MAAM,EACZ,QAAQ,GAAE,QAAiB;IAGrC,OAAO,CAAC,SAAS;IAOjB,OAAO,CAAC,aAAa;IAOrB,OAAO,CAAC,YAAY;IA2DpB,KAAK,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IAM/B,IAAI,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IAM9B,IAAI,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IAM9B,KAAK,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IAM/B,KAAK,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;CAKhC"}
|
package/cjs/package.json
CHANGED
package/cjs/types.d.ts
CHANGED
|
@@ -31,7 +31,11 @@ export type TVLabsSessionRequestUpdate = {
|
|
|
31
31
|
export type TVLabsSessionRequestResponse = {
|
|
32
32
|
request_id: string;
|
|
33
33
|
};
|
|
34
|
-
export type
|
|
34
|
+
export type TVLabsSocketParams = TVLabsServiceInfo & {
|
|
35
35
|
api_key: string;
|
|
36
36
|
};
|
|
37
|
+
export type TVLabsServiceInfo = {
|
|
38
|
+
service_version: string;
|
|
39
|
+
service_name: string;
|
|
40
|
+
};
|
|
37
41
|
//# sourceMappingURL=types.d.ts.map
|
package/cjs/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,OAAO,GAAG,QAAQ,CAAC;AAEhF,MAAM,MAAM,oBAAoB,GAAG;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAC5B,YAAY,CAAC,+BAA+B,GAAG;IAC7C,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,oBAAoB,CAAC,EAAE;QACrB,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,kCAAkC,CAAC,EAAE,MAAM,CAAC;QAC5C,qBAAqB,CAAC,EAAE,OAAO,CAAC;KACjC,CAAC;IACF,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,uBAAuB,CAAC,EAAE,MAAM,CAAC;CAClC,CAAC;AAEJ,MAAM,MAAM,gCAAgC,GAAG,CAC7C,QAAQ,EAAE,0BAA0B,KACjC,IAAI,CAAC;AAEV,MAAM,MAAM,0BAA0B,GAAG;IACvC,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,4BAA4B,GAAG;IACzC,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,OAAO,GAAG,QAAQ,CAAC;AAEhF,MAAM,MAAM,oBAAoB,GAAG;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAC5B,YAAY,CAAC,+BAA+B,GAAG;IAC7C,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,oBAAoB,CAAC,EAAE;QACrB,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,kCAAkC,CAAC,EAAE,MAAM,CAAC;QAC5C,qBAAqB,CAAC,EAAE,OAAO,CAAC;KACjC,CAAC;IACF,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,uBAAuB,CAAC,EAAE,MAAM,CAAC;CAClC,CAAC;AAEJ,MAAM,MAAM,gCAAgC,GAAG,CAC7C,QAAQ,EAAE,0BAA0B,KACjC,IAAI,CAAC;AAEV,MAAM,MAAM,0BAA0B,GAAG;IACvC,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,4BAA4B,GAAG;IACzC,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG,iBAAiB,GAAG;IACnD,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,eAAe,EAAE,MAAM,CAAC;IACxB,YAAY,EAAE,MAAM,CAAC;CACtB,CAAC"}
|
package/cjs/utils.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAG/C,wBAAgB,cAAc,IAAI,iBAAiB,CAKlD;AAED,wBAAgB,iBAAiB,IAAI,MAAM,CAE1C;AAED,wBAAgB,cAAc,IAAI,MAAM,CAEvC"}
|
package/esm/channel.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export declare class TVLabsChannel {
|
|
|
9
9
|
private requestTopic?;
|
|
10
10
|
private log;
|
|
11
11
|
private readonly events;
|
|
12
|
-
constructor(endpoint: string, maxReconnectRetries: number, key: string, logLevel
|
|
12
|
+
constructor(endpoint: string, maxReconnectRetries: number, key: string, logLevel?: LogLevel);
|
|
13
13
|
disconnect(): Promise<void>;
|
|
14
14
|
connect(): Promise<void>;
|
|
15
15
|
newSession(capabilities: TVLabsCapabilities, maxRetries: number, retry?: number): Promise<string>;
|
package/esm/channel.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"channel.d.ts","sourceRoot":"","sources":["../src/channel.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"channel.d.ts","sourceRoot":"","sources":["../src/channel.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACV,kBAAkB,EAIlB,QAAQ,EACT,MAAM,YAAY,CAAC;AAGpB,qBAAa,aAAa;IAgBtB,OAAO,CAAC,QAAQ;IAChB,OAAO,CAAC,mBAAmB;IAC3B,OAAO,CAAC,GAAG;IACX,OAAO,CAAC,QAAQ;IAlBlB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,UAAU,CAAU;IAC5B,OAAO,CAAC,YAAY,CAAC,CAAU;IAC/B,OAAO,CAAC,GAAG,CAAS;IAEpB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAOZ;gBAGD,QAAQ,EAAE,MAAM,EAChB,mBAAmB,EAAE,MAAM,EAC3B,GAAG,EAAE,MAAM,EACX,QAAQ,GAAE,QAAiB;IAgB/B,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAQ3B,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAiBxB,UAAU,CACd,YAAY,EAAE,kBAAkB,EAChC,UAAU,EAAE,MAAM,EAClB,KAAK,SAAI,GACR,OAAO,CAAC,MAAM,CAAC;YAWJ,WAAW;YAkBX,cAAc;IAsD5B,OAAO,CAAC,gBAAgB;YAUV,cAAc;YAuBd,IAAI;YAgBJ,IAAI;IAoBlB,OAAO,CAAC,MAAM;IAWd,OAAO,CAAC,gBAAgB;IAgBxB,OAAO,CAAC,iBAAiB;IAIzB,OAAO,CAAC,MAAM,CAAC,cAAc;CAQ9B"}
|