mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-11 12:30:18 +00:00
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:
@@ -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());
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user