node-srt/types/srt-api-async.d.ts
Stephan Hesse 074da05097
Worker-based Async API with await/Promise support (or plain callbacks) (#6)
* fix lint errors in eslint config :)

* index.d.s: add /* eslint-disable @typescript-eslint/triple-slash-reference */

* improve eslint calling script

* add async-worker version of the SRT JS API with await/Promise support
+ potentially out-of-order RPC-back/result-dequeuing is possible
with a type of call-ID generator and callback-map that we prototyped
(but not used atm since the worker is only doing sync/blocking internally
with the current SRT lib binding).

* add various examples for async API ("classic" callbacks / Promise / await)

* add .eslintignore (should go with commit where we just call "eslint .")

* index.js: add missing semi

* async.js: fix method name litteral in epollUWait

* async.js: allow for accept method to use a timeout opt (defaults to false),
and a custom timeout value option (default to default timeout),
which can potentially be set differently than the general default timeout.
+ make the timeout value a static class property so that it can be
user-defined module-load wide. defaults to constant in module top scope.

* async.js: fix for a rejected promise, make sure we don't resolve anymore
+ add a custom timeout value argument to _createAsyncWorkPromise

* async.js: rm an experiment

* fix a lint error in example

* add types for async api and fix some details on binding API types

* export async API to index

* async.js: add some missing docs for private methods

* include async types in index
2020-08-03 09:54:26 +02:00

107 lines
2.6 KiB
TypeScript

declare module "srt" {
type AsyncSRTCallback<T> = (result: T) => void;
class AsyncSRT {
static TimeoutMs: number;
/**
*
* @param sender
* @returns SRTSOCKET identifier (integer value)
*/
createSocket(sender: boolean, callback?: AsyncSRTCallback<number>): Promise<number>
/**
*
* @param socket
* @param address
* @param port
*/
bind(socket: number, address: string, port: number, callback?: AsyncSRTCallback<SRTResult>): Promise<SRTResult>
/**
*
* @param socket
* @param backlog
*/
listen(socket: number, backlog: number, callback?: AsyncSRTCallback<SRTResult>): Promise<SRTResult>
/**
*
* @param socket
* @param host
* @param port
*/
connect(socket: number, host: string, port: number, callback?: AsyncSRTCallback<SRTResult>): Promise<SRTResult>
/**
*
* @param socket
* @returns File descriptor of incoming connection pipe
*/
accept(socket: number, callback?: AsyncSRTCallback<SRTFileDescriptor>): Promise<SRTFileDescriptor>
/**
*
* @param socket
*/
close(socket: number, callback?: AsyncSRTCallback<SRTResult>): Promise<SRTResult>
/**
*
* @param socket
* @param chunkSize
*/
read(socket: number, chunkSize: number, callback?: AsyncSRTCallback<SRTReadReturn>): Promise<SRTReadReturn>
/**
*
* @param socket
* @param chunk
*/
write(socket: number, chunk: Buffer, callback?: AsyncSRTCallback<SRTResult>): Promise<SRTResult>
/**
*
* @param socket
* @param option
* @param value
*/
setSockOpt(socket: number, option: SRTSockOpt, value: SRTSockOptValue, callback?: AsyncSRTCallback<SRTResult>): Promise<SRTResult>
/**
*
* @param socket
* @param option
*/
getSockOpt(socket: number, option: SRTSockOpt, callback?: AsyncSRTCallback<SRTSockOptValue>): Promise<SRTSockOptValue>
/**
*
* @param socket
*/
getSockState(socket: number, callback?: AsyncSRTCallback<SRTSockStatus>): Promise<SRTSockStatus>
/**
* @returns epid
*/
epollCreate(callback?: AsyncSRTCallback<number>): Promise<number>
/**
*
* @param epid
* @param socket
* @param events
*/
epollAddUsock(epid: number, socket: number, events: number, callback?: AsyncSRTCallback<SRTResult>): Promise<SRTResult>
/**
*
* @param epid
* @param msTimeOut
*/
epollUWait(epid: number, msTimeOut: number, callback?: AsyncSRTCallback<SRTEpollEvent[]>): Promise<SRTEpollEvent[]>
}
}