From 20d4d70cc7ceaae976c478cde0c6ae59946dce3d Mon Sep 17 00:00:00 2001 From: Pawel Kadluczka Date: Wed, 20 Sep 2017 18:19:02 -0700 Subject: [PATCH] lowercasing event names --- .../Connection.spec.ts | 8 +-- .../HubConnection.spec.ts | 32 +++++----- .../HttpConnection.ts | 12 ++-- .../HubConnection.ts | 14 ++--- .../IConnection.ts | 4 +- .../Transports.ts | 58 +++++++++---------- .../wwwroot/js/connectionTests.js | 8 +-- .../wwwroot/js/hubConnectionTests.js | 6 +- samples/ChatSample/Views/Home/Index.cshtml | 7 +-- samples/SocketsSample/wwwroot/hubs.html | 7 +-- samples/SocketsSample/wwwroot/sockets.html | 2 +- samples/SocketsSample/wwwroot/streaming.html | 9 +-- 12 files changed, 79 insertions(+), 88 deletions(-) diff --git a/client-ts/Microsoft.AspNetCore.SignalR.Client.TS.Tests/Connection.spec.ts b/client-ts/Microsoft.AspNetCore.SignalR.Client.TS.Tests/Connection.spec.ts index 70120c0790..bfa3c9f9f4 100644 --- a/client-ts/Microsoft.AspNetCore.SignalR.Client.TS.Tests/Connection.spec.ts +++ b/client-ts/Microsoft.AspNetCore.SignalR.Client.TS.Tests/Connection.spec.ts @@ -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 { return Promise.resolve(transportTransferMode); }, send(data: any): Promise { return Promise.resolve(); }, stop(): void {}, - onDataReceived: null, - onClosed: null, + onreceive: null, + onclose: null, mode: transportTransferMode } as ITransport; diff --git a/client-ts/Microsoft.AspNetCore.SignalR.Client.TS.Tests/HubConnection.spec.ts b/client-ts/Microsoft.AspNetCore.SignalR.Client.TS.Tests/HubConnection.spec.ts index 2312f5b7ee..fc9cd990f9 100644 --- a/client-ts/Microsoft.AspNetCore.SignalR.Client.TS.Tests/HubConnection.spec.ts +++ b/client-ts/Microsoft.AspNetCore.SignalR.Client.TS.Tests/HubConnection.spec.ts @@ -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; }; diff --git a/client-ts/Microsoft.AspNetCore.SignalR.Client.TS/HttpConnection.ts b/client-ts/Microsoft.AspNetCore.SignalR.Client.TS/HttpConnection.ts index 795ce730d7..733454c6e8 100644 --- a/client-ts/Microsoft.AspNetCore.SignalR.Client.TS/HttpConnection.ts +++ b/client-ts/Microsoft.AspNetCore.SignalR.Client.TS/HttpConnection.ts @@ -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; } \ No newline at end of file diff --git a/client-ts/Microsoft.AspNetCore.SignalR.Client.TS/HubConnection.ts b/client-ts/Microsoft.AspNetCore.SignalR.Client.TS/HubConnection.ts index 4de459ad52..a59571ef37 100644 --- a/client-ts/Microsoft.AspNetCore.SignalR.Client.TS/HubConnection.ts +++ b/client-ts/Microsoft.AspNetCore.SignalR.Client.TS/HubConnection.ts @@ -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 void>(); this.methods = new Map 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 = { type: MessageType.Completion, invocationId: "-1", @@ -238,7 +234,7 @@ export class HubConnection { } } - onClosed(callback: ConnectionClosed) { + onclose(callback: ConnectionClosed) { if (callback) { this.closedCallbacks.push(callback); } diff --git a/client-ts/Microsoft.AspNetCore.SignalR.Client.TS/IConnection.ts b/client-ts/Microsoft.AspNetCore.SignalR.Client.TS/IConnection.ts index ef90d27a98..5eed29c079 100644 --- a/client-ts/Microsoft.AspNetCore.SignalR.Client.TS/IConnection.ts +++ b/client-ts/Microsoft.AspNetCore.SignalR.Client.TS/IConnection.ts @@ -11,6 +11,6 @@ export interface IConnection { send(data: any): Promise; stop(): void; - onDataReceived: DataReceived; - onClosed: ConnectionClosed; + onreceive: DataReceived; + onclose: ConnectionClosed; } \ No newline at end of file diff --git a/client-ts/Microsoft.AspNetCore.SignalR.Client.TS/Transports.ts b/client-ts/Microsoft.AspNetCore.SignalR.Client.TS/Transports.ts index 47ab138b6e..de891096b1 100644 --- a/client-ts/Microsoft.AspNetCore.SignalR.Client.TS/Transports.ts +++ b/client-ts/Microsoft.AspNetCore.SignalR.Client.TS/Transports.ts @@ -21,8 +21,8 @@ export interface ITransport { connect(url: string, requestedTransferMode: TransferMode): Promise; send(data: any): Promise; 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(); diff --git a/client-ts/Microsoft.AspNetCore.SignalR.Test.Server/wwwroot/js/connectionTests.js b/client-ts/Microsoft.AspNetCore.SignalR.Test.Server/wwwroot/js/connectionTests.js index 80df786ab4..5cbe60fbcc 100644 --- a/client-ts/Microsoft.AspNetCore.SignalR.Test.Server/wwwroot/js/connectionTests.js +++ b/client-ts/Microsoft.AspNetCore.SignalR.Test.Server/wwwroot/js/connectionTests.js @@ -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(); }; diff --git a/client-ts/Microsoft.AspNetCore.SignalR.Test.Server/wwwroot/js/hubConnectionTests.js b/client-ts/Microsoft.AspNetCore.SignalR.Test.Server/wwwroot/js/hubConnectionTests.js index 49be37c86c..fc428da7af 100644 --- a/client-ts/Microsoft.AspNetCore.SignalR.Test.Server/wwwroot/js/hubConnectionTests.js +++ b/client-ts/Microsoft.AspNetCore.SignalR.Test.Server/wwwroot/js/hubConnectionTests.js @@ -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(); }); diff --git a/samples/ChatSample/Views/Home/Index.cshtml b/samples/ChatSample/Views/Home/Index.cshtml index cad287cdf3..0207c365e6 100644 --- a/samples/ChatSample/Views/Home/Index.cshtml +++ b/samples/ChatSample/Views/Home/Index.cshtml @@ -18,17 +18,16 @@