Revert "feat(ocpp): 添加对WebSocket子协议的支持和缺失参数检查"
This reverts commit 216a8e118d.
This commit is contained in:
@@ -92,26 +92,6 @@ function sendCallError(
|
||||
)
|
||||
}
|
||||
|
||||
function pickOcppSubprotocol(
|
||||
negotiatedProtocol?: string | null,
|
||||
requestedHeader?: string | null,
|
||||
) {
|
||||
if (negotiatedProtocol && isSupportedOCPP(negotiatedProtocol)) {
|
||||
return negotiatedProtocol
|
||||
}
|
||||
|
||||
if (!requestedHeader) {
|
||||
return null
|
||||
}
|
||||
|
||||
const requestedProtocols = requestedHeader
|
||||
.split(',')
|
||||
.map((value) => value.trim())
|
||||
.filter(Boolean)
|
||||
|
||||
return requestedProtocols.find((protocol) => isSupportedOCPP(protocol)) ?? null
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory that produces a hono-ws event handler object for a single
|
||||
* OCPP WebSocket connection.
|
||||
@@ -119,11 +99,7 @@ function pickOcppSubprotocol(
|
||||
* Usage in route:
|
||||
* upgradeWebSocket((c) => createOcppHandler(c.req.param('chargePointId'), remoteAddr))
|
||||
*/
|
||||
export function createOcppHandler(
|
||||
chargePointIdentifier: string,
|
||||
remoteAddr?: string,
|
||||
requestedProtocolHeader?: string,
|
||||
) {
|
||||
export function createOcppHandler(chargePointIdentifier: string, remoteAddr?: string) {
|
||||
const ctx: OcppConnectionContext = {
|
||||
chargePointIdentifier,
|
||||
isRegistered: false,
|
||||
@@ -131,14 +107,14 @@ export function createOcppHandler(
|
||||
|
||||
return {
|
||||
onOpen(_evt: Event, ws: WSContext) {
|
||||
const subProtocol = pickOcppSubprotocol(ws.protocol, requestedProtocolHeader)
|
||||
if (!subProtocol) {
|
||||
const subProtocol = ws.protocol ?? 'unknown'
|
||||
if (!isSupportedOCPP(subProtocol)) {
|
||||
ws.close(1002, 'Unsupported subprotocol')
|
||||
return
|
||||
}
|
||||
ocppConnections.set(chargePointIdentifier, ws)
|
||||
console.log(
|
||||
`[OCPP] ${chargePointIdentifier} connected (${subProtocol})` +
|
||||
`[OCPP] ${chargePointIdentifier} connected` +
|
||||
(remoteAddr ? ` from ${remoteAddr}` : ''),
|
||||
)
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user