/var/www/doncode.com.ua/www/public/js
Edit: /var/www/doncode.com.ua/www/public/js/web_socket_use.js (2917B)
// Set URL of your WebSocketMain.swf here:
WEB_SOCKET_SWF_LOCATION = "/public/swf/WebSocketMain.swf";
WEB_SOCKET_SWF_LOCATION = "/public/swf/WebSocketMainInsecure.swf";
// Set this to dump debug message from Flash to console.log:
WEB_SOCKET_DEBUG = false;
// Everything below is the same as using standard WebSocket.
var ws;
var autoreconnect = true;
var pingInterval = 0;
var server_host = 'api.doncode.com.ua';
//var server_host = '192.168.0.243';
var taxi_server_mob_port = 7580;
var sid = '';
function sendPing(){
//output('TX: {"c":"lastgps"}');
ws.send('[{"cmd":"ping"}]\n');
}
function sendGetCars(){
//output('TX: {"c":"lastgps"}');
ws.send('[{"cmd":"get_cars"}]\n');
}
function sendGetOnline(){
//output('TX: {"c":"lastgps"}');
ws.send('[{"cmd":"get_online"}]\n');
}
function sendChat(message){
//output('TX: {"c":"lastgps"}');
ws.send('[{"cmd":"chat","text":"'+message+'"}]\n');
}
function web_socket_init(sessid) {
sid = sessid;
if(!autoreconnect){
output("autoreconnect disable")
return;
}
autoreconnect = true;
// Connect to Web Socket.
// Change host/port here to your own Web Socket server.
//host = document.getElementById('host').value;
output("Connecting to "+'ws://'+server_host+':'+taxi_server_mob_port+"...");
ws = new WebSocket('ws://'+server_host+':'+taxi_server_mob_port);
// Set event handlers.
ws.onopen = function() {
output("onopen");
ws.send('[{"cmd":"auth","sid":"'+sid+'"}]');
pingInterval = setInterval("sendPing()", 30000);
if (typeof(callback_onopen) == "function") {
console.log('RUN CALLBACK: callback_onopen');
callback_onopen();
}
};
ws.onmessage = function(e) {
// e.data contains received string.
output("onmessage: " + e.data);
j = JSON.parse(e.data);
if (typeof(callback_onmessage) == "function") {
console.log('RUN CALLBACK: callback_onmessage');
callback_onmessage(j);
}
//if(j.err == undefined){
// draw_marker(j);
//}
};
ws.onclose = function() {
output("onclose ");
clearInterval(pingInterval);
if(autoreconnect){
setTimeout("web_socket_init('"+sid+"')",5000);
}
if (typeof(callback_onclose) == "function") {
console.log('RUN CALLBACK: callback_onclose');
callback_onclose();
}
ws.close;
};
ws.onerror = function() {
output("onerror");
clearInterval(pingInterval);
if(autoreconnect){
//setTimeout("web_socket_init()",15000);
}
if (typeof(callback_onerror) == "function") {
console.log('RUN CALLBACK: callback_onerror');
callback_onerror();
}
ws.close;
};
}
function onSubmit() {
var input = document.getElementById("input");
// You can send message to the Web Socket using ws.send.
ws.send(input.value);
output("send: " + input.value);
input.value = "";
input.focus();
}
function onCloseClick() {
ws.close();
autoreconnect = false;
}
function output(str) {
console.log(str);
}