2019-02-06 16:49:29 +00:00
|
|
|
import * as net from "net";
|
|
|
|
import { Client } from "@coder/protocol";
|
2019-01-19 00:04:24 +00:00
|
|
|
import { client } from "./client";
|
2019-01-14 20:58:34 +00:00
|
|
|
|
2019-02-06 16:49:29 +00:00
|
|
|
type NodeNet = typeof net;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implementation of net for the browser.
|
|
|
|
*/
|
|
|
|
class Net implements NodeNet {
|
|
|
|
public constructor(
|
|
|
|
private readonly client: Client,
|
|
|
|
) {}
|
|
|
|
|
|
|
|
public get Socket(): typeof net.Socket {
|
|
|
|
return this.client.Socket;
|
|
|
|
}
|
|
|
|
|
|
|
|
public get Server(): typeof net.Server {
|
|
|
|
throw new Error("not implemented");
|
|
|
|
}
|
|
|
|
|
|
|
|
public connect(): net.Socket {
|
|
|
|
throw new Error("not implemented");
|
|
|
|
}
|
|
|
|
|
|
|
|
public createConnection(target: string | number | net.NetConnectOpts, host?: string | Function, callback?: Function): net.Socket {
|
|
|
|
if (typeof target === "object") {
|
|
|
|
throw new Error("not implemented");
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.client.createConnection(target, typeof host === "function" ? host : callback) as net.Socket;
|
|
|
|
}
|
|
|
|
|
|
|
|
public isIP(_input: string): number {
|
|
|
|
throw new Error("not implemented");
|
|
|
|
}
|
|
|
|
|
|
|
|
public isIPv4(_input: string): boolean {
|
|
|
|
throw new Error("not implemented");
|
|
|
|
}
|
|
|
|
|
|
|
|
public isIPv6(_input: string): boolean {
|
|
|
|
throw new Error("not implemented");
|
|
|
|
}
|
|
|
|
|
|
|
|
public createServer(
|
|
|
|
_options?: { allowHalfOpen?: boolean, pauseOnConnect?: boolean } | ((socket: net.Socket) => void),
|
|
|
|
_connectionListener?: (socket: net.Socket) => void,
|
|
|
|
): net.Server {
|
|
|
|
return this.client.createServer() as net.Server;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-19 00:04:24 +00:00
|
|
|
export = new Net(client);
|