Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
seleniumhq
GitHub Repository: seleniumhq/selenium
Path: blob/trunk/javascript/grid-ui/src/models/session-data.ts
2884 views
1
/*
2
* Licensed to the Software Freedom Conservancy (SFC) under one
3
* or more contributor license agreements. See the NOTICE file
4
* distributed with this work for additional information
5
* regarding copyright ownership. The SFC licenses this file
6
* to you under the Apache License, Version 2.0 (the
7
* "License"); you may not use this file except in compliance
8
* with the License. You may obtain a copy of the License at
9
*
10
* http://www.apache.org/licenses/LICENSE-2.0
11
*
12
* Unless required by applicable law or agreed to in writing,
13
* software distributed under the License is distributed on an
14
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
* KIND, either express or implied. See the License for the
16
* specific language governing permissions and limitations
17
* under the License.
18
*/
19
20
import Capabilities from './capabilities'
21
22
interface SessionData {
23
id: string
24
capabilities: string
25
browserName: string
26
browserVersion: string
27
platformName: string
28
startTime: string
29
uri: string
30
nodeId: string
31
nodeUri: string
32
sessionDurationMillis: number
33
slot: any
34
vnc: string
35
name: string
36
[key: string]: any
37
}
38
39
export function createSessionData (
40
id: string,
41
capabilities: string,
42
startTime: string,
43
uri: string,
44
nodeId: string,
45
nodeUri: string,
46
sessionDurationMillis: number,
47
slot: any,
48
origin: string
49
): SessionData {
50
const parsed = JSON.parse(capabilities) as Capabilities
51
const browserName = parsed.browserName
52
const browserVersion = parsed.browserVersion ?? parsed.version
53
const platformName = parsed.platformName ?? parsed.platform
54
let vnc: string = parsed['se:vnc'] ?? ''
55
if (vnc.length > 0) {
56
try {
57
const url = new URL(origin)
58
const vncUrl = new URL(vnc)
59
url.pathname = vncUrl.pathname
60
url.protocol = url.protocol === 'https:' ? 'wss:' : 'ws:'
61
vnc = url.href
62
} catch (error) {
63
console.log(error)
64
}
65
}
66
const name: string = parsed['se:name'] ?? id
67
return {
68
id,
69
capabilities,
70
browserName,
71
browserVersion,
72
platformName,
73
startTime,
74
uri,
75
nodeId,
76
nodeUri,
77
sessionDurationMillis,
78
slot,
79
vnc,
80
name
81
}
82
}
83
84
export default SessionData
85
86