Skip to content

Instantly share code, notes, and snippets.

@JS-AK
Created July 27, 2021 11:22
Show Gist options
  • Save JS-AK/75195b0bff4e96436cb27d0bf5ebbaab to your computer and use it in GitHub Desktop.
Save JS-AK/75195b0bff4e96436cb27d0bf5ebbaab to your computer and use it in GitHub Desktop.
main.js
document.addEventListener("DOMContentLoaded", function(event) {
console.log('DOMContentLoaded')
function getParameterByName(name, url) {
if (!url) url = window.location.href;
name = name.replace(/[\[\]]/g, '\\$&');
var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, ' '));
}
const socketId = getParameterByName('socketid')
var socket = io.connect('https://ecdo-socket.2people.io', {
transports: ['websocket', 'polling'],
query: { socketId: socketId }
});
socket.on('connect', function() {
console.log('connect')
});
socket.on('disconnect', function() {
console.log('disconnect')
});
socket.on('NOT_FOUND', function(data) {
console.log('NOT_FOUND')
c3_callFunction("NOT_FOUND", ["777"]);
});
socket.on('EYES_WRONG_POSITION', function(data) {
console.log('EYES_WRONG_POSITION')
c3_callFunction("EYES_WRONG_POSITION", ["777"]);
});
socket.on('EYES_CLOSED', function(data){
console.log('EYES_CLOSED')
c3_callFunction("EYES_CLOSED", ["777"]);
});
window.ecdoBackConnectToTrainerGame = function (token, data = {}) {
socket.emit('connectToTrainerGame', Object.assign({}, { token: token }, data))
}
window.ecdoBackDisconnectFromTrainerGame = function () {
socket.emit('disconnectFromTrainerGame')
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment