mirror of
https://github.com/ragestudio/linebridge.git
synced 2025-06-09 10:34:17 +00:00
Update WebSocket config to accept an object
The `websockets` parameter can now be an object, allowing `enabled` and `path` to be specified for finer control. Server startup log now displays the WebSocket path.
This commit is contained in:
parent
bc9b82dab1
commit
8046293b3c
@ -26,19 +26,21 @@ export default class Engine {
|
||||
this.app.use(this.mainMiddleware)
|
||||
this.app.use(this.router)
|
||||
|
||||
if (this.server.params.websockets === true) {
|
||||
this.ws = new RtEngine({
|
||||
path:
|
||||
this.server.params.wsPath ??
|
||||
`/${this.server.params.refName}`,
|
||||
onUpgrade: this.server.handleWsUpgrade,
|
||||
onConnection: this.server.handleWsConnection,
|
||||
onDisconnect: this.server.handleWsDisconnect,
|
||||
})
|
||||
if (typeof this.server.params.websockets === "object") {
|
||||
const { path, enabled } = this.server.params.websockets
|
||||
|
||||
global.websockets = this.ws
|
||||
if (enabled === true) {
|
||||
this.ws = new RtEngine({
|
||||
path: path ?? `/${this.server.params.refName}`,
|
||||
onUpgrade: this.server.handleWsUpgrade,
|
||||
onConnection: this.server.handleWsConnection,
|
||||
onDisconnect: this.server.handleWsDisconnect,
|
||||
})
|
||||
|
||||
this.ws.attach(this)
|
||||
global.websockets = this.ws
|
||||
|
||||
this.ws.attach(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -72,6 +72,10 @@ class Server {
|
||||
this.params.wsRoutesPath = this.constructor.wsRoutesPath
|
||||
}
|
||||
|
||||
if (typeof this.constructor.websockets === "object") {
|
||||
this.params.websockets = this.constructor.websockets
|
||||
}
|
||||
|
||||
if (typeof this.constructor.useMiddlewares !== "undefined") {
|
||||
if (!Array.isArray(this.constructor.useMiddlewares)) {
|
||||
this.constructor.useMiddlewares = [
|
||||
@ -219,9 +223,14 @@ class Server {
|
||||
const elapsedHrTime = process.hrtime(startHrTime)
|
||||
const elapsedTimeInMs = elapsedHrTime[0] * 1e3 + elapsedHrTime[1] / 1e6
|
||||
|
||||
console.info(
|
||||
`🛰 Server ready!\n\t - ${this.hasSSL ? "https" : "http"}://${this.params.listenIp}:${this.params.listenPort} \n\t - Websocket: ${this.engine.ws ? "Enabled" : "Disabled"} \n\t - Routes: ${this.engine.map.size} \n\t - Tooks: ${elapsedTimeInMs.toFixed(2)}ms \n\t `,
|
||||
)
|
||||
const lines = [
|
||||
`- Url: ${this.hasSSL ? "https" : "http"}://${this.params.listenIp}:${this.params.listenPort}`,
|
||||
`- Websocket: ${this.engine.ws ? this.engine.ws?.config?.path : "Disabled"}`,
|
||||
`- Routes: ${this.engine.map.size}`,
|
||||
`- Tooks: ${elapsedTimeInMs.toFixed(2)}ms`,
|
||||
]
|
||||
|
||||
console.info(`🛰 Server ready!\n \t${lines.join("\n\t")} \n`)
|
||||
}
|
||||
|
||||
register = {
|
||||
|
Loading…
x
Reference in New Issue
Block a user