samchon / tgrid

TypeScript RPC (Remote Procedure Call) for WebSocket and Worker protocols
https://tgrid.com/
MIT License
146 stars 19 forks source link

Headers info when connecting to a web-socket server #35

Closed samchon closed 4 years ago

samchon commented 4 years ago

Add headers info when connecting to a web-socket server composed by the TGrid. The headers may include additional information like activation and web-socket server may decide whether to accept the connection or not by parsing the headers.

When the feature adding headers has been implemented, web-socket components WebConnector, WebAcceptor and WebServer would be changed like below. Also, this update may cause a critical change on the message protocol. Therefore, when the feature has been implemented, it can't be compatible with the previous versions.

export class WebConnector<Provider extends object>
{
    public connect<Headers extends object>(url: string, headers?: Headers): Promise<void>;
}

export class WebAcceptor<Headers extends object, Provider extends object>
{
    public get path(): string;
    public get state(): string;
    public get headers(): Headers;
}

export class WebServer<Provider extends object>
{
    public open<Headers extends object>
    (
        port: number, 
        handler: (acceptor: WebAcceptor<Headers, Provider>) => any
    ): Promise<void>;
}