From d544b41b87f2d42a75284a1b3aba8068df15fd3a Mon Sep 17 00:00:00 2001 From: baiyufei Date: Thu, 26 Sep 2019 07:12:57 +0800 Subject: [PATCH] Create a type definition for npm module hark (#38375) * Create a type definition for npm module hark * Update index.d.ts * Update index.d.ts --- types/hark/hark-tests.ts | 22 ++++++++++++++++++++++ types/hark/index.d.ts | 34 ++++++++++++++++++++++++++++++++++ types/hark/tsconfig.json | 23 +++++++++++++++++++++++ types/hark/tslint.json | 1 + 4 files changed, 80 insertions(+) create mode 100644 types/hark/hark-tests.ts create mode 100644 types/hark/index.d.ts create mode 100644 types/hark/tsconfig.json create mode 100644 types/hark/tslint.json diff --git a/types/hark/hark-tests.ts b/types/hark/hark-tests.ts new file mode 100644 index 0000000000..9f57eb1e42 --- /dev/null +++ b/types/hark/hark-tests.ts @@ -0,0 +1,22 @@ +import hark = require('hark'); + +navigator.mediaDevices.getUserMedia({ audio: true, video: true }).then( + (stream) => { + const option: hark.Option = { + smoothing: 0.1, + interval: 50, + history: 10, + threshold: -50 + }; + const h: hark.Harker = hark(stream, option); + h.stop(); + h.resume(); + h.on('speaking', () => { + console.log('speaking'); + }); + + h.on('stopped_speaking', () => { + console.log('stop speaking'); + }); + } +); diff --git a/types/hark/index.d.ts b/types/hark/index.d.ts new file mode 100644 index 0000000000..e8537abcc4 --- /dev/null +++ b/types/hark/index.d.ts @@ -0,0 +1,34 @@ +// Type definitions for hark 1.2 +// Project: https://github.com/otalk/hark +// Definitions by: baiyufei +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.3 + +export = hark; + +declare function hark(stream: HTMLAudioElement | HTMLVideoElement | MediaStream, option?: hark.Option): hark.Harker; + +declare namespace hark { + interface Option { + smoothing?: number; + interval?: number; + threshold?: number; + play?: boolean; + history?: number; + } + + interface Harker { + speaking: boolean; + suspend(): Promise; + resume(): Promise; + readonly state: AudioContextState; + setThreshold(t: number): void; + setInterval(i: number): void; + stop(): void; + speakingHistory: number[]; + + on(event: 'speaking' | 'stopped_speaking', listener: () => void): void; + on(event: 'volume_change', listener: (currentVolume: number, threshold: number) => void): void; + on(event: 'state_change', listener: (state: AudioContextState) => void): void; + } +} diff --git a/types/hark/tsconfig.json b/types/hark/tsconfig.json new file mode 100644 index 0000000000..46852ee3b3 --- /dev/null +++ b/types/hark/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "hark-tests.ts" + ] +} diff --git a/types/hark/tslint.json b/types/hark/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/hark/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }