diff --git a/types/kurento-client/index.d.ts b/types/kurento-client/index.d.ts new file mode 100644 index 0000000000..f1620d451f --- /dev/null +++ b/types/kurento-client/index.d.ts @@ -0,0 +1,132 @@ +// Type definitions for kurento-client 6.12 +// Project: https://github.com/Kurento/kurento-client-js, https://www.kurento.org +// Definitions by: James Hill +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.2 + +declare namespace KurentoClient { + interface Constructor { + (ws_uri: string, options?: Options): Promise; + getComplexType: (complex: 'IceCandidate') => (value: any) => any; + } + + class ClientInstance { + create(type: 'MediaPipeline'): Promise; + create(type: 'WebRtcEndpoint'): Promise; + on(event: 'OnIceCandidate', callback: (event: IceCandidate) => void): void; + on(event: 'Error', callback: (error: Error) => void): void; + on(event: 'Recording' | 'Paused' | 'Stopped', callback: () => void): void; + getMediaobjectById(objectId: string): Promise; + close(): void; + } + + interface MediaObject { + id: string; + name: string; + tags: object; + addTag: (key: string, value: string, callback?: Callback) => Promise; + getTag: (key: string, callback?: Callback) => Promise; + getTags: (callback?: Callback) => Promise; + removeTag: (key: string, callback?: Callback) => Promise; + getChildren: (callback?: Callback) => Promise; + getCreationTime: (callback?: Callback) => Promise; + getMediaPipeline: (callback?: Callback) => Promise; + getParent: (callback?: Callback) => Promise; + getName: (callback?: Callback) => Promise; + setName: (name: string, callback?: Callback) => Promise; + } + + interface MediaElement { + connect: (sink: MediaElement, callback?: Callback) => Promise; + disconnect: (sink: MediaElement, callback?: Callback) => Promise; + getSinkConnections: (callback?: Callback) => Promise; + getSourceConnections: (callback?: Callback) => Promise; + } + + interface MediaPipeline extends ClientInstance, MediaObject { + getGstreamerDot: (callback?: Callback) => Promise; + getLatencyStats: (callback?: Callback) => Promise; + setLatencyStats: (callback?: Callback) => Promise; + } + + interface WebRtcEndpoint extends ClientInstance, MediaObject, MediaElement { + addIceCandidate: (candidate: RTCIceCandidate, callback?: Callback) => Promise; + closeDataChannel: (channelId: number, callback?: Callback) => Promise; + createDataChannel: (label?: string, ordered?: boolean, maxPacketLifeTime?: number, maxRetransmits?: number, protocol?: string, callback?: Callback) => Promise; + gatherCandidates: (callback?: Callback) => Promise; + getConnectionState: (callback?: Callback) => Promise; + getICECandidatePairs: (callback?: Callback) => Promise; + getIceConnectionState: (callback?: Callback) => Promise; + setMaxAudioRecvBandwidth: (value: number, callback?: Callback) => Promise; + getMaxAudioRecvBandwidth: (callback?: Callback) => Promise; + setMinVideoRecvBandwidth: (value: number, callback?: Callback) => Promise; + getMinVideoRecvBandwidth: (callback?: Callback) => Promise; + setMaxVideoRecvBandwidth: (value: number, callback?: Callback) => Promise; + getMaxVideoRecvBandwidth: (callback?: Callback) => Promise; + setMinVideoSendBandwidth: (value: number, callback?: Callback) => Promise; + getMinVideoSendBandwidth: (callback?: Callback) => Promise; + setMaxVideoSendBandwidth: (value: number, callback?: Callback) => Promise; + getMaxVideoSendBandwidth: (callback?: Callback) => Promise; + setMinOutputBitrate: (value: number, callback?: Callback) => Promise; + getMinOutputBitrate: (callback?: Callback) => Promise; + setMaxOutputBitrate: (value: number, callback?: Callback) => Promise; + getMaxOutputBitrate: (callback?: Callback) => Promise; + getMediaState: (callback?: Callback) => Promise; + setStunServerAddress: (server: string, callback?: Callback) => Promise; + getStunServerAddress: (callback?: Callback) => Promise; + setStunServerPort: (port: number, callback?: Callback) => Promise; + getStunServerPort: (callback?: Callback) => Promise; + setTurnUrl: (url: string, callback?: Callback) => Promise; + getTurnUrl: (callback?: Callback) => Promise; + processOffer: (offer: string, callback?: Callback) => Promise; + } + + interface ElementConnectionData { + source: WebRtcEndpoint; + sink: WebRtcEndpoint; + type: any; + sourceDescription: string; + sinkDescription: string; + } + + interface Error { + description: string; + errorCode: number; + type: string; + } + + interface Tag { + key: string; + value: string; + } + + interface IceConnection { + streamId: string; + componentId: number; + state: any; + } + + interface IceCandidate { + candidate: string; + sdpMid: string; + sdpMLineIndex: number; + } + + type Callback = (error: Error, result: T) => void; + + interface Options { + failAfter?: number; + enableTransactions?: boolean; + useImplicitTransactions?: boolean; + strict?: boolean; + request_timeout?: number; + response_timeout?: number; + duplicates_timeout?: number; + access_token?: string; + socket?: any; + } +} + +declare const kurento: KurentoClient.Constructor; + +export = kurento; diff --git a/types/kurento-client/kurento-client-tests.ts b/types/kurento-client/kurento-client-tests.ts new file mode 100644 index 0000000000..6e10f1943c --- /dev/null +++ b/types/kurento-client/kurento-client-tests.ts @@ -0,0 +1,28 @@ +import kurento from 'kurento-client'; + +async () => { + const sdpOffer = 'offer'; + const candidate = new RTCIceCandidate(); + + const client = await kurento('//server', { failAfter: 500, useImplicitTransactions: true }); + const pipeline = await client.create('MediaPipeline'); + const endpoint = await pipeline.create('WebRtcEndpoint'); + + endpoint.addIceCandidate(candidate); + + endpoint.on('OnIceCandidate', ({ candidate }) => { + const value = kurento.getComplexType('IceCandidate')( + candidate + ); + + endpoint.addIceCandidate(value); + }); + + const sdpAnswer = await endpoint.processOffer(sdpOffer); + + endpoint.gatherCandidates(error => { + // ok + }); + + return { sdpAnswer }; +}; diff --git a/types/kurento-client/tsconfig.json b/types/kurento-client/tsconfig.json new file mode 100644 index 0000000000..7000803ade --- /dev/null +++ b/types/kurento-client/tsconfig.json @@ -0,0 +1,25 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "esModuleInterop": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "kurento-client-tests.ts" + ] +} diff --git a/types/kurento-client/tslint.json b/types/kurento-client/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/kurento-client/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }