mirror of
https://github.com/onionshare/onionshare.git
synced 2025-05-04 23:45:04 -04:00
Create web UI and socket code for the chat interface
This commit is contained in:
parent
e7bd89c41d
commit
ec7a969dde
8 changed files with 186 additions and 1 deletions
31
share/static/js/chat.js
Normal file
31
share/static/js/chat.js
Normal file
|
@ -0,0 +1,31 @@
|
|||
$(function(){
|
||||
var socket;
|
||||
$(document).ready(function(){
|
||||
socket = io.connect('http://' + document.domain + ':' + location.port + '/chat');
|
||||
socket.on('connect', function() {
|
||||
socket.emit('joined', {});
|
||||
});
|
||||
socket.on('status', function(data) {
|
||||
console.log("received")
|
||||
$('#chat').append('<p><small><i>' + data.msg + '</i></small></p>');
|
||||
$('#chat').scrollTop($('#chat')[0].scrollHeight);
|
||||
});
|
||||
socket.on('message', function(data) {
|
||||
$('#chat').append('<p>' + data.msg + '</p>');
|
||||
$('#chat').scrollTop($('#chat')[0].scrollHeight);
|
||||
});
|
||||
$('#new-message').on('keypress', function(e) {
|
||||
var code = e.keyCode || e.which;
|
||||
if (code == 13) {
|
||||
emitMessage(socket);
|
||||
}
|
||||
});
|
||||
$('#send-button').on('click', emitMessage);
|
||||
});
|
||||
});
|
||||
|
||||
function emitMessage(socket) {
|
||||
text = $('#new-message').val();
|
||||
$('#new-message').val('');
|
||||
socket.emit('text', {msg: text});
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue