Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The 2020-03 changes #90

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/config/passport.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import passport from 'passport'
import { ExtractJwt, Strategy } from 'passport-jwt'
import User from '../models/user'

import { handleError, UserBanned, UserNoAuth } from '../utils/errors.utils'
import { handleError, UserBanned, UserNoAuth, UserNotAllowed } from '../utils/errors.utils'

passport.serializeUser((user, done) => done(null, user))
passport.deserializeUser((id, done) => done(null, id))
Expand All @@ -20,7 +20,7 @@ passport.use(new Strategy({

return done(null, user)
} catch (error) {
if (error.response.indexOf(noSessionResponses))
if (error.response && error.response.indexOf(noSessionResponses))
return done(UserNoAuth)

done(error)
Expand Down Expand Up @@ -71,7 +71,7 @@ export const authenticate = async (req: Request, res: Response, next: NextFuncti
return handleError(UserBanned, res)

if (req.baseUrl === '/admin' && user.roles.indexOf('admin') === -1)
return handleError(UserNoAuth, res)
return handleError(UserNotAllowed, res)

req.user = user

Expand Down
20 changes: 9 additions & 11 deletions src/controllers/internal.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ app.put('/portal', authenticate, async (req, res) => {

try {
const doc = await StoredRoom.findOne({ 'info.portal.id': id })
if(!doc)
if (!doc)
return RoomNotFound

//console.log('room found, updating status...')
Expand All @@ -48,24 +48,22 @@ app.put('/portal', authenticate, async (req, res) => {

//console.log('status updated and online members fetched:', online)

if(online.length > 0) {
if (online.length > 0) {
/**
* Broadcast allocation to all online clients
*/
const updateMessage = new WSMessage(0, allocation, 'PORTAL_UPDATE')
await updateMessage.broadcast(online)
await updateMessage.broadcastRoom(room)

if(status === 'open') {
//JanusId is -1 when a janus instance is not running.
if(allocation.janusId == -1) {
const token = signApertureToken(id),
if (status === 'open')
if (allocation.janusId) {
const token = signApertureToken(id),
apertureMessage = new WSMessage(0, { ws: process.env.APERTURE_WS_URL, t: token }, 'APERTURE_CONFIG')
await apertureMessage.broadcast(online)
await apertureMessage.broadcastRoom(room)
} else {
const janusMessage = new WSMessage(0, { id: janusId }, 'JANUS_CONFIG')
await janusMessage.broadcast(online)
const janusMessage = new WSMessage(0, { id: janusId, ip: janusIp }, 'JANUS_CONFIG')
await janusMessage.broadcastRoom(room)
}
}
}

res.sendStatus(200)
Expand Down
4 changes: 2 additions & 2 deletions src/drivers/portals.driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const createPortal = (room: Room) => new Promise(async (resolve, reject)
log(`Sending request to ${url}create with room id: ${room.id}`, [{ content: 'portals', color: 'MAGENTA' }])

await axios.post(`${url}create`, { roomId: room.id }, { headers })
.catch((reason) => {
.catch(reason => {
console.log(`AXIOS POST FAILED: ${reason}`)
throw reason
}
Expand All @@ -36,7 +36,7 @@ export const destroyPortal = (room: Room) => new Promise(async (resolve, reject)
{ portal } = room

if (!portal.id)
return
reject()

await axios.delete(`${url}${portal.id}`, { headers })

Expand Down
Loading