Skip to content

Commit

Permalink
chore: fix typing, removed any, cleanup comments (#13)
Browse files Browse the repository at this point in the history
* chore: typing, comment cleanup and readme env vars
  • Loading branch information
oshinongit authored Dec 4, 2023
1 parent 64761df commit d97b15b
Show file tree
Hide file tree
Showing 6 changed files with 143 additions and 143 deletions.
5 changes: 3 additions & 2 deletions src/api_productions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { ProductionManager } from './production_manager';
import { Connection } from './connection';
import { write, parse } from 'sdp-transform';
import dotenv from 'dotenv';
import { MediaStreamsInfoSsrc } from './media_streams_info';
dotenv.config();

type NewProduction = Static<typeof NewProduction>;
Expand All @@ -24,10 +25,10 @@ function generateOffer(
throw new Error('Missing audio when creating offer');
}

const ssrcs: object[] = [];
const ssrcs: MediaStreamsInfoSsrc[] = [];
endpoint.audio.ssrcs.forEach((ssrcsNr) => {
ssrcs.push({
ssrc: ssrcsNr,
ssrc: ssrcsNr.toString(),
cname: `${username}_audioCName`,
mslabel: `${username}_audioMSLabel`,
label: `${username}_audioLabel`
Expand Down
117 changes: 15 additions & 102 deletions src/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import { v4 as uuidv4 } from 'uuid';
import { EventEmitter } from 'events';
import { SessionDescription } from 'sdp-transform';

import { SfuEndpointDescription } from './sfu/interface';
import {
AudioSmbPayloadParameters,
MediaDescriptionBase,
SfuEndpointDescription
} from './sfu/interface';
import { MediaStreamsInfo } from './media_streams_info';

export class Connection extends EventEmitter {
Expand All @@ -16,7 +20,7 @@ export class Connection extends EventEmitter {

constructor(
resourceId: string,
mediaStreams: MediaStreamsInfo | any,
mediaStreams: MediaStreamsInfo,
endpointDescription: SfuEndpointDescription
) {
super();
Expand All @@ -35,11 +39,11 @@ export class Connection extends EventEmitter {
return this.resourceId;
}

protected log(...args: any[]) {
protected log(...args: string[] | Connection[]) {
console.log(`[connection ${this.connectionId}]`, ...args);
}

protected error(...args: any[]) {
protected error(...args: string[] | Connection[]) {
console.error(`[connection ${this.connectionId}]`, ...args);
}

Expand Down Expand Up @@ -86,7 +90,7 @@ export class Connection extends EventEmitter {
return offer;
}

protected makeMediaDescription(type: string): any {
protected makeMediaDescription(type: string): MediaDescriptionBase {
if (!this.endpointDescription) {
throw new Error('Missing endpointDescription');
}
Expand Down Expand Up @@ -183,15 +187,19 @@ export class Connection extends EventEmitter {
}
];

const parameters = Object.keys(audioPayloadType.parameters);
const parameters: string[] = Object.keys(audioPayloadType.parameters);
if (parameters.length !== 0) {
audioDescription.fmtp = [
{
payload: audioPayloadType.id,
config: parameters
.map(
(element) =>
`${element}=${audioPayloadType.parameters[element]}`
`${element}=${
audioPayloadType.parameters[
element as keyof AudioSmbPayloadParameters
]
}`
)
.join(';')
}
Expand Down Expand Up @@ -225,104 +233,9 @@ export class Connection extends EventEmitter {

offer.media.push(audioDescription);
}

// let videoMsLabels = new Set(this.mediaStreams.video.ssrcs.flatMap(element => element.mslabel));

// for (let msLabel of videoMsLabels) {
// const video = this.endpointDescription.video;
// let videoDescription = this.makeMediaDescription('video');
// videoDescription.payloads = video["payload-types"]
// .flatMap(element => element.id)
// .join(' ');
// videoDescription.rtp = video["payload-types"].flatMap(element => {
// return {
// payload: element.id,
// codec: element.name,
// rate: element.clockrate,
// encoding: element.channels
// }
// });
// videoDescription.ext = video["rtp-hdrexts"].flatMap(element => {
// return { value: element.id, uri: element.uri }
// });

// video["payload-types"].forEach(payloadType => {
// const parameters = Object.keys(payloadType.parameters);
// if (parameters.length !== 0) {
// videoDescription.fmtp.push({
// payload: payloadType.id,
// config: parameters
// .map(element => `${element}=${payloadType.parameters[element]}`)
// .join(';')
// });
// }

// payloadType["rtcp-fbs"].forEach(rtcpFb => {
// videoDescription.rtcpFb.push({
// payload: payloadType.id,
// type: rtcpFb.type,
// subtype: rtcpFb.subtype
// });
// });
// });

// for (let ssrc of this.mediaStreams.video.ssrcs.filter(element => element.mslabel === msLabel)) {
// videoDescription.ssrcs.push({ id: ssrc.ssrc, attribute: 'cname', value: ssrc.cname });
// videoDescription.ssrcs.push({ id: ssrc.ssrc, attribute: 'label', value: ssrc.label });
// videoDescription.ssrcs.push({ id: ssrc.ssrc, attribute: 'mslabel', value: ssrc.mslabel });
// videoDescription.ssrcs.push({ id: ssrc.ssrc, attribute: 'msid', value: `${ssrc.mslabel} ${ssrc.label}` });
// }

// videoDescription.ssrcGroups = this.mediaStreams.video.ssrcGroups.flatMap(element => {
// return {
// semantics: element.semantics,
// ssrcs: element.ssrcs.join(' ')
// }
// });
// offer.media.push(videoDescription);
// }
}

protected addSFUMids(offer: SessionDescription) {
// const video = this.endpointDescription.video;
// const videoSsrc = video.streams[0].sources[0].main;

// let videoDescription = this.makeMediaDescription('video');
// videoDescription.payloads = video["payload-types"]
// .flatMap(element => element.id)
// .join(' ');
// videoDescription.rtp = video["payload-types"].flatMap(element => {
// return {
// payload: element.id,
// codec: element.name,
// rate: element.clockrate,
// encoding: element.channels
// }
// });

// video["payload-types"].forEach(payloadType => {
// const parameters = Object.keys(payloadType.parameters);
// if (parameters.length !== 0) {
// videoDescription.fmtp.push({
// payload: payloadType.id,
// config: parameters
// .map(element => `${element}=${payloadType.parameters[element]}`)
// .join(';')
// });
// }
// });

// videoDescription.ext = video["rtp-hdrexts"].flatMap(element => {
// return { value: element.id, uri: element.uri }
// });
// videoDescription.ssrcs = [
// { id: videoSsrc, attribute: 'cname', value: 'feedbackvideocname' },
// { id: videoSsrc, attribute: 'label', value: 'feedbackvideolabel' },
// { id: videoSsrc, attribute: 'mslabel', value: 'feedbackvideomslabel' },
// { id: videoSsrc, attribute: 'msid', value: 'feedbackvideomslabel feedbackvideolabel' }
// ];
// offer.media.push(videoDescription);

const dataDescription = this.makeMediaDescription('application');
dataDescription.protocol = 'UDP/DTLS/SCTP';
dataDescription.payloads = 'webrtc-datachannel';
Expand Down
4 changes: 0 additions & 4 deletions src/media_streams_info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ export interface MediaStreamsInfo {
audio: {
ssrcs: MediaStreamsInfoSsrc[];
};
video: {
ssrcs: MediaStreamsInfoSsrc[];
ssrcGroups: MediaStreamsInfoSsrcGroup[];
};
}

const MediaStreamsInfoSsrcSchema = {
Expand Down
4 changes: 0 additions & 4 deletions src/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,3 @@ export const Line = Type.Object({
id: Type.String(),
connections: Type.Any()
});

export const ConferenceId = Type.Object({
id: Type.Integer()
});
109 changes: 93 additions & 16 deletions src/sfu/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,17 @@ interface RtcpFeedback {
subtype: string;
}

interface SfuPayloadType {
export interface AudioSmbPayloadParameters {
minptime: string;
useinbandfec: string;
}

interface AudioSmbPayloadType {
id: number;
name: string;
clockrate: number;
channels?: number;
parameters?: any;
parameters: AudioSmbPayloadParameters;
'rtcp-fbs'?: RtcpFeedback[];
}

Expand All @@ -63,24 +68,96 @@ export interface SfuVideoStream {

export interface SfuEndpointDescription {
'bundle-transport'?: SfuTransport;
audio?: {
audio: {
ssrcs: number[];
'payload-type': SfuPayloadType;
'payload-type': AudioSmbPayloadType;
'rtp-hdrexts': SfuRtpHeaderExtension[];
};
}

video?: {
streams: SfuVideoStream[];
'payload-types': SfuPayloadType[];
'rtp-hdrexts'?: SfuRtpHeaderExtension[];
};
interface Rtp {
payload: number;
codec: string;
rate: number;
encoding?: number;
}

interface Fmtp {
payload: number;
config: string;
}

interface Ext {
value: number;
uri: string;
}

interface Ssrc {
id: string;
attribute: string;
value?: string;
}

interface RtcpFb {
payload: number;
type: string;
subtype?: string | undefined;
}

interface sctpmap {
sctpmapNumber: number;
app: string;
maxMessageSize: number;
}

// export interface SfuProtocol {
// //log(...args: any[]);
// allocateEndpoint(conferenceId: string,
// endpointId: string, audio: boolean, video: boolean, data: boolean): Promise<SfuEndpointDescription>;
// configureEndpoint(conferenceId: string, endpointId: string,
// endpointDescription: SfuEndpointDescription): Promise<void>;
interface SsrcGroup {
semantics: string;
ssrcs: string;
}

// }
export interface MediaDescriptionBase {
mid: string;
type: string;
port: number;
protocol: string;
payloads: string;
rtp: Rtp[];
fmtp: Fmtp[];
rtcpFb: RtcpFb[];
rtcp: {
port: number;
netType: string;
ipVer: number;
address: string;
};
ext: Ext[];
sctpmap?: sctpmap;
ssrcs: Ssrc[];
ssrcGroups?: SsrcGroup[];
iceUfrag: string;
icePwd: string;
fingerprint: {
type: string;
hash: string;
};
setup: string;
direction: 'sendrecv' | 'recvonly' | 'sendonly' | 'inactive' | undefined;
rtcpMux: string;
connection: {
version: number;
ip: string;
};
candidates: {
foundation: string;
component: number;
transport: string;
priority: number;
ip: string;
port: number;
type: string;
raddr?: string;
rport?: number;
generation: number;
'network-id'?: number;
}[];
}
Loading

0 comments on commit d97b15b

Please sign in to comment.