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

Commit

Permalink
Making the client and tests work on IE
Browse files Browse the repository at this point in the history
  • Loading branch information
Pawel Kadluczka committed Aug 29, 2017
1 parent ff2bf5a commit 2a36aa1
Show file tree
Hide file tree
Showing 9 changed files with 188 additions and 226 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class Base64EncodedHubProtocol implements IHubProtocol {
parseMessages(input: any): HubMessage[] {
// The format of the message is `size:message;`
let pos = input.indexOf(":");
if (pos == -1 || !input.endsWith(";")) {
if (pos == -1 || input[input.length - 1] != ';') {
throw new Error("Invalid payload.");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export namespace TextMessageFormat {
}

export function parse(input: string): string[] {
if (!input.endsWith(RecordSeparator)) {
if (input[input.length - 1] != RecordSeparator) {
throw new Error("Message is incomplete.");
}

Expand Down Expand Up @@ -57,7 +57,10 @@ export namespace BinaryMessageFormat {
}

if (uint8Array.byteLength >= (offset + 8 + size)) {
result.push(uint8Array.slice(offset + 8, offset + 8 + size))
// IE does not support .slice() so use subarray
result.push(uint8Array.slice
? uint8Array.slice(offset + 8, offset + 8 + size)
: uint8Array.subarray(offset + 8, offset + 8 + size));
}
else {
throw new Error("Incomplete message");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,10 @@ export class HubConnection {
case MessageType.Completion:
let callback = this.callbacks.get(message.invocationId);
if (callback != null) {
callback(message);

if (message.type == MessageType.Completion) {
this.callbacks.delete(message.invocationId);
}
callback(message);
}
break;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,6 @@ export class LongPollingTransport implements ITransport {
}

let pollXhr = new XMLHttpRequest();
if (transferMode === TransferMode.Binary) {
pollXhr.responseType = "arraybuffer";
}

pollXhr.onload = () => {
if (pollXhr.status == 200) {
Expand Down Expand Up @@ -248,6 +245,11 @@ export class LongPollingTransport implements ITransport {

this.pollXhr = pollXhr;
this.pollXhr.open("GET", url, true);
if (transferMode === TransferMode.Binary) {
this.pollXhr.responseType = "arraybuffer";
}
// IE caches xhr requests
this.pollXhr.setRequestHeader("Cache-Control", "no-cache");
// TODO: consider making timeout configurable
this.pollXhr.timeout = 120000;
this.pollXhr.send();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
<script type="text/javascript" src="lib/jasmine/jasmine.js"></script>
<script type="text/javascript" src="lib/jasmine/jasmine-html.js"></script>
<script type="text/javascript" src="lib/jasmine/boot.js"></script>
<script type="text/javascript" src="lib/signalr/signalr-client.min.js"></script>
<script type="text/javascript" src="lib/signalr/signalr-msgpackprotocol.min.js"></script>
<script type="text/javascript" src="lib/signalr/signalr-clientES5.min.js"></script>
<script type="text/javascript" src="lib/signalr/signalr-msgpackprotocolES5.min.js"></script>
<script src="js/common.js"></script>
<script src="js/webSocketTests.js"></script>
<script src="js/connectionTests.js"></script>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
const ECHOENDPOINT_URL = `http://${document.location.host}/echo`;
"use strict";

var ECHOENDPOINT_URL = "http://" + document.location.host + "/echo";

function getTransportTypes() {
let transportTypes = [ signalR.TransportType.WebSockets ];
if (typeof (EventSource) !== "undefined") {
var transportTypes = [signalR.TransportType.WebSockets];
if (typeof EventSource !== "undefined") {
transportTypes.push(signalR.TransportType.ServerSentEvents);
}
transportTypes.push(signalR.TransportType.LongPolling);
Expand All @@ -11,14 +13,16 @@ function getTransportTypes() {
}

function eachTransport(action) {
getTransportTypes().forEach(t => action(t));
getTransportTypes().forEach(function (t) {
return action(t);
});
}

function eachTransportAndProtocol(action) {
let protocols = [
new signalR.JsonHubProtocol(),
new signalRMsgPack.MessagePackHubProtocol()
];
getTransportTypes().forEach(t =>
protocols.forEach(p => action(t, p)));
}
var protocols = [new signalR.JsonHubProtocol(), new signalRMsgPack.MessagePackHubProtocol()];
getTransportTypes().forEach(function (t) {
return protocols.forEach(function (p) {
return action(t, p);
});
});
}
Original file line number Diff line number Diff line change
@@ -1,61 +1,58 @@
describe('connection', () => {
it(`can connect to the server without specifying transport explicitly`, done => {
const message = "Hello World!";
let connection = new signalR.HttpConnection(ECHOENDPOINT_URL);
"use strict";

let received = "";
connection.onDataReceived = data => {
describe('connection', function () {
it("can connect to the server without specifying transport explicitly", function (done) {
var message = "Hello World!";
var connection = new signalR.HttpConnection(ECHOENDPOINT_URL);

var received = "";
connection.onDataReceived = function (data) {
received += data;
if (data == message) {
connection.stop();
}
}
};

connection.onClosed = error => {
connection.onClosed = function (error) {
expect(error).toBeUndefined();
done();
}
};

connection.start()
.then(() => {
connection.send(message);
})
.catch(e => {
fail();
done();
});
connection.start().then(function () {
connection.send(message);
}).catch(function (e) {
fail();
done();
});
});

eachTransport(transportType => {
it(`over ${signalR.TransportType[transportType]} can send and receive messages`, done => {
const message = "Hello World!";
let connection = new signalR.HttpConnection(ECHOENDPOINT_URL,
{
transport: transportType,
logger: new signalR.ConsoleLogger(signalR.LogLevel.Information)
});

let received = "";
connection.onDataReceived = data => {
eachTransport(function (transportType) {
it("over " + signalR.TransportType[transportType] + " can send and receive messages", function (done) {
var message = "Hello World!";
var connection = new signalR.HttpConnection(ECHOENDPOINT_URL, {
transport: transportType,
logger: new signalR.ConsoleLogger(signalR.LogLevel.Information)
});

var received = "";
connection.onDataReceived = function (data) {
received += data;
if (data == message) {
connection.stop();
}
}
};

connection.onClosed = error => {
connection.onClosed = function (error) {
expect(error).toBeUndefined();
done();
}
};

connection.start()
.then(() => {
connection.send(message);
})
.catch(e => {
fail();
done();
});
connection.start().then(function () {
connection.send(message);
}).catch(function (e) {
fail();
done();
});
});
});
});
});
Loading

0 comments on commit 2a36aa1

Please sign in to comment.