Skip to content

Commit

Permalink
Fix TS msgpack on IE and Ping breaking connection on server (#2847)
Browse files Browse the repository at this point in the history
  • Loading branch information
BrennanConroy authored Aug 21, 2018
1 parent 60d617c commit ac0e8f1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down Expand Up @@ -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);
});
});

0 comments on commit ac0e8f1

Please sign in to comment.