lowercasing event names
This commit is contained in:
parent
5ca089e33e
commit
20d4d70cc7
|
|
@ -152,8 +152,8 @@ describe("Connection", () => {
|
|||
return Promise.reject("");
|
||||
},
|
||||
stop(): void { },
|
||||
onDataReceived: undefined,
|
||||
onClosed: undefined,
|
||||
onreceive: undefined,
|
||||
onclose: undefined,
|
||||
}
|
||||
|
||||
let options: IHttpConnectionOptions = {
|
||||
|
|
@ -249,8 +249,8 @@ describe("Connection", () => {
|
|||
connect(url: string, requestedTransferMode: TransferMode): Promise<TransferMode> { return Promise.resolve(transportTransferMode); },
|
||||
send(data: any): Promise<void> { return Promise.resolve(); },
|
||||
stop(): void {},
|
||||
onDataReceived: null,
|
||||
onClosed: null,
|
||||
onreceive: null,
|
||||
onclose: null,
|
||||
mode: transportTransferMode
|
||||
} as ITransport;
|
||||
|
||||
|
|
|
|||
|
|
@ -117,7 +117,7 @@ describe("HubConnection", () => {
|
|||
let hubConnection = new HubConnection(connection);
|
||||
let invokePromise = hubConnection.invoke("testMethod");
|
||||
// Typically this would be called by the transport
|
||||
connection.onClosed(new Error("Connection lost"));
|
||||
connection.onclose(new Error("Connection lost"));
|
||||
|
||||
let ex = await captureException(async () => await invokePromise);
|
||||
expect(ex.message).toBe("Connection lost");
|
||||
|
|
@ -130,7 +130,7 @@ describe("HubConnection", () => {
|
|||
let invokePromise = hubConnection.invoke("testMethod");
|
||||
|
||||
connection.receive({ type: 2, invocationId: connection.lastInvocationId, item: null });
|
||||
connection.onClosed();
|
||||
connection.onclose();
|
||||
|
||||
let ex = await captureException(async () => await invokePromise);
|
||||
expect(ex.message).toBe("Streaming methods must be invoked using HubConnection.stream");
|
||||
|
|
@ -350,7 +350,7 @@ describe("HubConnection", () => {
|
|||
.subscribe(observer);
|
||||
|
||||
// Typically this would be called by the transport
|
||||
connection.onClosed(new Error("Connection lost"));
|
||||
connection.onclose(new Error("Connection lost"));
|
||||
|
||||
let ex = await captureException(async () => await observer.completed);
|
||||
expect(ex.message).toEqual("Error: Connection lost");
|
||||
|
|
@ -397,10 +397,10 @@ describe("HubConnection", () => {
|
|||
let connection = new TestConnection();
|
||||
let hubConnection = new HubConnection(connection);
|
||||
let invocations = 0;
|
||||
hubConnection.onClosed(e => invocations++);
|
||||
hubConnection.onClosed(e => invocations++);
|
||||
hubConnection.onclose(e => invocations++);
|
||||
hubConnection.onclose(e => invocations++);
|
||||
// Typically this would be called by the transport
|
||||
connection.onClosed();
|
||||
connection.onclose();
|
||||
expect(invocations).toBe(2);
|
||||
});
|
||||
|
||||
|
|
@ -408,20 +408,20 @@ describe("HubConnection", () => {
|
|||
let connection = new TestConnection();
|
||||
let hubConnection = new HubConnection(connection);
|
||||
let error: Error;
|
||||
hubConnection.onClosed(e => error = e);
|
||||
hubConnection.onclose(e => error = e);
|
||||
|
||||
// Typically this would be called by the transport
|
||||
connection.onClosed(new Error("Test error."));
|
||||
connection.onclose(new Error("Test error."));
|
||||
expect(error.message).toBe("Test error.");
|
||||
});
|
||||
|
||||
it("ignores null callbacks", async () => {
|
||||
let connection = new TestConnection();
|
||||
let hubConnection = new HubConnection(connection);
|
||||
hubConnection.onClosed(null);
|
||||
hubConnection.onClosed(undefined);
|
||||
hubConnection.onclose(null);
|
||||
hubConnection.onclose(undefined);
|
||||
// Typically this would be called by the transport
|
||||
connection.onClosed();
|
||||
connection.onclose();
|
||||
// expect no errors
|
||||
});
|
||||
});
|
||||
|
|
@ -447,18 +447,18 @@ class TestConnection implements IConnection {
|
|||
};
|
||||
|
||||
stop(): void {
|
||||
if (this.onClosed) {
|
||||
this.onClosed();
|
||||
if (this.onclose) {
|
||||
this.onclose();
|
||||
}
|
||||
};
|
||||
|
||||
receive(data: any): void {
|
||||
let payload = JSON.stringify(data);
|
||||
this.onDataReceived(TextMessageFormat.write(payload));
|
||||
this.onreceive(TextMessageFormat.write(payload));
|
||||
}
|
||||
|
||||
onDataReceived: DataReceived;
|
||||
onClosed: ConnectionClosed;
|
||||
onreceive: DataReceived;
|
||||
onclose: ConnectionClosed;
|
||||
sentData: [any];
|
||||
lastInvocationId: string;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -67,8 +67,8 @@ export class HttpConnection implements IConnection {
|
|||
this.url += (this.url.indexOf("?") == -1 ? "?" : "&") + `id=${this.connectionId}`;
|
||||
|
||||
this.transport = this.createTransport(this.options.transport, negotiateResponse.availableTransports);
|
||||
this.transport.onDataReceived = this.onDataReceived;
|
||||
this.transport.onClosed = e => this.stopConnection(true, e);
|
||||
this.transport.onreceive = this.onreceive;
|
||||
this.transport.onclose = e => this.stopConnection(true, e);
|
||||
|
||||
let requestedTransferMode =
|
||||
this.features.transferMode === TransferMode.Binary
|
||||
|
|
@ -151,8 +151,8 @@ export class HttpConnection implements IConnection {
|
|||
|
||||
this.connectionState = ConnectionState.Disconnected;
|
||||
|
||||
if (raiseClosed && this.onClosed) {
|
||||
this.onClosed(error);
|
||||
if (raiseClosed && this.onclose) {
|
||||
this.onclose(error);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -182,6 +182,6 @@ export class HttpConnection implements IConnection {
|
|||
return normalizedUrl;
|
||||
}
|
||||
|
||||
onDataReceived: DataReceived;
|
||||
onClosed: ConnectionClosed;
|
||||
onreceive: DataReceived;
|
||||
onclose: ConnectionClosed;
|
||||
}
|
||||
|
|
@ -41,12 +41,8 @@ export class HubConnection {
|
|||
this.logger = LoggerFactory.createLogger(options.logging);
|
||||
|
||||
this.protocol = options.protocol || new JsonHubProtocol();
|
||||
this.connection.onDataReceived = data => {
|
||||
this.onDataReceived(data);
|
||||
};
|
||||
this.connection.onClosed = (error?: Error) => {
|
||||
this.onConnectionClosed(error);
|
||||
}
|
||||
this.connection.onreceive = (data: any) => this.processIncomingData(data);
|
||||
this.connection.onclose = (error?: Error) => this.connectionClosed(error);
|
||||
|
||||
this.callbacks = new Map<string, (invocationEvent: CompletionMessage | ResultMessage) => void>();
|
||||
this.methods = new Map<string, ((...args: any[]) => void)[]>();
|
||||
|
|
@ -54,7 +50,7 @@ export class HubConnection {
|
|||
this.id = 0;
|
||||
}
|
||||
|
||||
private onDataReceived(data: any) {
|
||||
private processIncomingData(data: any) {
|
||||
// Parse the messages
|
||||
let messages = this.protocol.parseMessages(data);
|
||||
|
||||
|
|
@ -95,7 +91,7 @@ export class HubConnection {
|
|||
}
|
||||
}
|
||||
|
||||
private onConnectionClosed(error?: Error) {
|
||||
private connectionClosed(error?: Error) {
|
||||
let errorCompletionMessage = <CompletionMessage>{
|
||||
type: MessageType.Completion,
|
||||
invocationId: "-1",
|
||||
|
|
@ -238,7 +234,7 @@ export class HubConnection {
|
|||
}
|
||||
}
|
||||
|
||||
onClosed(callback: ConnectionClosed) {
|
||||
onclose(callback: ConnectionClosed) {
|
||||
if (callback) {
|
||||
this.closedCallbacks.push(callback);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,6 @@ export interface IConnection {
|
|||
send(data: any): Promise<void>;
|
||||
stop(): void;
|
||||
|
||||
onDataReceived: DataReceived;
|
||||
onClosed: ConnectionClosed;
|
||||
onreceive: DataReceived;
|
||||
onclose: ConnectionClosed;
|
||||
}
|
||||
|
|
@ -21,8 +21,8 @@ export interface ITransport {
|
|||
connect(url: string, requestedTransferMode: TransferMode): Promise<TransferMode>;
|
||||
send(data: any): Promise<void>;
|
||||
stop(): void;
|
||||
onDataReceived: DataReceived;
|
||||
onClosed: TransportClosed;
|
||||
onreceive: DataReceived;
|
||||
onclose: TransportClosed;
|
||||
}
|
||||
|
||||
export class WebSocketTransport implements ITransport {
|
||||
|
|
@ -55,19 +55,19 @@ export class WebSocketTransport implements ITransport {
|
|||
|
||||
webSocket.onmessage = (message: MessageEvent) => {
|
||||
this.logger.log(LogLevel.Trace, `(WebSockets transport) data received: ${message.data}`);
|
||||
if (this.onDataReceived) {
|
||||
this.onDataReceived(message.data);
|
||||
if (this.onreceive) {
|
||||
this.onreceive(message.data);
|
||||
}
|
||||
}
|
||||
|
||||
webSocket.onclose = (event: CloseEvent) => {
|
||||
// webSocket will be null if the transport did not start successfully
|
||||
if (this.onClosed && this.webSocket) {
|
||||
if (this.onclose && this.webSocket) {
|
||||
if (event.wasClean === false || event.code !== 1000) {
|
||||
this.onClosed(new Error(`Websocket closed with status code: ${event.code} (${event.reason})`));
|
||||
this.onclose(new Error(`Websocket closed with status code: ${event.code} (${event.reason})`));
|
||||
}
|
||||
else {
|
||||
this.onClosed();
|
||||
this.onclose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -90,8 +90,8 @@ export class WebSocketTransport implements ITransport {
|
|||
}
|
||||
}
|
||||
|
||||
onDataReceived: DataReceived;
|
||||
onClosed: TransportClosed;
|
||||
onreceive: DataReceived;
|
||||
onclose: TransportClosed;
|
||||
}
|
||||
|
||||
export class ServerSentEventsTransport implements ITransport {
|
||||
|
|
@ -116,13 +116,13 @@ export class ServerSentEventsTransport implements ITransport {
|
|||
|
||||
try {
|
||||
eventSource.onmessage = (e: MessageEvent) => {
|
||||
if (this.onDataReceived) {
|
||||
if (this.onreceive) {
|
||||
try {
|
||||
this.logger.log(LogLevel.Trace, `(SSE transport) data received: ${e.data}`);
|
||||
this.onDataReceived(e.data);
|
||||
this.onreceive(e.data);
|
||||
} catch (error) {
|
||||
if (this.onClosed) {
|
||||
this.onClosed(error);
|
||||
if (this.onclose) {
|
||||
this.onclose(error);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
|
@ -133,8 +133,8 @@ export class ServerSentEventsTransport implements ITransport {
|
|||
reject();
|
||||
|
||||
// don't report an error if the transport did not start successfully
|
||||
if (this.eventSource && this.onClosed) {
|
||||
this.onClosed(new Error(e.message || "Error occurred"));
|
||||
if (this.eventSource && this.onclose) {
|
||||
this.onclose(new Error(e.message || "Error occurred"));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -162,8 +162,8 @@ export class ServerSentEventsTransport implements ITransport {
|
|||
}
|
||||
}
|
||||
|
||||
onDataReceived: DataReceived;
|
||||
onClosed: TransportClosed;
|
||||
onreceive: DataReceived;
|
||||
onclose: TransportClosed;
|
||||
}
|
||||
|
||||
export class LongPollingTransport implements ITransport {
|
||||
|
|
@ -201,7 +201,7 @@ export class LongPollingTransport implements ITransport {
|
|||
|
||||
pollXhr.onload = () => {
|
||||
if (pollXhr.status == 200) {
|
||||
if (this.onDataReceived) {
|
||||
if (this.onreceive) {
|
||||
try {
|
||||
let response = transferMode === TransferMode.Text
|
||||
? pollXhr.responseText
|
||||
|
|
@ -209,14 +209,14 @@ export class LongPollingTransport implements ITransport {
|
|||
|
||||
if (response) {
|
||||
this.logger.log(LogLevel.Trace, `(LongPolling transport) data received: ${response}`);
|
||||
this.onDataReceived(response);
|
||||
this.onreceive(response);
|
||||
}
|
||||
else {
|
||||
this.logger.log(LogLevel.Information, "(LongPolling transport) timed out");
|
||||
}
|
||||
} catch (error) {
|
||||
if (this.onClosed) {
|
||||
this.onClosed(error);
|
||||
if (this.onclose) {
|
||||
this.onclose(error);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
|
@ -224,21 +224,21 @@ export class LongPollingTransport implements ITransport {
|
|||
this.poll(url, transferMode);
|
||||
}
|
||||
else if (this.pollXhr.status == 204) {
|
||||
if (this.onClosed) {
|
||||
this.onClosed();
|
||||
if (this.onclose) {
|
||||
this.onclose();
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (this.onClosed) {
|
||||
this.onClosed(new HttpError(pollXhr.statusText, pollXhr.status));
|
||||
if (this.onclose) {
|
||||
this.onclose(new HttpError(pollXhr.statusText, pollXhr.status));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
pollXhr.onerror = () => {
|
||||
if (this.onClosed) {
|
||||
if (this.onclose) {
|
||||
// network related error or denied cross domain request
|
||||
this.onClosed(new Error("Sending HTTP request failed."));
|
||||
this.onclose(new Error("Sending HTTP request failed."));
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -270,8 +270,8 @@ export class LongPollingTransport implements ITransport {
|
|||
}
|
||||
}
|
||||
|
||||
onDataReceived: DataReceived;
|
||||
onClosed: TransportClosed;
|
||||
onreceive: DataReceived;
|
||||
onclose: TransportClosed;
|
||||
}
|
||||
|
||||
const headers = new Map<string, string>();
|
||||
|
|
|
|||
|
|
@ -10,14 +10,14 @@ describe('connection', function () {
|
|||
var connection = new signalR.HttpConnection(ECHOENDPOINT_URL);
|
||||
|
||||
var received = "";
|
||||
connection.onDataReceived = function (data) {
|
||||
connection.onreceive = function (data) {
|
||||
received += data;
|
||||
if (data == message) {
|
||||
connection.stop();
|
||||
}
|
||||
};
|
||||
|
||||
connection.onClosed = function (error) {
|
||||
connection.onclose = function (error) {
|
||||
expect(error).toBeUndefined();
|
||||
done();
|
||||
};
|
||||
|
|
@ -42,14 +42,14 @@ describe('connection', function () {
|
|||
});
|
||||
|
||||
var received = "";
|
||||
connection.onDataReceived = function (data) {
|
||||
connection.onreceive = function (data) {
|
||||
received += data;
|
||||
if (data == message) {
|
||||
connection.stop();
|
||||
}
|
||||
};
|
||||
|
||||
connection.onClosed = function (error) {
|
||||
connection.onclose = function (error) {
|
||||
expect(error).toBeUndefined();
|
||||
done();
|
||||
};
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ describe('hubConnection', function () {
|
|||
logging: signalR.LogLevel.Trace
|
||||
};
|
||||
var hubConnection = new signalR.HubConnection(TESTHUBENDPOINT_URL, options);
|
||||
hubConnection.onClosed(function (error) {
|
||||
hubConnection.onclose(function (error) {
|
||||
expect(error).toBe(undefined);
|
||||
done();
|
||||
});
|
||||
|
|
@ -46,7 +46,7 @@ describe('hubConnection', function () {
|
|||
};
|
||||
var hubConnection = new signalR.HubConnection(TESTHUBENDPOINT_URL, options);
|
||||
|
||||
hubConnection.onClosed(function (error) {
|
||||
hubConnection.onclose(function (error) {
|
||||
expect(error).toBe(undefined);
|
||||
done();
|
||||
});
|
||||
|
|
@ -172,7 +172,7 @@ describe('hubConnection', function () {
|
|||
};
|
||||
var hubConnection = new signalR.HubConnection('http://' + document.location.host + '/uncreatable', options);
|
||||
|
||||
hubConnection.onClosed(function (error) {
|
||||
hubConnection.onclose(function (error) {
|
||||
expect(error.message).toMatch(errorRegex[signalR.TransportType[transportType]]);
|
||||
done();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -18,17 +18,16 @@
|
|||
<script>
|
||||
let transportType = signalR.TransportType[getParameterByName('transport')] || signalR.TransportType.WebSockets;
|
||||
let logger = new signalR.ConsoleLogger(signalR.LogLevel.Information);
|
||||
let http = new signalR.HttpConnection(`http://${document.location.host}/chat`, { transport: transportType, logger: logger });
|
||||
let connection = new signalR.HubConnection(http, logger);
|
||||
let connection = new signalR.HubConnection('/chat', { transport: transportType, logger: logger });
|
||||
|
||||
connection.onClosed = e => {
|
||||
connection.onclose(e => {
|
||||
if (e) {
|
||||
appendLine('Connection closed with error: ' + e, 'red');
|
||||
}
|
||||
else {
|
||||
appendLine('Disconnected', 'green');
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
connection.on('SetUsersOnline', usersOnline => {
|
||||
usersOnline.forEach(user => addUserOnline(user));
|
||||
|
|
|
|||
|
|
@ -104,20 +104,19 @@ click('connect', function(event) {
|
|||
connectButton.disabled = true;
|
||||
disconnectButton.disabled = false;
|
||||
console.log('http://' + document.location.host + '/' + hubRoute);
|
||||
let http = new signalR.HttpConnection('http://' + document.location.host + '/' + hubRoute, { transport: transportType, logger: logger });
|
||||
connection = new signalR.HubConnection(http, logger);
|
||||
connection = new signalR.HubConnection(hubRoute, logger, { transport: transportType, logger: logger });
|
||||
connection.on('Send', function(msg) {
|
||||
addLine('message-list', msg);
|
||||
});
|
||||
|
||||
connection.onClosed = function(e) {
|
||||
connection.onclose(function(e) {
|
||||
if (e) {
|
||||
addLine('message-list', 'Connection closed with error: ' + e, 'red');
|
||||
}
|
||||
else {
|
||||
addLine('message-list', 'Disconnected', 'green');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
connection.start()
|
||||
.then(function() {
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@
|
|||
let url = 'http://' + document.location.host + '/chat';
|
||||
let connection = new signalR.HttpConnection(url, { transport: transportType, logger: new signalR.ConsoleLogger(signalR.LogLevel.Information) });
|
||||
|
||||
connection.onDataReceived = function(data) {
|
||||
connection.onreceive = function(data) {
|
||||
let child = document.createElement('li');
|
||||
child.innerText = data;
|
||||
document.getElementById('messages').appendChild(child);
|
||||
|
|
|
|||
|
|
@ -54,8 +54,6 @@
|
|||
let invocationCounter = 0;
|
||||
|
||||
document.getElementById('transportName').innerHTML = signalR.TransportType[transportType];
|
||||
|
||||
let url = 'http://' + document.location.host + '/streaming';
|
||||
let connection = null;
|
||||
|
||||
click('clearButton', function () {
|
||||
|
|
@ -67,17 +65,16 @@
|
|||
});
|
||||
|
||||
click('connectButton', function () {
|
||||
let http = new signalR.HttpConnection(url, { transport: transportType, logger: logger });
|
||||
connection = new signalR.HubConnection(http, logger);
|
||||
connection = new signalR.HubConnection('/streaming', { transport: transportType, logger: logger });
|
||||
|
||||
connection.onClosed = function () {
|
||||
connection.onclose(function () {
|
||||
channelButton.disabled = true;
|
||||
observableButton.disabled = true;
|
||||
connectButton.disabled = false;
|
||||
disconnectButton.disabled = true;
|
||||
|
||||
addLine('resultsList', 'disconnected', 'green');
|
||||
};
|
||||
});
|
||||
|
||||
connection.start()
|
||||
.then(function () {
|
||||
|
|
|
|||
Loading…
Reference in New Issue