From ac0e8f11ca86c38c44dcce622f97e666a056f6e7 Mon Sep 17 00:00:00 2001 From: BrennanConroy Date: Tue, 21 Aug 2018 14:47:43 -0700 Subject: [PATCH] Fix TS msgpack on IE and Ping breaking connection on server (#2847) --- .../src/MessagePackHubProtocol.ts | 5 +++-- .../tests/MessagePackHubProtocol.test.ts | 12 +++++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/clients/ts/signalr-protocol-msgpack/src/MessagePackHubProtocol.ts b/clients/ts/signalr-protocol-msgpack/src/MessagePackHubProtocol.ts index 269e003f4a..123abd68f3 100644 --- a/clients/ts/signalr-protocol-msgpack/src/MessagePackHubProtocol.ts +++ b/clients/ts/signalr-protocol-msgpack/src/MessagePackHubProtocol.ts @@ -12,7 +12,8 @@ import { BinaryMessageFormat } from "./BinaryMessageFormat"; // constant encoding of the ping message // see: https://github.com/aspnet/SignalR/blob/dev/specs/HubProtocol.md#ping-message-encoding-1 -const SERIALIZED_PING_MESSAGE: ArrayBuffer = Uint8Array.from([0x91, MessageType.Ping]).buffer; +// Don't use Uint8Array.from as IE does not support it +const SERIALIZED_PING_MESSAGE: Uint8Array = new Uint8Array([0x91, MessageType.Ping]); /** Implements the MessagePack Hub Protocol */ export class MessagePackHubProtocol implements IHubProtocol { @@ -67,7 +68,7 @@ export class MessagePackHubProtocol implements IHubProtocol { case MessageType.Completion: throw new Error(`Writing messages of type '${message.type}' is not supported.`); case MessageType.Ping: - return SERIALIZED_PING_MESSAGE; + return BinaryMessageFormat.write(SERIALIZED_PING_MESSAGE); default: throw new Error("Invalid message type."); } diff --git a/clients/ts/signalr-protocol-msgpack/tests/MessagePackHubProtocol.test.ts b/clients/ts/signalr-protocol-msgpack/tests/MessagePackHubProtocol.test.ts index 8f70a7c796..e22dc33fe5 100644 --- a/clients/ts/signalr-protocol-msgpack/tests/MessagePackHubProtocol.test.ts +++ b/clients/ts/signalr-protocol-msgpack/tests/MessagePackHubProtocol.test.ts @@ -4,7 +4,7 @@ import { CompletionMessage, InvocationMessage, MessageType, NullLogger, StreamItemMessage } from "@aspnet/signalr"; import { MessagePackHubProtocol } from "../src/MessagePackHubProtocol"; -describe("MessageHubProtocol", () => { +describe("MessagePackHubProtocol", () => { it("can write/read non-blocking Invocation message", () => { const invocation = { arguments: [42, true, "test", ["x1", "y2"], null], @@ -188,4 +188,14 @@ describe("MessageHubProtocol", () => { }, ]); }); + + it("can write ping message", () => { + const payload = new Uint8Array([ + 0x02, // length prefix + 0x91, // message array length = 1 (fixarray) + 0x06, // type = 6 = Ping (fixnum) + ]); + const buffer = new MessagePackHubProtocol().writeMessage({ type: MessageType.Ping }); + expect(new Uint8Array(buffer)).toEqual(payload); + }); });