Skip to content

Commit

Permalink
make types more correct
Browse files Browse the repository at this point in the history
this does not change the code, only tightens the types
to better express the constraints.

 - TrackInfo#media is not allowed to be "application"
 - SupportedMedia#codecs is no longer required
 - SDPInfoParams accepts Plain stuff too
 - SDPInfo constructor "version" parameter optional
 - DataChannelInfo#maxMessageSize is optional
 - RIDInfo#direction is DirectionWay, not Direction
 - DTLSInfoPlain#setup is optional
  • Loading branch information
mildsunrise committed May 29, 2024
1 parent 8a196d8 commit 35ade73
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 20 deletions.
4 changes: 2 additions & 2 deletions lib/DataChannelInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class DataChannelInfo
* @constructor
* @alias DataChannelInfo
* @param {Number} port
* @param {Number} maxMessageSize
* @param {Number} [maxMessageSize]
*/
constructor(port,maxMessageSize)
{
Expand Down Expand Up @@ -50,7 +50,7 @@ class DataChannelInfo

/**
* Get max message size
* @returns {Number}
* @returns {Number | undefined}
*/
getMaxMessageSize() {
return this.maxMessageSize;
Expand Down
5 changes: 1 addition & 4 deletions lib/SDPInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class SDPInfo
/**
* @constructor
* @alias SDPInfo
* @param {Number} version SDP version attribute
* @param {Number} [version] SDP version attribute
*/
constructor(version)
{
Expand Down Expand Up @@ -515,7 +515,6 @@ class SDPInfo
*/
answer(params) {
//Create local SDP info
//@ts-expect-error
const answer = new SDPInfo();

//Add ice
Expand Down Expand Up @@ -1104,7 +1103,6 @@ class SDPInfo
SDPInfo.create = function(params)
{
//Create local SDP info
//@ts-expect-error
const sdp = new SDPInfo();

//Add ice
Expand Down Expand Up @@ -1280,7 +1278,6 @@ SDPInfo.parse = function(string)
const sdp = SDPTransform.parse(string);

//Create sdp info object
//@ts-expect-error
const sdpInfo = new SDPInfo();

//Set version
Expand Down
4 changes: 2 additions & 2 deletions lib/StreamInfo.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const TrackInfo = require("./TrackInfo");

/** @typedef {import(".").MediaType} MediaType */
/** @typedef {import(".").TrackType} TrackType */
/** @typedef {import(".").StreamInfoPlain} StreamInfoPlain */
/** @typedef {import(".").StreamInfoLike} StreamInfoLike */

Expand Down Expand Up @@ -88,7 +88,7 @@ class StreamInfo {
}
/**
* Get first track for the media type
* @param {MediaType} media - Media type "audio"|"video"
* @param {TrackType} media - Media type "audio"|"video"
* @returns {TrackInfo}
*/
getFirstTrack(media) {
Expand Down
6 changes: 3 additions & 3 deletions lib/TrackInfo.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const SourceGroupInfo = require("./SourceGroupInfo");
const TrackEncodingInfo = require("./TrackEncodingInfo");

/** @typedef {import(".").MediaType} MediaType */
/** @typedef {import(".").TrackType} TrackType */
/** @typedef {import(".").TrackInfoPlain} TrackInfoPlain */
/** @typedef {import(".").TrackInfoLike} TrackInfoLike */
/** @typedef {import(".").TrackEncodingInfoPlain} TrackEncodingInfoPlain */
Expand All @@ -15,7 +15,7 @@ class TrackInfo
/**
* @constructor
* @alias TrackInfo
* @param {MediaType} media - Media type "audio"|"video"
* @param {TrackType} media - Media type "audio"|"video"
* @param {String} id - Track id
*/
constructor(media,id) {
Expand Down Expand Up @@ -110,7 +110,7 @@ class TrackInfo

/**
* Get media type
* @returns {MediaType} - "audio"|"video"
* @returns {TrackType} - "audio"|"video"
*/
getMedia() {
return this.media;
Expand Down
22 changes: 13 additions & 9 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export import Direction = require("./Direction");

// Manually defined types

export type TrackType = 'audio'|'video';

export type MediaType = 'audio'|'video'|'application';

export type Capabilities = { [k in MediaType]?: SupportedMedia };
Expand All @@ -28,15 +30,15 @@ export type SDPParams = { [k: string]: string };

export interface SDPInfoParams {
/** ICE info object */
ice?: ICEInfo;
ice?: ICEInfoLike;
/** DTLS info object */
dtls?: DTLSInfo;
dtls?: DTLSInfoLike;
/** Array of ICE candidates */
candidates?: CandidateInfo[];
candidates?: CandidateInfoLike[];
/** Capabilities for each media type */
capabilities?: Capabilities;

crypto?: CryptoInfo;
crypto?: CryptoInfoLike;
}

export interface RTCPFeedbackInfoPlain {
Expand All @@ -46,7 +48,7 @@ export interface RTCPFeedbackInfoPlain {

export interface SupportedMedia {
/** Map or codecInfo or list of strings with the supported codec names */
codecs: Map<number, CodecInfo> | string[];
codecs?: Map<number, CodecInfo> | string[];
/** List of strings with the supported extension URIs */
extensions?: Iterable<string>;
/** Simulcast is enabled */
Expand All @@ -59,6 +61,8 @@ export interface SupportedMedia {
dataChannel?: DataChannelInfoPlain;
}

export type SetupPlain = 'active'|'passive'|'actpass'|'inactive';
export type DirectionWayPlain = 'send'|'recv';
export type DirectionPlain = 'sendrecv'|'sendonly'|'recvonly'|'inactive';

export interface CodecInfoPlain {
Expand All @@ -75,7 +79,7 @@ export interface StreamInfoPlain {
}
export interface RIDInfoPlain {
id: string;
direction: DirectionPlain;
direction: DirectionWayPlain;
formats: number[];
params: SDPParams;
}
Expand Down Expand Up @@ -117,7 +121,7 @@ export interface ICEInfoPlain {
endOfCandidates?: boolean;
}
export interface DTLSInfoPlain {
setup: string;
setup?: SetupPlain;
hash: string;
fingerprint: string;
}
Expand All @@ -135,7 +139,7 @@ export interface TrackEncodingInfoPlain {
}
export interface TrackInfoPlain {
id: string;
media: MediaType;
media: TrackType;
mediaId?: string;
ssrcs?: number[];
groups?: SourceGroupInfoPlain[];
Expand All @@ -159,7 +163,7 @@ export interface SimulcastStreamInfoPlain {

export interface DataChannelInfoPlain {
port: number;
maxMessageSize: number;
maxMessageSize?: number;
}

export interface SourceInfoPlain {
Expand Down

0 comments on commit 35ade73

Please sign in to comment.