Skip to content

Commit 05da12e

Browse files
committed
Fix websocket types
1 parent 570622c commit 05da12e

File tree

4 files changed

+22
-8
lines changed

4 files changed

+22
-8
lines changed

node-client/package-lock.json

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node-client/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"@types/node": "^8.0.2",
2828
"@types/request": "^2.47.0",
2929
"@types/underscore": "^1.8.1",
30+
"@types/websocket": "0.0.38",
3031
"base-64": "^0.1.0",
3132
"bluebird": "^3.3.5",
3233
"byline": "^5.0.0",

node-client/src/exec.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import querystring = require('querystring');
22
import stream = require('stream');
3+
import ws = require('websocket');
34

45
import { WebSocketHandler } from './web-socket-handler';
56
import { KubeConfig } from './config';
@@ -9,10 +10,10 @@ export class Exec {
910

1011
public constructor(config: KubeConfig) {
1112
this.handler = new WebSocketHandler(config);
12-
}
13+
}
1314

1415
// TODO: make command an array and support multiple args
15-
public async exec(namespace: string, podName: string, containerName: string, command: string, stdout: stream.Writable | any, stderr: stream.Writable | any, stdin: stream.Readable | any, tty: boolean): Promise<WebSocket> {
16+
public async exec(namespace: string, podName: string, containerName: string, command: string, stdout: stream.Writable | any, stderr: stream.Writable | any, stdin: stream.Readable | any, tty: boolean): Promise<ws.connection> {
1617
var query = {
1718
stdout: stdout != null,
1819
stderr: stderr != null,
@@ -29,6 +30,6 @@ export class Exec {
2930
if (stdin != null) {
3031
WebSocketHandler.handleStandardInput(conn, stdin);
3132
}
32-
return conn as WebSocket;
33+
return conn;
3334
}
3435
}

node-client/src/web-socket-handler.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,8 @@ export class WebSocketHandler {
3131
const server = this.config.getCurrentCluster().server;
3232
const target = server.startsWith('https://') ? server.substr(8) : server.substr(7);
3333
const uri = `wss://${target}${path}`;
34-
const opts = { uri };
3534

36-
this.config.applyToRequest(opts);
37-
let client = new ws.client({ 'tlsOptions': opts });
35+
const client = new ws.client();
3836

3937
return new Promise((resolve, reject) => {
4038
client.on('connect', (connection) => {
@@ -46,7 +44,7 @@ export class WebSocketHandler {
4644
}
4745
else if (message.type === 'binary') {
4846
if (binaryHandler) {
49-
let stream = message.binaryData.readInt8();
47+
let stream = message.binaryData.readInt8(0);
5048
binaryHandler(stream, message.binaryData.slice(1));
5149
}
5250
}
@@ -98,7 +96,7 @@ export class WebSocketHandler {
9896
});
9997

10098
stdin.on('end', () => {
101-
conn.close(ws.connection.CLOSE_REASON_NORMAL);
99+
conn.close();
102100
});
103101
}
104102
}

0 commit comments

Comments
 (0)