mirror of
https://github.com/ragestudio/linebridge.git
synced 2025-06-09 02:24:17 +00:00
support disabled websocket
This commit is contained in:
parent
153ebcf4cc
commit
bbc419bcda
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "linebridge",
|
||||
"version": "0.18.6",
|
||||
"version": "0.17.0",
|
||||
"description": "API Framework for RageStudio backends",
|
||||
"author": "RageStudio",
|
||||
"main": "./dist/client/index.js",
|
||||
|
@ -18,10 +18,6 @@ export default class Engine {
|
||||
ws = null
|
||||
|
||||
init = async (params) => {
|
||||
this.io = new SocketIO.Server({
|
||||
path: `/${params.refName}`,
|
||||
})
|
||||
|
||||
// register 404
|
||||
await this.router.any("*", (req, res) => {
|
||||
return res.status(404).json({
|
||||
@ -40,13 +36,19 @@ export default class Engine {
|
||||
}
|
||||
})
|
||||
|
||||
this.io.attachApp(this.app.uws_instance)
|
||||
if (!params.disableWebSockets) {
|
||||
this.io = new SocketIO.Server({
|
||||
path: `/${params.refName}`,
|
||||
})
|
||||
|
||||
this.ws = global.rtengine = new rtengine({
|
||||
...params,
|
||||
handleAuth: params.handleWsAuth,
|
||||
io: this.io,
|
||||
})
|
||||
this.io.attachApp(this.app.uws_instance)
|
||||
|
||||
this.ws = global.rtengine = new rtengine({
|
||||
...params,
|
||||
handleAuth: params.handleWsAuth,
|
||||
io: this.io,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
listen = async (params) => {
|
||||
@ -67,40 +69,47 @@ export default class Engine {
|
||||
return true
|
||||
})
|
||||
|
||||
process.send({
|
||||
type: "router:ws:register",
|
||||
id: process.env.lb_service.id,
|
||||
index: process.env.lb_service.index,
|
||||
data: {
|
||||
namespace: params.refName,
|
||||
listen: {
|
||||
ip: this.params.listen_ip,
|
||||
port: this.params.listen_port,
|
||||
},
|
||||
}
|
||||
})
|
||||
if (!params.disableWebSockets) {
|
||||
process.send({
|
||||
type: "router:ws:register",
|
||||
id: process.env.lb_service.id,
|
||||
index: process.env.lb_service.index,
|
||||
data: {
|
||||
namespace: params.refName,
|
||||
listen: {
|
||||
ip: this.params.listen_ip,
|
||||
port: this.params.listen_port,
|
||||
},
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// try to send router map to host
|
||||
process.send({
|
||||
type: "router:register",
|
||||
id: process.env.lb_service.id,
|
||||
index: process.env.lb_service.index,
|
||||
data: {
|
||||
router_map: this.router.map,
|
||||
path_overrides: pathOverrides,
|
||||
listen: {
|
||||
ip: this.params.listen_ip,
|
||||
port: this.params.listen_port,
|
||||
},
|
||||
}
|
||||
})
|
||||
if (process.send) {
|
||||
// try to send router map to host
|
||||
process.send({
|
||||
type: "router:register",
|
||||
id: process.env.lb_service.id,
|
||||
index: process.env.lb_service.index,
|
||||
data: {
|
||||
router_map: this.router.map,
|
||||
path_overrides: pathOverrides,
|
||||
listen: {
|
||||
ip: this.params.listen_ip,
|
||||
port: this.params.listen_port,
|
||||
},
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
await this.app.listen(this.params.listen_port)
|
||||
}
|
||||
|
||||
close = async () => {
|
||||
this.io.close()
|
||||
if (this.io) {
|
||||
this.io.close()
|
||||
}
|
||||
|
||||
await this.app.close()
|
||||
}
|
||||
}
|
@ -58,6 +58,7 @@ class Server {
|
||||
this.params.listen_port = this.constructor.listenPort ?? this.constructor.listen_port ?? this.params.listen_port ?? 3000
|
||||
this.params.http_protocol = this.params.http_protocol ?? "http"
|
||||
this.params.http_address = `${this.params.http_protocol}://${defaults.localhost_address}:${this.params.listen_port}`
|
||||
this.params.disableWebSockets = this.constructor.disableWebSockets ?? this.params.disableWebSockets ?? false
|
||||
|
||||
this.params.routesPath = this.constructor.routesPath ?? this.params.routesPath
|
||||
this.params.wsRoutesPath = this.constructor.wsRoutesPath ?? this.params.wsRoutesPath
|
||||
@ -135,10 +136,12 @@ class Server {
|
||||
await this.engine.app.use(this.engine.router)
|
||||
|
||||
// initialize websocket init hook if needed
|
||||
if (typeof this.engine.ws?.initialize == "function") {
|
||||
await this.engine.ws.initialize({
|
||||
redisInstance: this.redis
|
||||
})
|
||||
if (this.engine.ws) {
|
||||
if (typeof this.engine.ws?.initialize == "function") {
|
||||
await this.engine.ws.initialize({
|
||||
redisInstance: this.redis
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// if is a linebridge service then initialize IPC Channels
|
||||
|
Loading…
x
Reference in New Issue
Block a user