mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-07-30 11:19:44 -04:00
installing socketIO and testing the WebSocket connection
This commit is contained in:
23
app/assets/javascripts/socket.js
Normal file
23
app/assets/javascripts/socket.js
Normal file
@@ -0,0 +1,23 @@
|
||||
|
||||
(function (window) {
|
||||
document.addEventListener('DOMContentLoaded', (event) => {
|
||||
var socket = io();
|
||||
|
||||
socket.on('connect', function() {
|
||||
console.log('Connected to the server');
|
||||
});
|
||||
|
||||
socket.on('message', function(msg) {
|
||||
var li = document.createElement("li");
|
||||
li.appendChild(document.createTextNode(msg));
|
||||
document.getElementById("messages").appendChild(li);
|
||||
});
|
||||
|
||||
document.getElementById('sendButton').addEventListener('click', function() {
|
||||
var message = document.getElementById("message").value;
|
||||
socket.send(message);
|
||||
document.getElementById("message").value = '';
|
||||
});
|
||||
});
|
||||
|
||||
})(window);
|
||||
Reference in New Issue
Block a user