From a3aae340d87587ac391730f8678ac84cb830eccc Mon Sep 17 00:00:00 2001 From: srgooglo Date: Wed, 26 Oct 2022 11:31:06 +0000 Subject: [PATCH] fix bad syntax --- .../controllers/StreamingController/index.js | 146 +++++++++--------- 1 file changed, 73 insertions(+), 73 deletions(-) diff --git a/packages/server/src/controllers/StreamingController/index.js b/packages/server/src/controllers/StreamingController/index.js index eef3ec63..c3d4e9eb 100755 --- a/packages/server/src/controllers/StreamingController/index.js +++ b/packages/server/src/controllers/StreamingController/index.js @@ -277,89 +277,89 @@ export default class StreamingController extends Controller { if (info) { return res.json(info) } - }, - "/streaming/publish": async (req, res) => { - const { app, stream, tcUrl } = req.body + } + }, + "/streaming/publish": async (req, res) => { + const { app, stream, tcUrl } = req.body - const streaming = await this.methods.pushToLocalList({ - app, - stream, - tcUrl - }).catch((err) => { + const streaming = await this.methods.pushToLocalList({ + app, + stream, + tcUrl + }).catch((err) => { + res.status(500).json({ + code: 1, + error: err.message + }) + + return false + }) + + if (streaming) { + global.wsInterface.io.emit(`streaming.new`, { + username: streaming.username, + }) + + return res.json({ + code: 0, + status: "ok" + }) + } + }, + "/streaming/unpublish": async (req, res) => { + const { stream } = req.body + + const streaming = await this.methods.removeFromLocalList({ + stream + }).catch((err) => { + res.status(500).json({ + code: 2, + status: err.message + }) + + return false + }) + + if (streaming) { + global.wsInterface.io.emit(`streaming.end`, { + username: streaming.username, + }) + + return res.json({ + code: 0, + status: "ok" + }) + } + }, + "/regenerate_streaming_key": { + middlewares: ["withAuthentication"], + fn: async (req, res) => { + // check if the user already has a key + let streamingKey = await StreamingKey.findOne({ + user_id: req.user._id.toString() + }) + + // if exists, delete it + + if (streamingKey) { + await streamingKey.remove() + } + + // generate a new key + const newKey = await this.methods.genereteKey(req.user._id.toString()).catch(err => { res.status(500).json({ - code: 1, - error: err.message + error: `Cannot generate a new key: ${err.message}`, }) return false }) - if (streaming) { - global.wsInterface.io.emit(`streaming.new`, { - username: streaming.username, - }) - - return res.json({ - code: 0, - status: "ok" - }) - } - }, - "/streaming/unpublish": async (req, res) => { - const { stream } = req.body - - const streaming = await this.methods.removeFromLocalList({ - stream - }).catch((err) => { - res.status(500).json({ - code: 2, - status: err.message - }) - + if (!newKey) { return false - }) - - if (streaming) { - global.wsInterface.io.emit(`streaming.end`, { - username: streaming.username, - }) - - return res.json({ - code: 0, - status: "ok" - }) } - }, - "/regenerate_streaming_key": { - middlewares: ["withAuthentication"], - fn: async (req, res) => { - // check if the user already has a key - let streamingKey = await StreamingKey.findOne({ - user_id: req.user._id.toString() - }) - // if exists, delete it - - if (streamingKey) { - await streamingKey.remove() - } - - // generate a new key - const newKey = await this.methods.genereteKey(req.user._id.toString()).catch(err => { - res.status(500).json({ - error: `Cannot generate a new key: ${err.message}`, - }) - - return false - }) - - if (!newKey) { - return false - } - - return res.json(newKey) - } + return res.json(newKey) } } } -} +} \ No newline at end of file