mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-19 13:32:17 +08:00
Add opentok typings with tests.
This commit is contained in:
63
opentok/opentok-tests.ts
Normal file
63
opentok/opentok-tests.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
import * as OpenTok from 'opentok';
|
||||
|
||||
const client = new OpenTok('API_KEY', 'API_SECRET');
|
||||
|
||||
const sessionOptions: OpenTok.SessionOptions = {
|
||||
mediaMode: 'routed',
|
||||
archiveMode: 'manual',
|
||||
location: '12.34.56.78',
|
||||
};
|
||||
|
||||
client.createSession(sessionOptions, (err: Error, session: OpenTok.Session) => {
|
||||
if (err) return console.log(err);
|
||||
console.log(session.sessionId);
|
||||
});
|
||||
|
||||
const tokenOptions: OpenTok.TokenOptions = {
|
||||
role: 'subscriber',
|
||||
data: 'name=Seth',
|
||||
expireTime: 123456,
|
||||
};
|
||||
|
||||
const token = client.generateToken('SESSION_ID', tokenOptions);
|
||||
|
||||
const archiveOptions: OpenTok.ArchiveOptions = {
|
||||
name: 'name',
|
||||
hasAudio: true,
|
||||
hasVideo: true,
|
||||
outputMode: 'individual',
|
||||
};
|
||||
|
||||
client.startArchive('SESSION_ID', archiveOptions, (err: Error, archive: OpenTok.Archive) => {
|
||||
if (err) return console.log(err);
|
||||
console.log(archive.id);
|
||||
});
|
||||
|
||||
client.stopArchive('ARCHIVE_ID', (err: Error, archive: OpenTok.Archive) => {
|
||||
if (err) return console.log(err);
|
||||
console.log('Stopped archive:' + archive.id);
|
||||
});
|
||||
|
||||
client.getArchive('ARCHIVE_ID', (err: Error, archive: OpenTok.Archive) => {
|
||||
if (err) return console.log(err);
|
||||
console.log(archive);
|
||||
});
|
||||
|
||||
client.deleteArchive('ARCHIVE_ID', (err: Error) => {
|
||||
if (err) return console.log(err);
|
||||
console.log('success');
|
||||
});
|
||||
|
||||
const listArchivesOptions: OpenTok.ListArchivesOptions = {
|
||||
count: 10,
|
||||
offset: 5,
|
||||
}
|
||||
|
||||
client.listArchives(listArchivesOptions, (err: Error, archives: OpenTok.Archive[], totalCount: number) => {
|
||||
if (err) return console.log(err);
|
||||
|
||||
console.log(totalCount + ' archives');
|
||||
for (var i = 0; i < archives.length; i++) {
|
||||
console.log(archives[i].id);
|
||||
}
|
||||
});
|
||||
80
opentok/opentok.d.ts
vendored
Normal file
80
opentok/opentok.d.ts
vendored
Normal file
@@ -0,0 +1,80 @@
|
||||
// Type definitions for opentok v2.3.2
|
||||
// Project: https://github.com/opentok/opentok-node
|
||||
// Definitions by: Seth Westphal <https://github.com/westy92>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
declare module 'opentok' {
|
||||
|
||||
namespace OpenTok {
|
||||
|
||||
export type OutputMode = 'composed' | 'individual';
|
||||
|
||||
export type ArchiveStatus = 'available' | 'expired' | 'failed' | 'paused' | 'started' | 'stopped' | 'uploaded';
|
||||
|
||||
export interface Archive {
|
||||
createdAt: number;
|
||||
duration: string;
|
||||
id: string;
|
||||
name: string;
|
||||
partnerId: string;
|
||||
reason: string;
|
||||
sessionId: string;
|
||||
size: number;
|
||||
status: ArchiveStatus;
|
||||
hasAudio: boolean;
|
||||
hasVideo: boolean;
|
||||
outputMode: OutputMode;
|
||||
url: string;
|
||||
}
|
||||
|
||||
export interface ArchiveOptions {
|
||||
name?: string;
|
||||
hasAudio?: boolean;
|
||||
hasVideo?: boolean;
|
||||
outputMode?: OutputMode;
|
||||
}
|
||||
|
||||
export type MediaMode = 'relayed' | 'routed';
|
||||
|
||||
export type ArchiveMode = 'manual' | 'always';
|
||||
|
||||
export interface SessionOptions {
|
||||
mediaMode?: MediaMode;
|
||||
archiveMode?: ArchiveMode;
|
||||
location?: string;
|
||||
}
|
||||
|
||||
export interface Session {
|
||||
sessionId: string;
|
||||
}
|
||||
|
||||
export type Token = string;
|
||||
|
||||
export type Role = 'subscriber' | 'publisher' | 'moderator';
|
||||
|
||||
export interface TokenOptions {
|
||||
role?: Role;
|
||||
data?: string;
|
||||
expireTime?: number;
|
||||
}
|
||||
|
||||
export interface ListArchivesOptions {
|
||||
count?: number;
|
||||
offset?: number;
|
||||
}
|
||||
}
|
||||
|
||||
class OpenTok {
|
||||
constructor(apiKey: string, apiSecret: string);
|
||||
|
||||
public createSession(options: OpenTok.SessionOptions, callback: (err: Error, session: OpenTok.Session) => void): void;
|
||||
public generateToken(sessionId: string, options: OpenTok.TokenOptions): OpenTok.Token;
|
||||
public startArchive(sessionId: string, options: OpenTok.ArchiveOptions, callback: (err: Error, archive: OpenTok.Archive) => void): void;
|
||||
public stopArchive(archiveId: string, callback: (err: Error, archive: OpenTok.Archive) => void): void;
|
||||
public getArchive(archiveId: string, callback: (err: Error, archive: OpenTok.Archive) => void): void;
|
||||
public deleteArchive(archiveId: string, callback: (err: Error) => void): void;
|
||||
public listArchives(options: OpenTok.ListArchivesOptions, callback: (err: Error, archives: OpenTok.Archive[], totalCount: number) => void): void;
|
||||
}
|
||||
|
||||
export = OpenTok;
|
||||
}
|
||||
Reference in New Issue
Block a user