1 import { Protocol
, ProtocolVersion
} from
'../../types/UIProtocol';
3 import { IncomingMessage
} from
'http';
4 import Utils from
'../../utils/Utils';
5 import logger from
'../../utils/Logger';
7 export class UIServiceUtils
{
8 public static handleProtocols
= (protocols
: Set
<string>, request
: IncomingMessage
): string | false => {
9 let protocolIndex
: number;
10 let protocol
: Protocol
;
11 let version
: ProtocolVersion
;
12 for (const fullProtocol
of protocols
) {
13 protocolIndex
= fullProtocol
.indexOf(Protocol
.UI
);
14 protocol
= fullProtocol
.substring(protocolIndex
, protocolIndex
+ Protocol
.UI
.length
) as Protocol
;
15 version
= fullProtocol
.substring(protocolIndex
+ Protocol
.UI
.length
) as ProtocolVersion
;
16 if (Object.values(Protocol
).includes(protocol
) && Object.values(ProtocolVersion
).includes(version
)) {
20 logger
.error(`${Utils.logPrefix(' UI WebSocket Server:')} Unsupported protocol: ${protocol} or protocol version: ${version}`);