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 Unstaged Update #145

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
5 changes: 0 additions & 5 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ PORTALS_API_URL=http://localhost:5000
# This should the same secure key in @cryb/portals/.env under 'API_KEY'
PORTALS_API_KEY=api-portals-key

# The base WS endpoint that is used to talk to @cryb/aperture which is sent to the client via WS once the stream is ready
APERTURE_WS_URL=ws://localhost:9001
# This should be the same secure key in @cryb/aperture/.env under 'APERTURE_KEY'
APERTURE_WS_KEY=api-aperture-key

# Optional: the base URL of @cryb/auth. This service usually runs on port 4500
# AUTH_BASE_URL=http://localhost:4500

Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ The following services need to be installed for `@cryb/api` to function:
We recommend that you run the following services alongside `@cryb/api`, but it's not required.

* `@cryb/portals`
* `@cryb/aperture`

You also need to install the required dependencies by running `yarn`.

Expand All @@ -92,7 +91,7 @@ Make sure that you have installed MongoDB and Redis, and they are both running l
The command to start MongoDB is `mongod`, and the command to start Redis is `redis-server`.
Most Linux distributions will have those packaged, and will start automatically with your system.

If you're developing a feature that requires the VM infrastructure, then make sure `@cryb/portals` and `@cryb/aperture` are running.
If you're developing a feature that requires the VM infrastructure, then make sure `@cryb/portals` and Janus WebRTC server are running.

#### Starting @cryb/api

Expand Down
20 changes: 6 additions & 14 deletions src/controllers/internal.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { PortalAllocationStatus } from '../models/room/defs'
import WSMessage from '../server/websocket/models/message'

import authenticate from '../server/middleware/authenticate.internal.middleware'
import { signApertureToken } from '../utils/aperture.utils'
import { handleError, RoomNotFound } from '../utils/errors.utils'

const app = express()
Expand All @@ -32,7 +31,7 @@ app.post('/portal', authenticate, async (req, res) => {
* Existing Portal Status Update
*/
app.put('/portal', authenticate, async (req, res) => {
const { id, status, janusId, janusIp } = req.body as { id: string; status: PortalAllocationStatus; janusId?: number; janusIp?: string }
const { id, status, janusId } = req.body as { id: string; status: PortalAllocationStatus; janusId?: number }
// console.log('recieved', id, status, 'from portal microservice, finding room...')

try {
Expand All @@ -43,28 +42,21 @@ app.put('/portal', authenticate, async (req, res) => {
// console.log('room found, updating status...')

const room = new Room(doc)
const { portal: allocation } = await room.updatePortalAllocation({ janusId, janusIp, status }),
const { portal: allocation } = await room.updatePortalAllocation({ janusId, status }),
{ online } = await room.fetchOnlineMemberIds()

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

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

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

Expand Down
3 changes: 1 addition & 2 deletions src/models/room/defs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ export type PortalAllocationStatus =

export interface IPortalAllocation {
id?: string
janusId?: number,
janusIp?: string,
janusId?: number,

status: PortalAllocationStatus
lastUpdatedAt?: number
Expand Down
3 changes: 1 addition & 2 deletions src/models/room/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,7 @@ export default class Room {
try {
const allocation: IPortalAllocation = {
id,
janusId: 1,
janusIp: '0.0.0.0',
janusId: -1,
status: 'creating',
lastUpdatedAt: Date.now()
}
Expand Down
1 change: 0 additions & 1 deletion src/schemas/room.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const RoomSchema = new Schema({
portal: {
id: String,
janusId: Number,
janusIp: String,

status: String,
lastUpdatedAt: String
Expand Down
1 change: 0 additions & 1 deletion src/server/websocket/models/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ type WSEventIncomingMouseEventType =

type WSEventEmittingType =
'JANUS_CONFIG' |
'APERTURE_CONFIG' |
'ROOM_DESTROY' |
'MESSAGE_CREATE' |
'MESSAGE_DESTROY' |
Expand Down
11 changes: 2 additions & 9 deletions src/server/websocket/models/socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import User from '../../../models/user'
import client from '../../../config/redis.config'

import config from '../../../config/defaults'
import { signApertureToken } from '../../../utils/aperture.utils'
import { verifyToken } from '../../../utils/generate.utils'
import { extractUserId, UNALLOCATED_PORTALS_KEYS } from '../../../utils/helpers.utils'
import log from '../../../utils/log.utils'
Expand Down Expand Up @@ -87,14 +86,8 @@ export default class WSSocket {
room.createPortal()
})
} else if (room.portal.id) {
//JanusId is -1 when a janus instance is not running.
if(room.portal.janusId == -1) {
const token = signApertureToken(room.portal.id), apertureMessage = new WSMessage(0, { ws: process.env.APERTURE_WS_URL, t: token }, 'APERTURE_CONFIG')
apertureMessage.broadcast([ extractUserId(user) ])
} else {
const janusMessage = new WSMessage(0, { id: room.portal.janusId, ip: room.portal.janusIp }, 'JANUS_CONFIG')
janusMessage.broadcast([ extractUserId(user) ])
}
const janusMessage = new WSMessage(0, { id: room.portal.janusId }, 'JANUS_CONFIG')
janusMessage.broadcast([ extractUserId(user) ])
}
}

Expand Down
3 changes: 0 additions & 3 deletions src/utils/aperture.utils.ts

This file was deleted.