Path: blob/trunk/javascript/grid-ui/src/models/session-data.ts
2884 views
/*1* Licensed to the Software Freedom Conservancy (SFC) under one2* or more contributor license agreements. See the NOTICE file3* distributed with this work for additional information4* regarding copyright ownership. The SFC licenses this file5* to you under the Apache License, Version 2.0 (the6* "License"); you may not use this file except in compliance7* with the License. You may obtain a copy of the License at8*9* http://www.apache.org/licenses/LICENSE-2.010*11* Unless required by applicable law or agreed to in writing,12* software distributed under the License is distributed on an13* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY14* KIND, either express or implied. See the License for the15* specific language governing permissions and limitations16* under the License.17*/1819import Capabilities from './capabilities'2021interface SessionData {22id: string23capabilities: string24browserName: string25browserVersion: string26platformName: string27startTime: string28uri: string29nodeId: string30nodeUri: string31sessionDurationMillis: number32slot: any33vnc: string34name: string35[key: string]: any36}3738export function createSessionData (39id: string,40capabilities: string,41startTime: string,42uri: string,43nodeId: string,44nodeUri: string,45sessionDurationMillis: number,46slot: any,47origin: string48): SessionData {49const parsed = JSON.parse(capabilities) as Capabilities50const browserName = parsed.browserName51const browserVersion = parsed.browserVersion ?? parsed.version52const platformName = parsed.platformName ?? parsed.platform53let vnc: string = parsed['se:vnc'] ?? ''54if (vnc.length > 0) {55try {56const url = new URL(origin)57const vncUrl = new URL(vnc)58url.pathname = vncUrl.pathname59url.protocol = url.protocol === 'https:' ? 'wss:' : 'ws:'60vnc = url.href61} catch (error) {62console.log(error)63}64}65const name: string = parsed['se:name'] ?? id66return {67id,68capabilities,69browserName,70browserVersion,71platformName,72startTime,73uri,74nodeId,75nodeUri,76sessionDurationMillis,77slot,78vnc,79name80}81}8283export default SessionData848586