Skip to content

Commit

Permalink
feat: integrate smb public instance (#9)
Browse files Browse the repository at this point in the history
* fix: added ssrcs from answer

* feat: config env vars

* chore: fix service name

---------

Co-authored-by: Jonas Birmé <jonas.birme@eyevinn.se>
  • Loading branch information
oshinongit and birme authored Nov 28, 2023
1 parent e6d9b13 commit 60a2e0e
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 6 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
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# {{Name}}
# intercom-manager

<!--
Expand Down
22 changes: 19 additions & 3 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,6 +103,18 @@ async function handleAnswerRequest(

const parsedAnswer = parse(answer);
const answerMediaDescription = parsedAnswer.media[0];
if (parsedAnswer.media[1].ssrcs) {
let parsedSsrcs = parsedAnswer.media[1].ssrcs[0].id;
if (typeof parsedSsrcs === 'string') {
parsedSsrcs = parseInt(parsedSsrcs, 10);
}
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 @@ -181,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
4 changes: 2 additions & 2 deletions src/server.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import api from './api';

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

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: 1 addition & 0 deletions src/smb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ export class SmbProtocol {
},
body: JSON.stringify(request)
});
console.log(request);

if (!response.ok) {
console.log(JSON.stringify(request));
Expand Down

0 comments on commit 60a2e0e

Please sign in to comment.