|
function isSecure(wsComponents) { |
|
return typeof wsComponents.secure === 'boolean' ? wsComponents.secure : String(wsComponents.scheme).toLowerCase() === "wss"; |
|
} |
|
|
|
const handler = { |
|
scheme: "ws", |
|
domainHost: true, |
|
parse: function (components, options) { |
|
const wsComponents = components; |
|
|
|
wsComponents.secure = isSecure(wsComponents); |
|
|
|
wsComponents.resourceName = (wsComponents.path || '/') + (wsComponents.query ? '?' + wsComponents.query : ''); |
|
wsComponents.path = undefined; |
|
wsComponents.query = undefined; |
|
return wsComponents; |
|
}, |
|
serialize: function (wsComponents, options) { |
|
|
|
if (wsComponents.port === (isSecure(wsComponents) ? 443 : 80) || wsComponents.port === "") { |
|
wsComponents.port = undefined; |
|
} |
|
|
|
if (typeof wsComponents.secure === 'boolean') { |
|
wsComponents.scheme = (wsComponents.secure ? 'wss' : 'ws'); |
|
wsComponents.secure = undefined; |
|
} |
|
|
|
if (wsComponents.resourceName) { |
|
const [path, query] = wsComponents.resourceName.split('?'); |
|
wsComponents.path = (path && path !== '/' ? path : undefined); |
|
wsComponents.query = query; |
|
wsComponents.resourceName = undefined; |
|
} |
|
|
|
wsComponents.fragment = undefined; |
|
return wsComponents; |
|
} |
|
}; |
|
export default handler; |
|
|