Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
2 changed files
with
28 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import * as signalR from "@aspnet/signalr-client" | ||
import * as $ from "jquery" | ||
|
||
// Get the user name and store it to prepend to messages. | ||
$('#displayname').val(<string>prompt('Enter your name:', '')); | ||
// Set initial focus to message input box. | ||
$('#message').focus(); | ||
|
||
var connection = new signalR.HubConnection('/chat'); | ||
// Create a function that the hub can call to broadcast messages. | ||
connection.on('broadcastMessage', function (name, message) { | ||
// Html encode display name and message. | ||
var encodedName = $('<div />').text(name).html(); | ||
var encodedMsg = $('<div />').text(message).html(); | ||
// Add the message to the page. | ||
$('#discussion').append('<li><strong>' + encodedName | ||
+ '</strong>: ' + encodedMsg + '</li>'); | ||
}); | ||
|
||
// Start the connection. | ||
connection.start().then(function () { | ||
$('#sendmessage').click(function () { | ||
// Call the Send method on the hub. | ||
connection.invoke('send', $('#displayname').val(), $('#message').val()); | ||
// Clear text box and reset focus for next comment. | ||
$('#message').val('').focus(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters