19 lines
491 B
JavaScript
19 lines
491 B
JavaScript
'use strict';
|
|
|
|
let webSocket;
|
|
|
|
$.when($.ready).then(function () {
|
|
let protocolPrefix = (window.location.protocol === 'https:') ? 'wss:' : 'ws:';
|
|
webSocket = new WebSocket(`${protocolPrefix}//${location.host}/socket/player`);
|
|
});
|
|
|
|
function sendUsername() {
|
|
const username = $('#username').val()
|
|
if (username !== null && username !== '') {
|
|
console.log(`Username: ${username}`)
|
|
webSocket.send(username)
|
|
} else {
|
|
alert("Please enter a name!")
|
|
}
|
|
}
|