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

Add typescript types definition #31

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module.exports = function (grunt) {
}
},
jshint: {
files: ['Gruntfile.js', 'index.js', 'lib/**.js', 'test/**.js'],
files: ['Gruntfile.js', 'index.js', 'index.d.ts', 'lib/**.js', 'test/**.js'],
options: grunt.file.readJSON('.jshintrc')
}
});
Expand Down
175 changes: 175 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
declare module "sdp-jingle-json" {
export interface Session {
sid?: string;
contents: Media[];
groups?: SessionGroup[];
}

export interface Media {
creator: Role;
senders: Senders;
name: string; // SDP mid, or kind (audio/video) if no mid present
application: Description;
transport: Transport;
}

export interface Description {
applicationType: string; // usually "rtp"
media: string; // usually "video" | "audio"
payloads: Payload[];
encryption?: Encryption[];
feedback?: Feedback[];
headerExtensions?: HeaderExtension[];
bandwidth?: Bandwidth;
sources?: MediaSource[];
sourceGroups?: MediaSourceGroup[];
ssrc?: string;
mux?: boolean;
rsize?: boolean;
googConferenceFlag?: boolean;
}

export interface Transport {
transportType: string;
ufrag: string;
pwd: string;
candidates: Candidate[];
fingerprints: Fingerprint[];
sctp?: {number: string, protocol: string, streams: string}[];
}

export interface SessionGroup {
semantics: string;
contents: string[];
}

export interface Payload {
id: string;
name: string;
clockrate: string;
channels: number;
parameters: PayloadParameters[];
feedback: Feedback[];
}

export interface PayloadParameters {
key: string;
value: string;
}

export interface Encryption {
tag: string;
cipherSuite: string;
keyParams: string;
sessionParams: string;
}

export interface Feedback {
id: string;
type: string;
value: string;
parameters: string[];
}

export interface HeaderExtension {
id: string;
uri: string;
senders: Senders;
}

export interface MediaSource {
ssrc: string;
parameters: MediaSourceParameters[];
}

export interface MediaSourceParameters {
key: string;
value: string;
}

export interface MediaSourceGroup {
semantics: string;
sources: string[];
}

export interface Bandwidth {
type: string;
bandwidth: string;
}

export interface Fingerprint {
hash: string;
value: string;
setup?: string;
}

export interface Candidate {
id?: string;
foundation: string;
component: string;
protocol: string;
priority: string;
ip: string;
port: string;
type: string;
generation: string;
relAddr?: string;
relPort?: string;
tcpType?: string;
network: string;
}

export type Role = "initiator" | "responder";
export type Direction = "incoming" | "outgoing";
export type Senders = "initiator" | "responder" | "both" | "none";

// Conversion from JSON to SDP
export interface ToSessionSDPOptions {
role?: Role;
direction?: Direction;
sid?: string | number;
time?: number;
}

export interface ToMediaSDPOptions {
role?: Role;
direction?: Direction;
}

export function toIncomingSDPOffer(session: Session): string;
export function toOutgoingSDPOffer(session: Session): string;
export function toIncomingSDPAnswer(session: Session): string;
export function toOutgoingSDPAnswer(session: Session): string;
export function toIncomingMediaSDPOffer(media: Media): string;
export function toOutgoingMediaSDPOffer(media: Media): string;
export function toIncomingMediaSDPAnswer(media: Media): string;
export function toOutgoingMediaSDPAnswer(media: Media): string;
export function toSessionSDP(session: Session, opts: ToSessionSDPOptions): string;
export function toMediaSDP(media: Media, opts: ToMediaSDPOptions): string;
export function toCandidateSDP(candidate: Candidate): string;

// Conversion from SDP to JSON
export interface ToSessionJSONOptions {
role?: Role;
direction?: Direction;
creators?: Role[];
}

export interface ToMediaJSONOptions {
role?: Role;
direction?: Direction;
creator?: Role;
}

export function toIncomingJSONOffer(sdp: string, creators?: Role[]): Session;
export function toOutgoingJSONOffer(sdp: string, creators?: Role[]): Session;
export function toIncomingJSONAnswer(sdp: string, creators?: Role[]): Session;
export function toOutgoingJSONAnswer(sdp: string, creators?: Role[]): Session;
export function toIncomingMediaJSONOffer(sdp: string, creators?: Role[]): Media;
export function toOutgoingMediaJSONOffer(sdp: string, creators?: Role[]): Media;
export function toIncomingMediaJSONAnswer(sdp: string, creators?: Role[]): Media;
export function toOutgoingMediaJSONAnswer(sdp: string, creators?: Role[]): Media;
export function toSessionJSON(sdp: string, opts: ToSessionJSONOptions): Session;
export function toMediaJSON(sdp: string, session: string, opts: ToMediaJSONOptions): Media;
export function toCandidateJSON(sdp: string): Candidate;
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "3.1.0",
"description": "A parser/serializer for SDP to JSON. Useful for converting SDP to other formats like Jingle for WebRTC signalling",
"main": "index.js",
"types": "index.d.ts",
"repository": {
"type": "git",
"url": "https://github.com/legastero/sdp-jingle-json.git"
Expand Down