signalr added a sample test that shows how you can handle client function and call functions on the server.

Closes #354
This commit is contained in:
basarat
2013-09-07 00:20:52 +10:00
parent a12a8fdfda
commit 4e668d8040
+30 -2
View File
@@ -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 });
}
}
// 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('<li>' + message + '</li>');
};
// Start the connection
$.connection.hub.start().done(function () {
$("#broadcast").click(function () {
// Call the chat method on the server
chat.server.send($('#msg').val());
});
});
});