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
This commit is contained in:
baiyufei 2019-09-26 07:12:57 +08:00 committed by Ben Lichtman
parent 444e10e486
commit d544b41b87
4 changed files with 80 additions and 0 deletions

22
types/hark/hark-tests.ts Normal file
View File

@ -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');
});
}
);

34
types/hark/index.d.ts vendored Normal file
View File

@ -0,0 +1,34 @@
// Type definitions for hark 1.2
// Project: https://github.com/otalk/hark
// Definitions by: baiyufei <https://github.com/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<void>;
resume(): Promise<void>;
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;
}
}

23
types/hark/tsconfig.json Normal file
View File

@ -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"
]
}

1
types/hark/tslint.json Normal file
View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }