Skip to content

Commit

Permalink
TypeScriptの型定義ファイルを出力するように変更
Browse files Browse the repository at this point in the history
  • Loading branch information
horiuchi committed Jul 30, 2020
1 parent 58f3f2f commit 865f72d
Show file tree
Hide file tree
Showing 8 changed files with 261 additions and 1 deletion.
66 changes: 66 additions & 0 deletions dist/ayame.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import Connection from './connection';
import { ConnectionOptions } from './connection/options';
/**
* オーディオ、ビデオの送受信方向に関するオプションです。
* - sendrecv
* - recvonly
* - sendonly
*
* @typedef {string} ConnectionDirection
*/
/**
* @typedef {Object} ConnectionAudioOption - オーディオ接続に関するオプションです。
* @property {ConnectionDirection} direction 送受信方向
* @property {boolean} enabled 有効かどうかのフラグ
*/
/**
* ビデオ接続のコーデックに関するオプションです。
* - VP8
* - VP9
* - H264
*
* @typedef {string} VideoCodecOption
*/
/**
* @typedef {Object} ConnectionVideoOption - ビデオ接続に関するオプションです。
* @property {VideoCodecOption} codec コーデックの設定
* @property {ConnectionDirection} direction 送受信方向
* @property {boolean} enabled 有効かどうかのフラグ
*/
/**
* @typedef {Object} ConnectionOptions - 接続時に指定するオプションです。
* @property {ConnectionAudioOption} audio オーディオの設定
* @property {ConnectionVideoOption} video ビデオの設定
* @property {string} clientId クライアントID
* @property {Array.<RTCIceServer>} iceServers ayame server から iceServers が返って来なかった場合に使われる iceServer の情報
* @property {string} signalingKey 送信するシグナリングキー
*/
/**
* Ayame Connection のデフォルトのオプションです。
*
* audio: { direction: 'sendrecv', enabled: true}
*
* video: { direction: 'sendrecv', enabled: true}
*
* iceServers: [{ urls: 'stun:stun.l.google.com:19302' }]
*
* clientId: randomString(17)
*
* @type {ConnectionOptions} ConnectionOptions
*/
export declare const defaultOptions: ConnectionOptions;
/**
* @desc Ayame Connection を生成します。
* @param {string} signalingUrl シグナリングに用いる websocket url
* @param {string} roomId 接続する roomId
* @param {ConnectionOptions} [options=defaultOptions] 接続時のオプション
* @param {boolean} [debug=false] デバッグログを出力するかどうかのフラグ
* @param {boolean} [isRelay=false] iceTranspolicy を強制的に relay するかどうかのフラグ(デバッグ用)
* @return {Connection} 生成された Ayame Connection
*/
export declare function connection(signalingUrl: string, roomId: string, options?: ConnectionOptions, debug?: boolean, isRelay?: boolean): Connection;
/**
* @desc Ayame Web SDK のバージョンを出力します。
* @return {string} Ayame Web SDK のバージョン
*/
export declare function version(): string;
2 changes: 1 addition & 1 deletion dist/ayame.min.js

Large diffs are not rendered by default.

66 changes: 66 additions & 0 deletions dist/connection/base.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { ConnectionOptions } from './options';
/**
* @ignore
*/
declare class ConnectionBase {
debug: boolean;
roomId: string;
signalingUrl: string;
options: ConnectionOptions;
connectionState: string;
stream: MediaStream | null;
remoteStream: MediaStream | null;
authnMetadata: any;
authzMetadata: any;
_ws: WebSocket | null;
_pc: RTCPeerConnection | null;
_callbacks: any;
_removeCodec: boolean;
_isOffer: boolean;
_isExistUser: boolean;
_dataChannels: Array<RTCDataChannel>;
_pcConfig: {
iceServers: Array<RTCIceServer>;
iceTransportPolicy: RTCIceTransportPolicy;
};
/**
* @ignore
*/
on(kind: string, callback: Function): void;
/**
* オブジェクトを生成し、リモートのピアまたはサーバーに接続します。
* @param signalingUrl シグナリングに利用する URL
* @param roomId Ayame のルームID
* @param options Ayame の接続オプション
* @param [debug=false] デバッグログの出力可否
* @param [isRelay=false] iceTransportPolicy を強制的に relay にするか
* @listens {open} Ayame Server に accept され、PeerConnection が生成されると送信されます。
* @listens {connect} PeerConnection が接続されると送信されます。
* @listens {disconnect} PeerConnection が切断されると送信されます。
* @listens {addstream} リモートのストリームが追加されると送信されます。
* @listens {removestream} リモートのストリームが削除されると送信されます。
* @listens {bye} Ayame Server から bye を受信すると送信されます。
*/
constructor(signalingUrl: string, roomId: string, options: ConnectionOptions, debug?: boolean, isRelay?: boolean);
_disconnect(): Promise<void>;
_signaling(): Promise<void>;
_createPeerConnection(): void;
_createDataChannel(label: string, options: RTCDataChannelInit | undefined): Promise<RTCDataChannel | null>;
_onDataChannel(event: RTCDataChannelEvent): void;
_sendOffer(): Promise<void>;
_isVideoCodecSpecified(): boolean;
_createAnswer(): Promise<void>;
_setAnswer(sessionDescription: RTCSessionDescription): Promise<void>;
_setOffer(sessionDescription: RTCSessionDescription): Promise<void>;
_addIceCandidate(candidate: RTCIceCandidate): Promise<void>;
_sendIceCandidate(candidate: RTCIceCandidate): void;
_sendSdp(sessionDescription: RTCSessionDescription): void;
_sendWs(message: Record<string, any>): void;
_getTransceiver(pc: RTCPeerConnection, track: any): RTCRtpTransceiver | null;
_findDataChannel(label: string): RTCDataChannel | undefined;
_closeDataChannel(dataChannel: RTCDataChannel): Promise<void>;
_closePeerConnection(): Promise<void>;
_closeWebSocketConnection(): Promise<void>;
_traceLog(title: string, message?: Record<string, any> | string): void;
}
export default ConnectionBase;
48 changes: 48 additions & 0 deletions dist/connection/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import ConnectionBase from './base';
import { ConnectionOptions, MetadataOption } from './options';
/**
* Peer Connection 接続を管理するクラスです。
*/
declare class Connection extends ConnectionBase {
/**
* @desc オブジェクトを生成し、リモートのピアまたはサーバーに接続します。
* @param {string} signalingUrl シグナリングに利用する URL
* @param {string} roomId Ayame のルームID
* @param {ConnectionOptions} options Ayame の接続オプション
* @param {boolean} [debug=false] デバッグログの出力可否
* @param {boolean} [isRelay=false] iceTransportPolicy を強制的に relay にするか
* @listens {open} Ayame Server に accept され、PeerConnection が生成されると送信されます。
* @listens {connect} PeerConnection が接続されると送信されます。
* @listens {disconnect} PeerConnection が切断されると送信されます。
* @listens {addstream} リモートのストリームが追加されると送信されます。
* @listens {removestream} リモートのストリームが削除されると送信されます。
*/
constructor(signalingUrl: string, roomId: string, options: ConnectionOptions, debug?: boolean, isRelay?: boolean);
/**
* @typedef {Object} MetadataOption - 接続時に指定できるメタデータです。
* @property {any} authnMetadata 送信するメタデータ
*/
/**
* @desc PeerConnection 接続を開始します。
* @param {MediaStream|null} [stream=null] - ローカルのストリーム
* @param {MetadataOption|null} [metadataOption=null] - 送信するメタデータ
*/
connect(stream: MediaStream | null, metadataOption?: MetadataOption | null): Promise<void>;
/**
* @desc Datachannel を作成します。
* @param {string} label - dataChannel の label
* @param {RTCDataChannelInit|undefined} [options=undefined] - dataChannel の init オプション
* @return {RTCDataChannel|null} 生成されたデータチャネル
*/
createDataChannel(label: string, options?: RTCDataChannelInit | undefined): Promise<RTCDataChannel | null>;
/**
* @desc Datachannel を削除します。
* @param {string} label - 削除する dataChannel の label
*/
removeDataChannel(label: string): Promise<void>;
/**
* @desc PeerConnection 接続を切断します。
*/
disconnect(): Promise<void>;
}
export default Connection;
59 changes: 59 additions & 0 deletions dist/connection/options.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
* @typedef {string} ConnectionDirection - オーディオ、ビデオの送受信方向に関するオプションです。
*
* - sendrecv
* - recvonly
* - sendonly
*/
export declare type ConnectionDirection = 'sendrecv' | 'recvonly' | 'sendonly';
/**
* @typedef {Object} ConnectionAudioOption - オーディオ接続に関するオプションです。
* @property {ConnectionDirection} direction 送受信方向
* @property {boolean} enabled 有効かどうかのフラグ
*/
export interface ConnectionAudioOption {
direction: ConnectionDirection;
enabled: boolean;
}
/**
* @public
* @typedef {string} VideoCodecOption - ビデオ接続のコーデックに関するオプションです。
*
* - VP8
* - VP9
* - H264
*/
export declare type VideoCodecOption = 'VP8' | 'VP9' | 'H264';
/**
* @typedef {Object} ConnectionVideoOption - ビデオ接続に関するオプションです。
* @property {VideoCodecOption} codec コーデックの設定
* @property {ConnectionDirection} direction 送受信方向
* @property {boolean} enabled 有効かどうかのフラグ
*/
export interface ConnectionVideoOption {
codec?: VideoCodecOption;
direction: ConnectionDirection;
enabled: boolean;
}
/**
* @typedef {Object} ConnectionOptions - 接続時に指定するオプションです。
* @property {ConnectionAudioOption} audio オーディオの設定
* @property {ConnectionVideoOption} video ビデオの設定
* @property {string} clientId クライアントID
* @property {Array.<RTCIceServer>} iceServers ayame server から iceServers が返って来なかった場合に使われる iceServer の情報
* @property {string} signalingKey 送信するシグナリングキー
*/
export interface ConnectionOptions {
audio: ConnectionAudioOption;
video: ConnectionVideoOption;
clientId: string;
iceServers: Array<RTCIceServer>;
signalingKey?: string;
}
/**
* @typedef {Object} MetadataOption - 接続時に指定できるメタデータです。
* @property {any} authnMetadata 送信するメタデータ
*/
export interface MetadataOption {
authnMetadata?: any;
}
19 changes: 19 additions & 0 deletions dist/utils.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { VideoCodecOption } from './connection/options';
/**
* @ignore
*/
export declare function randomString(strLength: number): string;
/**
* @ignore
*/
export declare function browser(): string;
/**
* @ignore
*/
export declare function traceLog(title: string, value?: string | Record<string, any>): void;
/** @private */
export declare function getVideoCodecsFromString(codec: VideoCodecOption, codecs: Array<any>): Array<any>;
/**
* @ignore
*/
export declare function removeCodec(sdp: string, codec: VideoCodecOption): string;
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"directories": {
"doc": "docs/"
},
"types": "dist/ayame.d.ts",
"homepage": "https://github.com/OpenAyame/ayame-web-sdk",
"author": "Shiguredo Inc.",
"license": "Apache-2.0",
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"sourceMap": true,
"declaration": true,
"baseUrl": ".",
"types": [
"webrtc",
Expand Down

0 comments on commit 865f72d

Please sign in to comment.