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

chore: improved docs and removed bad code #39

Merged
merged 1 commit into from
Mar 20, 2024
Merged
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
80 changes: 48 additions & 32 deletions src/api_productions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ function getLine(productionLines: Line[], name: string): Line {
name
);
if (!line) {
throw new Error('Trying to join production that does not exist');
throw new Error('Trying to get line that does not exist');
}
return line;
}
Expand Down Expand Up @@ -220,7 +220,7 @@ const apiProductions: FastifyPluginCallback<ApiProductionsOptions> = (
'/production',
{
schema: {
// description: 'Create a new Production resource.',
description: 'Create a new Production.',
body: NewProduction,
response: {
200: Production
Expand Down Expand Up @@ -250,7 +250,7 @@ const apiProductions: FastifyPluginCallback<ApiProductionsOptions> = (
'/productions',
{
schema: {
// description: 'Retrieves all Productions.',
description: 'Retrieves all Productions.',
response: {
200: Type.Array(Production)
}
Expand All @@ -269,21 +269,23 @@ const apiProductions: FastifyPluginCallback<ApiProductionsOptions> = (
);

fastify.get<{
Params: { name: string };
Params: { productionname: string };
Reply: Production | string;
}>(
'/productions/:name',
'/productions/:productionname',
{
schema: {
// description: 'Retrieves a Production.',
description: 'Retrieves a Production.',
response: {
200: Production
}
}
},
async (request, reply) => {
try {
const production: Production = getProduction(request.params.name);
const production: Production = getProduction(
request.params.productionname
);
reply.code(200).send(production);
} catch (err) {
reply
Expand All @@ -294,21 +296,23 @@ const apiProductions: FastifyPluginCallback<ApiProductionsOptions> = (
);

fastify.get<{
Params: { name: string };
Params: { productionname: string };
Reply: Line[] | string;
}>(
'/productions/:name/lines',
'/productions/:productionname/lines',
{
schema: {
// description: 'Retrieves lines for a Production.',
description: 'Retrieves all lines for a Production.',
response: {
200: Type.Array(Line)
}
}
},
async (request, reply) => {
try {
const production: Production = getProduction(request.params.name);
const production: Production = getProduction(
request.params.productionname
);
reply.code(200).send(production.lines);
} catch (err) {
reply
Expand All @@ -319,21 +323,23 @@ const apiProductions: FastifyPluginCallback<ApiProductionsOptions> = (
);

fastify.get<{
Params: { name: string; linename: string };
Params: { productionname: string; linename: string };
Reply: Line | string;
}>(
'/productions/:name/lines/:linename',
'/productions/:productionname/lines/:linename',
{
schema: {
// description: 'Retrieves an active Production line.',
description: 'Retrieves an active Production line.',
Copy link
Contributor

@martinstark martinstark Mar 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does it mean that it's active, can the request fail if a line on a production is "inactive"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved in meeting.

*Line objects can be saved in the service manager memory but not have connection resources allocated in the SMB instance. These are inactive etc.

response: {
200: Line
}
}
},
async (request, reply) => {
try {
const production: Production = getProduction(request.params.name);
const production: Production = getProduction(
request.params.productionname
);
const line: Line = getLine(production.lines, request.params.linename);
reply.code(200).send(line);
} catch (err) {
Expand All @@ -345,13 +351,14 @@ const apiProductions: FastifyPluginCallback<ApiProductionsOptions> = (
);

fastify.post<{
Params: { name: string; linename: string; username: string };
Params: { productionname: string; linename: string; username: string };
Reply: { [key: string]: string | string[] } | string;
}>(
'/productions/:name/lines/:linename/users/:username',
'/productions/:productionname/lines/:linename/users/:username',
{
schema: {
// description: 'Initiate line conference join.',
description:
'Initiate connection protocol. Generates sdp offer describing remote SMB instance.',
response: {
200: Type.Object({
sdp: Type.String()
Expand All @@ -361,7 +368,9 @@ const apiProductions: FastifyPluginCallback<ApiProductionsOptions> = (
},
async (request, reply) => {
try {
const production: Production = getProduction(request.params.name);
const production: Production = getProduction(
request.params.productionname
);
const line: Line = getLine(production.lines, request.params.linename);

const activeLines = await getActiveLines(smb, smbServerUrl);
Expand Down Expand Up @@ -422,21 +431,24 @@ const apiProductions: FastifyPluginCallback<ApiProductionsOptions> = (
);

fastify.patch<{
Params: { name: string; linename: string; username: string };
Params: { productionname: string; linename: string; username: string };
Body: string;
}>(
'/productions/:name/lines/:linename/users/:username',
'/productions/:productionname/lines/:linename/users/:username',
{
schema: {
//description: 'Provide client connection information to finalize line conference join.',
description:
'Provide client local SDP description as request body to finalize connection protocol.',
response: {
200: Line
}
}
},
async (request, reply) => {
try {
const production: Production = getProduction(request.params.name);
const production: Production = getProduction(
request.params.productionname
);
const line: Line = getLine(production.lines, request.params.linename);

const connectionEndpointDescription: SmbEndpointDescription =
Expand Down Expand Up @@ -469,24 +481,28 @@ const apiProductions: FastifyPluginCallback<ApiProductionsOptions> = (
);

fastify.delete<{
Params: { name: string };
Params: { productionname: string };
Reply: string;
}>(
'/productions/:name',
'/productions/:productionname',
{
schema: {
// description: 'Deletes a Production.',
description: 'Deletes a Production.',
response: {
204: Type.String()
}
}
},
async (request, reply) => {
try {
if (!productionManager.deleteProduction(request.params.name)) {
if (
!productionManager.deleteProduction(request.params.productionname)
) {
throw new Error('Could not delete production');
}
reply.code(204).send(`Deleted production ${request.params.name}`);
reply
.code(204)
.send(`Deleted production ${request.params.productionname}`);
} catch (err) {
reply
.code(500)
Expand All @@ -496,13 +512,13 @@ const apiProductions: FastifyPluginCallback<ApiProductionsOptions> = (
);

fastify.delete<{
Params: { name: string; linename: string; username: string };
Params: { productionname: string; linename: string; username: string };
Reply: string;
}>(
'/productions/:name/lines/:linename/users/:username',
'/productions/:productionname/lines/:linename/users/:username',
{
schema: {
// description: 'Deletes a Connection from ProductionManager.',
description: 'Deletes a Connection from ProductionManager.',
response: {
204: Type.String()
}
Expand All @@ -512,7 +528,7 @@ const apiProductions: FastifyPluginCallback<ApiProductionsOptions> = (
try {
if (
!productionManager.removeConnectionFromLine(
request.params.name,
request.params.productionname,
request.params.linename,
request.params.username
)
Expand Down
4 changes: 1 addition & 3 deletions src/connection.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { EventEmitter } from 'events';
import { SessionDescription } from 'sdp-transform';

import {
Expand All @@ -8,7 +7,7 @@ import {
} from './sfu/interface';
import { MediaStreamsInfo } from './media_streams_info';

export class Connection extends EventEmitter {
export class Connection {
private resourceId: string;
private connectionId: string;
private nextMid = 0;
Expand All @@ -24,7 +23,6 @@ export class Connection extends EventEmitter {
endpointDescription: SfuEndpointDescription,
endpointId: string
) {
super();
this.resourceId = resourceId;
this.connectionId = endpointId;
this.mediaStreams = mediaStreams;
Expand Down
Loading