Skip to content
This repository has been archived by the owner on Dec 18, 2018. It is now read-only.

Commit

Permalink
[TS] Change websocket library in Node (#2989)
Browse files Browse the repository at this point in the history
  • Loading branch information
BrennanConroy authored Sep 21, 2018
1 parent 4dfd93c commit ef3d3b1
Show file tree
Hide file tree
Showing 13 changed files with 99 additions and 145 deletions.
118 changes: 51 additions & 67 deletions clients/ts/FunctionalTests/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion clients/ts/FunctionalTests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"karma-summary-reporter": "^1.5.0",
"ts-node": "^4.1.0",
"typescript": "^3.0.1",
"websocket": " ^1.0.26"
"ws": " ^6.0.0"
},
"scripts": {
"clean": "node ../common/node_modules/rimraf/bin.js ./wwwroot/dist ./obj/js",
Expand Down
7 changes: 3 additions & 4 deletions clients/ts/FunctionalTests/ts/WebSocketTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ describe("WebSockets", () => {
return;
}
} else {
const websocketModule = require("websocket");
const hasWebsocket = websocketModule && websocketModule.w3cwebsocket;
if (hasWebsocket) {
webSocket = new websocketModule.w3cwebsocket(ECHOENDPOINT_URL.replace(/^http/, "ws"));
const websocketModule = require("ws");
if (websocketModule) {
webSocket = new websocketModule(ECHOENDPOINT_URL.replace(/^http/, "ws"));
} else {
// No WebSockets implementations in current environment, skip test
done();
Expand Down
2 changes: 1 addition & 1 deletion clients/ts/signalr-protocol-msgpack/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import * as msgpack5 from "msgpack5";
import { CompletionMessage, HubMessage, IHubProtocol, ILogger, InvocationMessage, LogLevel, MessageHeaders, MessageType, NullLogger, StreamInvocationMessage, StreamItemMessage, TransferFormat } from "@aspnet/signalr";

import { BinaryMessageFormat } from "./BinaryMessageFormat";
import { isArrayBuffer } from "./Utils";

// TypeDoc's @inheritDoc and @link don't work across modules :(

Expand All @@ -31,7 +32,7 @@ export class MessagePackHubProtocol implements IHubProtocol {
*/
public parseMessages(input: ArrayBuffer | Buffer, logger: ILogger): HubMessage[] {
// The interface does allow "string" to be passed in, but this implementation does not. So let's throw a useful error.
if (!(input instanceof ArrayBuffer) && !(input instanceof Buffer)) {
if (!(input instanceof Buffer) && !(isArrayBuffer(input))) {
throw new Error("Invalid input for MessagePack hub protocol. Expected an ArrayBuffer or Buffer.");
}

Expand Down
11 changes: 11 additions & 0 deletions clients/ts/signalr-protocol-msgpack/src/Utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

// Copied from signalr/Utils.ts
/** @private */
export function isArrayBuffer(val: any): val is ArrayBuffer {
return val && typeof ArrayBuffer !== "undefined" &&
(val instanceof ArrayBuffer ||
// Sometimes we get an ArrayBuffer that doesn't satisfy instanceof
(val.constructor && val.constructor.name === "ArrayBuffer"));
}
Loading

0 comments on commit ef3d3b1

Please sign in to comment.