TeaSpeak-Client/native/serverconnection/exports/exports.d.ts

278 lines
9.1 KiB
TypeScript
Raw Normal View History

declare module "tc-native/connection" {
2019-10-25 19:51:40 -04:00
export enum ServerType {
UNKNOWN,
TEASPEAK,
TEAMSPEAK
}
export enum PlayerState {
BUFFERING,
PLAYING,
STOPPING,
STOPPED
}
export interface NativeVoiceClient {
client_id: number;
callback_playback: () => any;
callback_stopped: () => any;
callback_state_changed: (new_state: PlayerState) => any;
get_state() : PlayerState;
get_volume() : number;
set_volume(volume: number) : void;
abort_replay();
get_stream() : audio.playback.AudioOutputStream;
}
export interface NativeVoiceConnection {
register_client(client_id: number) : NativeVoiceClient;
available_clients() : NativeVoiceClient[];
unregister_client(client_id: number);
audio_source() : audio.record.AudioConsumer;
set_audio_source(consumer: audio.record.AudioConsumer | undefined);
decoding_supported(codec: number) : boolean;
encoding_supported(codec: number) : boolean;
get_encoder_codec() : number;
set_encoder_codec(codec: number);
/* could may throw an exception when the underlying voice sender has been deallocated */
enable_voice_send(flag: boolean);
}
export interface NativeServerConnection {
callback_voice_data: (buffer: Uint8Array, client_id: number, codec_id: number, flag_head: boolean, packet_id: number) => any;
callback_command: (command: string, arguments: any, switches: string[]) => any;
callback_disconnect: (reason?: string) => any;
_voice_connection: NativeVoiceConnection;
server_type: ServerType;
connected(): boolean;
connect(properties: {
remote_host: string,
remote_port: number,
timeout: number,
callback: (error: number) => any,
identity_key: string | undefined, /* if identity_key empty, then an ephemeral license will be created */
teamspeak: boolean
});
disconnect(reason: string | undefined, callback: (error: number) => any) : boolean;
error_message(id: number) : string;
send_command(command: string, arguments: any[], switches: string[]);
send_voice_data(buffer: Uint8Array, codec_id: number, header: boolean);
send_voice_data_raw(buffer: Float32Array, channels: number, sample_rate: number, header: boolean);
/* ping in microseconds */
current_ping() : number;
}
export function spawn_server_connection() : NativeServerConnection;
export function destroy_server_connection(connection: NativeServerConnection);
export namespace ft {
export interface TransferObject {
name: string;
direction: "upload" | "download";
}
export interface FileTransferSource extends TransferObject {
total_size: number;
}
export interface FileTransferTarget extends TransferObject {
expected_size: number;
}
export interface NativeFileTransfer {
handle: TransferObject;
callback_finished: (aborted?: boolean) => any;
callback_start: () => any;
callback_progress: (current: number, max: number) => any;
callback_failed: (message: string) => any;
2019-10-29 13:11:47 -04:00
/**
* @return true if the connect method has been executed successfully
* false if the connect fails, callback_failed will be called with the exact reason
*/
start() : boolean;
2019-10-25 19:51:40 -04:00
}
export interface TransferOptions {
remote_address: string;
remote_port: number;
transfer_key: string;
client_transfer_id: number;
server_transfer_id: number;
object: TransferObject;
}
export function upload_transfer_object_from_file(path: string, name: string) : FileTransferSource;
export function upload_transfer_object_from_buffer(buffer: ArrayBuffer) : FileTransferSource;
export function download_transfer_object_from_buffer(target_buffer: ArrayBuffer) : FileTransferTarget;
export function download_transfer_object_from_file(path: string, name: string, expectedSize: number) : FileTransferTarget;
2019-10-25 19:51:40 -04:00
export function destroy_connection(connection: NativeFileTransfer);
export function spawn_connection(transfer: TransferOptions) : NativeFileTransfer;
}
export namespace audio {
export interface AudioDevice {
name: string;
driver: string;
device_id: string;
input_supported: boolean;
output_supported: boolean;
input_default: boolean;
output_default: boolean;
}
export namespace playback {
export interface AudioOutputStream {
sample_rate: number;
channels: number;
get_buffer_latency() : number;
set_buffer_latency(value: number);
get_buffer_max_latency() : number;
set_buffer_max_latency(value: number);
flush_buffer();
2019-10-25 19:51:40 -04:00
}
export interface OwnedAudioOutputStream extends AudioOutputStream {
callback_underflow: () => any;
callback_overflow: () => any;
clear();
write_data(buffer: ArrayBuffer, interleaved: boolean);
write_data_rated(buffer: ArrayBuffer, interleaved: boolean, sample_rate: number);
deleted() : boolean;
delete();
}
2020-02-08 10:50:48 -05:00
export function set_device(device_id: string);
export function current_device() : string;
2019-10-25 19:51:40 -04:00
export function create_stream() : OwnedAudioOutputStream;
export function get_master_volume() : number;
export function set_master_volume(volume: number);
}
export namespace record {
export interface ConsumeFilter {
get_name() : string;
}
export interface MarginedFilter {
2020-04-16 07:12:00 -04:00
/* in seconds */
get_margin_time() : number;
set_margin_time(value: number);
2019-10-25 19:51:40 -04:00
}
export interface VADConsumeFilter extends ConsumeFilter, MarginedFilter {
get_level() : number;
}
export interface ThresholdConsumeFilter extends ConsumeFilter, MarginedFilter {
get_threshold() : number;
set_threshold(value: number);
get_attack_smooth() : number;
set_attack_smooth(value: number);
get_release_smooth() : number;
set_release_smooth(value: number);
set_analyze_filter(callback: (value: number) => any);
}
export interface StateConsumeFilter extends ConsumeFilter {
is_consuming() : boolean;
set_consuming(flag: boolean);
}
export interface AudioConsumer {
sample_rate: number;
channels: number;
frame_size: number;
/* TODO add some kind of order to may improve CPU performance (Some filters are more intense then others) */
get_filters() : ConsumeFilter[];
unregister_filter(filter: ConsumeFilter);
create_filter_vad(level: number) : VADConsumeFilter;
create_filter_threshold(threshold: number) : ThresholdConsumeFilter;
create_filter_state() : StateConsumeFilter;
callback_data: (buffer: Float32Array) => any;
callback_ended: () => any;
callback_started: () => any;
}
export interface AudioRecorder {
2020-02-08 10:50:48 -05:00
get_device() : string;
set_device(device_id: string, callback: () => void); /* Recorder needs to be started afterwards */
2019-10-25 19:51:40 -04:00
2020-02-08 10:50:48 -05:00
start(callback: (result: boolean | string) => void);
2019-10-25 19:51:40 -04:00
started() : boolean;
stop();
get_volume() : number;
set_volume(volume: number);
create_consumer() : AudioConsumer;
get_consumers() : AudioConsumer[];
delete_consumer(consumer: AudioConsumer);
}
export function create_recorder() : AudioRecorder;
}
2020-03-18 18:32:57 -04:00
export namespace sounds {
export enum PlaybackResult {
SUCCEEDED,
CANCELED,
SOUND_NOT_INITIALIZED,
FILE_OPEN_ERROR,
PLAYBACK_ERROR
}
export interface PlaybackSettings {
file: string;
volume?: number;
callback?: (result: PlaybackResult, message: string) => void;
}
export function playback_sound(settings: PlaybackSettings) : number;
export function cancel_playback(playback: number);
}
2020-02-08 10:50:48 -05:00
export function initialize(callback: () => any);
export function initialized() : boolean;
2019-10-25 19:51:40 -04:00
export function available_devices() : AudioDevice[];
}
}