mirror of
https://github.com/yudai/gotty.git
synced 2026-03-06 22:00:17 +01:00
Add xterm itegration
* Move to TypeScript from legacy JavaScript * Add support of xterm.js * Hterm is still available for backward compatibility
This commit is contained in:
parent
d6c98866b9
commit
8803721f3d
40 changed files with 9051 additions and 124 deletions
60
js/src/websocket.ts
Normal file
60
js/src/websocket.ts
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
export class ConnectionFactory {
|
||||
url: string;
|
||||
protocols: string[];
|
||||
|
||||
constructor(url: string, protocols: string[]) {
|
||||
this.url = url;
|
||||
this.protocols = protocols;
|
||||
};
|
||||
|
||||
create(): Connection {
|
||||
return new Connection(this.url, this.protocols);
|
||||
};
|
||||
}
|
||||
|
||||
export class Connection {
|
||||
bare: WebSocket;
|
||||
|
||||
|
||||
constructor(url: string, protocols: string[]) {
|
||||
this.bare = new WebSocket(url, protocols);
|
||||
}
|
||||
|
||||
open() {
|
||||
// nothing todo for websocket
|
||||
};
|
||||
|
||||
close() {
|
||||
this.bare.close();
|
||||
};
|
||||
|
||||
send(data: string) {
|
||||
this.bare.send(data);
|
||||
};
|
||||
|
||||
isOpen(): boolean {
|
||||
if (this.bare.readyState == WebSocket.CONNECTING ||
|
||||
this.bare.readyState == WebSocket.OPEN) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
onOpen(callback: () => void) {
|
||||
this.bare.onopen = (event) => {
|
||||
callback();
|
||||
}
|
||||
};
|
||||
|
||||
onReceive(callback: (data: string) => void) {
|
||||
this.bare.onmessage = (event) => {
|
||||
callback(event.data);
|
||||
}
|
||||
};
|
||||
|
||||
onClose(callback: () => void) {
|
||||
this.bare.onclose = (event) => {
|
||||
callback();
|
||||
};
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue