Fix TS msgpack on IE and Ping breaking connection on server (#2847)
This commit is contained in:
parent
60d617c5ac
commit
ac0e8f11ca
|
|
@ -12,7 +12,8 @@ import { BinaryMessageFormat } from "./BinaryMessageFormat";
|
||||||
|
|
||||||
// constant encoding of the ping message
|
// constant encoding of the ping message
|
||||||
// see: https://github.com/aspnet/SignalR/blob/dev/specs/HubProtocol.md#ping-message-encoding-1
|
// 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 */
|
/** Implements the MessagePack Hub Protocol */
|
||||||
export class MessagePackHubProtocol implements IHubProtocol {
|
export class MessagePackHubProtocol implements IHubProtocol {
|
||||||
|
|
@ -67,7 +68,7 @@ export class MessagePackHubProtocol implements IHubProtocol {
|
||||||
case MessageType.Completion:
|
case MessageType.Completion:
|
||||||
throw new Error(`Writing messages of type '${message.type}' is not supported.`);
|
throw new Error(`Writing messages of type '${message.type}' is not supported.`);
|
||||||
case MessageType.Ping:
|
case MessageType.Ping:
|
||||||
return SERIALIZED_PING_MESSAGE;
|
return BinaryMessageFormat.write(SERIALIZED_PING_MESSAGE);
|
||||||
default:
|
default:
|
||||||
throw new Error("Invalid message type.");
|
throw new Error("Invalid message type.");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
import { CompletionMessage, InvocationMessage, MessageType, NullLogger, StreamItemMessage } from "@aspnet/signalr";
|
import { CompletionMessage, InvocationMessage, MessageType, NullLogger, StreamItemMessage } from "@aspnet/signalr";
|
||||||
import { MessagePackHubProtocol } from "../src/MessagePackHubProtocol";
|
import { MessagePackHubProtocol } from "../src/MessagePackHubProtocol";
|
||||||
|
|
||||||
describe("MessageHubProtocol", () => {
|
describe("MessagePackHubProtocol", () => {
|
||||||
it("can write/read non-blocking Invocation message", () => {
|
it("can write/read non-blocking Invocation message", () => {
|
||||||
const invocation = {
|
const invocation = {
|
||||||
arguments: [42, true, "test", ["x1", "y2"], null],
|
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);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue