Skip to content

Commit 35ade73

Browse files
committed
make types more correct
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
1 parent 8a196d8 commit 35ade73

File tree

5 files changed

+21
-20
lines changed

5 files changed

+21
-20
lines changed

lib/DataChannelInfo.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class DataChannelInfo
1111
* @constructor
1212
* @alias DataChannelInfo
1313
* @param {Number} port
14-
* @param {Number} maxMessageSize
14+
* @param {Number} [maxMessageSize]
1515
*/
1616
constructor(port,maxMessageSize)
1717
{
@@ -50,7 +50,7 @@ class DataChannelInfo
5050

5151
/**
5252
* Get max message size
53-
* @returns {Number}
53+
* @returns {Number | undefined}
5454
*/
5555
getMaxMessageSize() {
5656
return this.maxMessageSize;

lib/SDPInfo.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class SDPInfo
4040
/**
4141
* @constructor
4242
* @alias SDPInfo
43-
* @param {Number} version SDP version attribute
43+
* @param {Number} [version] SDP version attribute
4444
*/
4545
constructor(version)
4646
{
@@ -515,7 +515,6 @@ class SDPInfo
515515
*/
516516
answer(params) {
517517
//Create local SDP info
518-
//@ts-expect-error
519518
const answer = new SDPInfo();
520519

521520
//Add ice
@@ -1104,7 +1103,6 @@ class SDPInfo
11041103
SDPInfo.create = function(params)
11051104
{
11061105
//Create local SDP info
1107-
//@ts-expect-error
11081106
const sdp = new SDPInfo();
11091107

11101108
//Add ice
@@ -1280,7 +1278,6 @@ SDPInfo.parse = function(string)
12801278
const sdp = SDPTransform.parse(string);
12811279

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

12861283
//Set version

lib/StreamInfo.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const TrackInfo = require("./TrackInfo");
22

3-
/** @typedef {import(".").MediaType} MediaType */
3+
/** @typedef {import(".").TrackType} TrackType */
44
/** @typedef {import(".").StreamInfoPlain} StreamInfoPlain */
55
/** @typedef {import(".").StreamInfoLike} StreamInfoLike */
66

@@ -88,7 +88,7 @@ class StreamInfo {
8888
}
8989
/**
9090
* Get first track for the media type
91-
* @param {MediaType} media - Media type "audio"|"video"
91+
* @param {TrackType} media - Media type "audio"|"video"
9292
* @returns {TrackInfo}
9393
*/
9494
getFirstTrack(media) {

lib/TrackInfo.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const SourceGroupInfo = require("./SourceGroupInfo");
22
const TrackEncodingInfo = require("./TrackEncodingInfo");
33

4-
/** @typedef {import(".").MediaType} MediaType */
4+
/** @typedef {import(".").TrackType} TrackType */
55
/** @typedef {import(".").TrackInfoPlain} TrackInfoPlain */
66
/** @typedef {import(".").TrackInfoLike} TrackInfoLike */
77
/** @typedef {import(".").TrackEncodingInfoPlain} TrackEncodingInfoPlain */
@@ -15,7 +15,7 @@ class TrackInfo
1515
/**
1616
* @constructor
1717
* @alias TrackInfo
18-
* @param {MediaType} media - Media type "audio"|"video"
18+
* @param {TrackType} media - Media type "audio"|"video"
1919
* @param {String} id - Track id
2020
*/
2121
constructor(media,id) {
@@ -110,7 +110,7 @@ class TrackInfo
110110

111111
/**
112112
* Get media type
113-
* @returns {MediaType} - "audio"|"video"
113+
* @returns {TrackType} - "audio"|"video"
114114
*/
115115
getMedia() {
116116
return this.media;

lib/index.ts

+13-9
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ export import Direction = require("./Direction");
2020

2121
// Manually defined types
2222

23+
export type TrackType = 'audio'|'video';
24+
2325
export type MediaType = 'audio'|'video'|'application';
2426

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

2931
export interface SDPInfoParams {
3032
/** ICE info object */
31-
ice?: ICEInfo;
33+
ice?: ICEInfoLike;
3234
/** DTLS info object */
33-
dtls?: DTLSInfo;
35+
dtls?: DTLSInfoLike;
3436
/** Array of ICE candidates */
35-
candidates?: CandidateInfo[];
37+
candidates?: CandidateInfoLike[];
3638
/** Capabilities for each media type */
3739
capabilities?: Capabilities;
3840

39-
crypto?: CryptoInfo;
41+
crypto?: CryptoInfoLike;
4042
}
4143

4244
export interface RTCPFeedbackInfoPlain {
@@ -46,7 +48,7 @@ export interface RTCPFeedbackInfoPlain {
4648

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

64+
export type SetupPlain = 'active'|'passive'|'actpass'|'inactive';
65+
export type DirectionWayPlain = 'send'|'recv';
6266
export type DirectionPlain = 'sendrecv'|'sendonly'|'recvonly'|'inactive';
6367

6468
export interface CodecInfoPlain {
@@ -75,7 +79,7 @@ export interface StreamInfoPlain {
7579
}
7680
export interface RIDInfoPlain {
7781
id: string;
78-
direction: DirectionPlain;
82+
direction: DirectionWayPlain;
7983
formats: number[];
8084
params: SDPParams;
8185
}
@@ -117,7 +121,7 @@ export interface ICEInfoPlain {
117121
endOfCandidates?: boolean;
118122
}
119123
export interface DTLSInfoPlain {
120-
setup: string;
124+
setup?: SetupPlain;
121125
hash: string;
122126
fingerprint: string;
123127
}
@@ -135,7 +139,7 @@ export interface TrackEncodingInfoPlain {
135139
}
136140
export interface TrackInfoPlain {
137141
id: string;
138-
media: MediaType;
142+
media: TrackType;
139143
mediaId?: string;
140144
ssrcs?: number[];
141145
groups?: SourceGroupInfoPlain[];
@@ -159,7 +163,7 @@ export interface SimulcastStreamInfoPlain {
159163

160164
export interface DataChannelInfoPlain {
161165
port: number;
162-
maxMessageSize: number;
166+
maxMessageSize?: number;
163167
}
164168

165169
export interface SourceInfoPlain {

0 commit comments

Comments
 (0)