mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-10 02:54:15 +00:00
initialize http server
This commit is contained in:
parent
ff34d2900b
commit
27972f3f5f
@ -42,21 +42,38 @@ class StreamingServer {
|
||||
|
||||
Sessions = new SessionsManager()
|
||||
|
||||
PublicStreamings = []
|
||||
|
||||
constructor() {
|
||||
this.registerMediaServerEvents()
|
||||
this.registerHTTPServerEndpoints()
|
||||
|
||||
// fire initization
|
||||
this.initialize()
|
||||
}
|
||||
|
||||
registerMediaServerEvents = () => {
|
||||
Object.keys(this.mediaServerEvents).forEach(eventName => {
|
||||
Object.keys(this.mediaServerEvents).forEach((eventName) => {
|
||||
this.IMediaServer.on(eventName, this.mediaServerEvents[eventName])
|
||||
})
|
||||
}
|
||||
|
||||
registerHTTPServerEndpoints = () => {
|
||||
Object.keys(this.httpServerEndpoints).forEach((route) => {
|
||||
this.IHTTPServer.registerHTTPEndpoint({
|
||||
route: route,
|
||||
...this.httpServerEndpoints[route]
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
httpServerEndpoints = {
|
||||
"/streams": {
|
||||
method: "get",
|
||||
fn: async (req, res) => {
|
||||
return res.json(this.Sessions.publicStreams)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mediaServerEvents = {
|
||||
preConnect: async (id, args) => {
|
||||
// this event is fired after client is connected
|
||||
@ -77,6 +94,8 @@ class StreamingServer {
|
||||
|
||||
// stop the session
|
||||
this.Sessions.removeSession(id)
|
||||
|
||||
this.Sessions.unpublishStream(id)
|
||||
},
|
||||
prePublish: async (id, StreamPath, args) => {
|
||||
// this event is fired before client is published
|
||||
@ -87,20 +106,22 @@ class StreamingServer {
|
||||
key: streamingKey
|
||||
})
|
||||
|
||||
console.log(streamingUserspace)
|
||||
|
||||
if (!streamingUserspace) {
|
||||
this.Sessions.removeSession(id)
|
||||
return false
|
||||
}
|
||||
|
||||
PublicStreamings.push(id)
|
||||
this.Sessions.publishStream({
|
||||
id,
|
||||
user_id: streamingUserspace.user_id,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
initialize = async () => {
|
||||
await this.Db.connect()
|
||||
this.IMediaServer.run()
|
||||
this.IHTTPServer.initialize()
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user