Skip to content

Commit

Permalink
feat: config env vars
Browse files Browse the repository at this point in the history
  • Loading branch information
oshinongit committed Nov 28, 2023
1 parent 09983cc commit b85cebd
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 9 deletions.
12 changes: 12 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"@fastify/swagger-ui": "^1.5.0",
"@fastify/type-provider-typebox": "^2.4.0",
"@sinclair/typebox": "^0.25.24",
"dotenv": "^16.3.1",
"fastify": "4.23.2",
"nodemon": "^2.0.20",
"sdp-transform": "^2.14.1",
Expand Down
22 changes: 15 additions & 7 deletions src/api_productions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ import { SmbProtocol, SmbEndpointDescription } from './smb';
import { ProductionManager } from './production_manager';
import { Connection } from './connection';
import { write, parse } from 'sdp-transform';
import dotenv from 'dotenv';
dotenv.config();

type NewProduction = Static<typeof NewProduction>;
type Production = Static<typeof Production>;
type Line = Static<typeof Line>;

const productionManager = new ProductionManager();
const ENDPOINT_IDLE_TIMEOUT_S = 600;
const ENDPOINT_IDLE_TIMEOUT_S: string =
process.env.ENDPOINT_IDLE_TIMEOUT_S ?? '180';
const SMB_ADDRESS: string = process.env.SMB_ADDRESS ?? 'http://localhost:8080';

function generateOffer(
endpoint: SmbEndpointDescription,
Expand Down Expand Up @@ -71,7 +75,7 @@ async function createEndpoint(
endpointId,
audio,
data,
ENDPOINT_IDLE_TIMEOUT_S
parseInt(ENDPOINT_IDLE_TIMEOUT_S, 10)
);
return endpoint;
}
Expand Down Expand Up @@ -99,14 +103,18 @@ async function handleAnswerRequest(

const parsedAnswer = parse(answer);
const answerMediaDescription = parsedAnswer.media[0];
if(parsedAnswer.media[1].ssrcs) {
if (parsedAnswer.media[1].ssrcs) {
let parsedSsrcs = parsedAnswer.media[1].ssrcs[0].id;
if (typeof parsedSsrcs === "string"){
if (typeof parsedSsrcs === 'string') {
parsedSsrcs = parseInt(parsedSsrcs, 10);
}
endpointDescription.audio.ssrcs.push(parsedSsrcs)
endpointDescription.audio.ssrcs.push(parsedSsrcs);
}
if (endpointDescription.audio.ssrcs.length === 0) {
throw new Error(
'Missing audio ssrcs when handling sdp answer from endpoint'
);
}


const transport = endpointDescription['bundle-transport'];
if (!transport) {
Expand Down Expand Up @@ -189,7 +197,7 @@ function getLine(productionLines: Line[], name: string): Line {
}

const apiProductions: FastifyPluginCallback = (fastify, opts, next) => {
const smbServerUrl = 'http://localhost:8080/conferences/';
const smbServerUrl = SMB_ADDRESS + '/conferences/';
const smb = new SmbProtocol();

fastify.post<{
Expand Down
2 changes: 1 addition & 1 deletion src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import api from './api';

const server = api({ title: '@eyevinn/typescript-nodejs' });

const PORT = process.env.PORT ? Number(process.env.PORT) : 8001;
const PORT = process.env.PORT ? Number(process.env.PORT) : 8000;

server.listen({ port: PORT, host: '0.0.0.0' }, (err, address) => {
if (err) {
Expand Down
1 change: 0 additions & 1 deletion src/smb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ export class SmbProtocol {
},
body: JSON.stringify(request)
});

console.log(request);

if (!response.ok) {
Expand Down

0 comments on commit b85cebd

Please sign in to comment.