Compare commits
2 Commits
3587d0184f
...
4211560f20
| Author | SHA1 | Date |
|---|---|---|
|
|
4211560f20 | |
|
|
51238d47a1 |
|
|
@ -5,6 +5,7 @@
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>InstantChat</title>
|
<title>InstantChat</title>
|
||||||
<link rel="stylesheet" href="css/style.css">
|
<link rel="stylesheet" href="css/style.css">
|
||||||
|
<script src="js/jquery-3.3.1.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,45 @@
|
||||||
|
// Constants and variables
|
||||||
|
var wsUri = "ws://localhost:8765";
|
||||||
|
|
||||||
|
|
||||||
|
// Initialization
|
||||||
|
function init() {
|
||||||
|
console.log("Init...");
|
||||||
|
openWebSocket();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Open WebSocket
|
||||||
|
function openWebSocket() {
|
||||||
|
websocket = new WebSocket(wsUri);
|
||||||
|
websocket.onopen = function(evt) { onOpen(evt) };
|
||||||
|
websocket.onclose = function(evt) { onClose(evt) };
|
||||||
|
websocket.onmessage = function(evt) { onMessage(evt) };
|
||||||
|
websocket.onerror = function(evt) { onError(evt) };
|
||||||
|
}
|
||||||
|
|
||||||
|
// WebSocket event handlers
|
||||||
|
function onOpen(evt) {
|
||||||
|
console.log('Connected to ' + wsUri + '.');
|
||||||
|
|
||||||
|
text = "Meow";
|
||||||
|
console.log('Sending "' + text + '".');
|
||||||
|
websocket.send(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
function onClose(evt) {
|
||||||
|
console.log("Connection closed.");
|
||||||
|
}
|
||||||
|
|
||||||
|
function onMessage(evt) {
|
||||||
|
console.log('Received: "' + evt.data + '".');
|
||||||
|
}
|
||||||
|
|
||||||
|
function onError(evt) {
|
||||||
|
console.error('Error: "' + evt.data + '".');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Run script after page is loaded
|
||||||
|
$(function() {
|
||||||
|
init();
|
||||||
|
});
|
||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue