diff --git a/signalr/signalr-tests.ts b/signalr/signalr-tests.ts index f69d557d33..4ac0752c1a 100644 --- a/signalr/signalr-tests.ts +++ b/signalr/signalr-tests.ts @@ -53,10 +53,19 @@ function test_connection() { interface MyHubConnection extends HubConnection { someState: string; SomeFunction: Function; + + // My Hubs Client functions: + client: { + addMessage: (message: string) => void; + } + // My Hubs Server function: + server: { + send(message: string); + } } interface SignalR { - chat: HubConnection; + chat: MyHubConnection; myHub: MyHubConnection; } @@ -106,4 +115,23 @@ function test_hubs() { }); var connection = $.hubConnection('http://localhost:8081/'); connection.start({ jsonp: true }); -} \ No newline at end of file +} + +// Sample from : https://github.com/SignalR/SignalR/wiki/QuickStart-Hubs#javascript--html +$(function () { + // Proxy created on the fly + var chat = $.connection.chat; + + // Declare a function on the chat hub so the server can invoke it + chat.client.addMessage = function (message) { + $('#messages').append('
  • ' + message + '
  • '); + }; + + // Start the connection + $.connection.hub.start().done(function () { + $("#broadcast").click(function () { + // Call the chat method on the server + chat.server.send($('#msg').val()); + }); + }); +}); \ No newline at end of file