Getting the client to run (#12)
* Clean up workbench and integrate initialization data * Uncomment Electron fill * Run server & client together * Clean up Electron fill & patch * Bind fs methods This makes them usable with the promise form: `promisify(access)(...)`. * Add space between tag and title to browser logger * Add typescript dep to server and default __dirname for path * Serve web files from server * Adjust some dev options * Rework workbench a bit to use a class and catch unexpected errors * No mkdirs for now, fix util fill, use bash with exec * More fills, make general client abstract * More fills * Fix cp.exec * Fix require calls in fs fill being aliased * Create data and storage dir * Implement fs.watch Using exec for now. * Implement storage database fill * Fix os export and homedir * Add comment to use navigator.sendBeacon * Fix fs callbacks (some args are optional) * Make sure data directory exists when passing it back * Update patch * Target es5 * More fills * Add APIs required for bootstrap-fork to function (#15) * Add bootstrap-fork execution * Add createConnection * Bundle bootstrap-fork into cli * Remove .node directory created from spdlog * Fix npm start * Remove unnecessary comment * Add webpack-hot-middleware if CLI env is not set * Add restarting to shared process * Fix starting with yarn
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import * as events from "events";
|
||||
import * as stream from "stream";
|
||||
import { SendableConnection } from "../common/connection";
|
||||
import { ShutdownSessionMessage, ClientMessage, SessionOutputMessage, WriteToSessionMessage, ResizeSessionTTYMessage, TTYDimensions as ProtoTTYDimensions } from "../proto";
|
||||
import { ShutdownSessionMessage, ClientMessage, WriteToSessionMessage, ResizeSessionTTYMessage, TTYDimensions as ProtoTTYDimensions, ConnectionOutputMessage, ConnectionCloseMessage } from "../proto";
|
||||
|
||||
export interface TTYDimensions {
|
||||
readonly columns: number;
|
||||
@@ -33,8 +33,8 @@ export interface ChildProcess {
|
||||
|
||||
export class ServerProcess extends events.EventEmitter implements ChildProcess {
|
||||
public readonly stdin = new stream.Writable();
|
||||
public readonly stdout = new stream.Readable({ read: () => true });
|
||||
public readonly stderr = new stream.Readable({ read: () => true });
|
||||
public readonly stdout = new stream.Readable({ read: (): boolean => true });
|
||||
public readonly stderr = new stream.Readable({ read: (): boolean => true });
|
||||
public pid: number | undefined;
|
||||
|
||||
private _killed: boolean = false;
|
||||
@@ -42,7 +42,7 @@ export class ServerProcess extends events.EventEmitter implements ChildProcess {
|
||||
public constructor(
|
||||
private readonly connection: SendableConnection,
|
||||
private readonly id: number,
|
||||
private readonly hasTty: boolean = false,
|
||||
private readonly hasTty: boolean = false,
|
||||
) {
|
||||
super();
|
||||
|
||||
@@ -77,7 +77,7 @@ export class ServerProcess extends events.EventEmitter implements ChildProcess {
|
||||
this.connection.send(client.serializeBinary());
|
||||
}
|
||||
|
||||
public resize(dimensions: TTYDimensions) {
|
||||
public resize(dimensions: TTYDimensions): void {
|
||||
const resize = new ResizeSessionTTYMessage();
|
||||
resize.setId(this.id);
|
||||
const tty = new ProtoTTYDimensions();
|
||||
@@ -89,3 +89,129 @@ export class ServerProcess extends events.EventEmitter implements ChildProcess {
|
||||
this.connection.send(client.serializeBinary());
|
||||
}
|
||||
}
|
||||
|
||||
export interface Socket {
|
||||
readonly destroyed: boolean;
|
||||
readonly connecting: boolean;
|
||||
write(buffer: Buffer): void;
|
||||
end(): void;
|
||||
|
||||
addListener(event: "data", listener: (data: Buffer) => void): this;
|
||||
addListener(event: "close", listener: (hasError: boolean) => void): this;
|
||||
addListener(event: "connect", listener: () => void): this;
|
||||
addListener(event: "end", listener: () => void): this;
|
||||
|
||||
on(event: "data", listener: (data: Buffer) => void): this;
|
||||
on(event: "close", listener: (hasError: boolean) => void): this;
|
||||
on(event: "connect", listener: () => void): this;
|
||||
on(event: "end", listener: () => void): this;
|
||||
|
||||
once(event: "data", listener: (data: Buffer) => void): this;
|
||||
once(event: "close", listener: (hasError: boolean) => void): this;
|
||||
once(event: "connect", listener: () => void): this;
|
||||
once(event: "end", listener: () => void): this;
|
||||
|
||||
removeListener(event: "data", listener: (data: Buffer) => void): this;
|
||||
removeListener(event: "close", listener: (hasError: boolean) => void): this;
|
||||
removeListener(event: "connect", listener: () => void): this;
|
||||
removeListener(event: "end", listener: () => void): this;
|
||||
|
||||
emit(event: "data", data: Buffer): boolean;
|
||||
emit(event: "close"): boolean;
|
||||
emit(event: "connect"): boolean;
|
||||
emit(event: "end"): boolean;
|
||||
}
|
||||
|
||||
|
||||
export class ServerSocket extends events.EventEmitter implements Socket {
|
||||
|
||||
public writable: boolean = true;
|
||||
public readable: boolean = true;
|
||||
|
||||
private _destroyed: boolean = false;
|
||||
private _connecting: boolean = true;
|
||||
|
||||
public constructor(
|
||||
private readonly connection: SendableConnection,
|
||||
private readonly id: number,
|
||||
connectCallback?: () => void,
|
||||
) {
|
||||
super();
|
||||
|
||||
if (connectCallback) {
|
||||
this.once("connect", () => {
|
||||
this._connecting = false;
|
||||
connectCallback();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public get destroyed(): boolean {
|
||||
return this._destroyed;
|
||||
}
|
||||
|
||||
public get connecting(): boolean {
|
||||
return this._connecting;
|
||||
}
|
||||
|
||||
public write(buffer: Buffer): void {
|
||||
const sendData = new ConnectionOutputMessage();
|
||||
sendData.setId(this.id);
|
||||
sendData.setData(buffer);
|
||||
const client = new ClientMessage();
|
||||
client.setConnectionOutput(sendData);
|
||||
this.connection.send(client.serializeBinary());
|
||||
}
|
||||
|
||||
public end(): void {
|
||||
const closeMsg = new ConnectionCloseMessage();
|
||||
closeMsg.setId(this.id);
|
||||
const client = new ClientMessage();
|
||||
client.setConnectionClose(closeMsg);
|
||||
this.connection.send(client.serializeBinary());
|
||||
}
|
||||
|
||||
public addListener(event: "data", listener: (data: Buffer) => void): this;
|
||||
public addListener(event: "close", listener: (hasError: boolean) => void): this;
|
||||
public addListener(event: "connect", listener: () => void): this;
|
||||
public addListener(event: "end", listener: () => void): this;
|
||||
public addListener(event: string, listener: any): this {
|
||||
return super.addListener(event, listener);
|
||||
}
|
||||
|
||||
public removeListener(event: "data", listener: (data: Buffer) => void): this;
|
||||
public removeListener(event: "close", listener: (hasError: boolean) => void): this;
|
||||
public removeListener(event: "connect", listener: () => void): this;
|
||||
public removeListener(event: "end", listener: () => void): this;
|
||||
public removeListener(event: string, listener: any): this {
|
||||
return super.removeListener(event, listener);
|
||||
}
|
||||
|
||||
public on(event: "data", listener: (data: Buffer) => void): this;
|
||||
public on(event: "close", listener: (hasError: boolean) => void): this;
|
||||
public on(event: "connect", listener: () => void): this;
|
||||
public on(event: "end", listener: () => void): this;
|
||||
public on(event: string, listener: any): this {
|
||||
return super.on(event, listener);
|
||||
}
|
||||
|
||||
public once(event: "data", listener: (data: Buffer) => void): this;
|
||||
public once(event: "close", listener: (hasError: boolean) => void): this;
|
||||
public once(event: "connect", listener: () => void): this;
|
||||
public once(event: "end", listener: () => void): this;
|
||||
public once(event: string, listener: any): this {
|
||||
return super.once(event, listener);
|
||||
}
|
||||
|
||||
public emit(event: "data", data: Buffer): boolean;
|
||||
public emit(event: "close"): boolean;
|
||||
public emit(event: "connect"): boolean;
|
||||
public emit(event: "end"): boolean;
|
||||
public emit(event: string, ...args: any[]): boolean {
|
||||
return super.emit(event, ...args);
|
||||
}
|
||||
|
||||
public setDefaultEncoding(encoding: string): this {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user