Fix in socketEvntHandler in socket.js. Small cleanup in socket.js
This commit is contained in:
parent
6824f18c8e
commit
cb9c7c63dc
88
socket.js
88
socket.js
@ -10,76 +10,30 @@ function Socket() {
|
|||||||
this.socketKey = guid();
|
this.socketKey = guid();
|
||||||
}
|
}
|
||||||
|
|
||||||
//Socket.create = function(/*callback*/) {
|
|
||||||
//
|
|
||||||
// var socket = new Socket();
|
|
||||||
//
|
|
||||||
// function socketEventHandler(event) {
|
|
||||||
//
|
|
||||||
// var payload = event.payload;
|
|
||||||
//
|
|
||||||
// if (payload.socketKey !== socket.socketKey) {
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// switch(payload.type) {
|
|
||||||
// case "Close":
|
|
||||||
// console.debug("SocketsForCordova: Close event, socket key: " + payload.socketKey);
|
|
||||||
// window.document.removeEventListener(SOCKET_EVENT, socketEventHandler);
|
|
||||||
// socket.onClose();
|
|
||||||
// break;
|
|
||||||
// case "DataReceived":
|
|
||||||
// console.debug("SocketsForCordova: DataReceived event, socket key: " + payload.socketKey);
|
|
||||||
// socket.onData(new Int8Array(payload.data));
|
|
||||||
// break;
|
|
||||||
// case "Error":
|
|
||||||
// console.debug("SocketsForCordova: Error event, socket key: " + payload.socketKey);
|
|
||||||
// socket.onError(payload.errorMessage);
|
|
||||||
// break;
|
|
||||||
// default:
|
|
||||||
// console.error("SocketsForCordova: Unknown event type " + payload.type + ", socket key: " + payload.socketKey);
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// window.document.addEventListener(SOCKET_EVENT, socketEventHandler);
|
|
||||||
//
|
|
||||||
// exec(
|
|
||||||
// function() {
|
|
||||||
// console.debug("SocketsForCordova: Socket object successfully constructed.");
|
|
||||||
// callback(socket);
|
|
||||||
// },
|
|
||||||
// function(error) {
|
|
||||||
// console.error("SocketsForCordova: Unexpected error during constructing Socket object. Error: " + error);
|
|
||||||
// },
|
|
||||||
// CORDOVA_SERVICE_NAME,
|
|
||||||
// "create",
|
|
||||||
// [ socket.socketKey ]);
|
|
||||||
//};
|
|
||||||
|
|
||||||
Socket.prototype.open = function (host, port, success, error) {
|
Socket.prototype.open = function (host, port, success, error) {
|
||||||
|
|
||||||
|
var _that = this;
|
||||||
function socketEventHandler(event) {
|
function socketEventHandler(event) {
|
||||||
|
|
||||||
var payload = event.payload;
|
var payload = event.payload;
|
||||||
|
|
||||||
if (payload.socketKey !== socket.socketKey) {
|
if (payload.socketKey !== _that.socketKey) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(payload.type) {
|
switch(payload.type) {
|
||||||
case "Close":
|
case "Close":
|
||||||
console.debug("SocketsForCordova: Close event, socket key: " + payload.socketKey);
|
//console.debug("SocketsForCordova: Close event, socket key: " + payload.socketKey);
|
||||||
window.document.removeEventListener(SOCKET_EVENT, socketEventHandler);
|
window.document.removeEventListener(SOCKET_EVENT, socketEventHandler);
|
||||||
socket.onClose();
|
_that.onClose();
|
||||||
break;
|
break;
|
||||||
case "DataReceived":
|
case "DataReceived":
|
||||||
console.debug("SocketsForCordova: DataReceived event, socket key: " + payload.socketKey);
|
//console.debug("SocketsForCordova: DataReceived event, socket key: " + payload.socketKey);
|
||||||
socket.onData(new Int8Array(payload.data));
|
_that.onData(new Int8Array(payload.data));
|
||||||
break;
|
break;
|
||||||
case "Error":
|
case "Error":
|
||||||
console.debug("SocketsForCordova: Error event, socket key: " + payload.socketKey);
|
//console.debug("SocketsForCordova: Error event, socket key: " + payload.socketKey);
|
||||||
socket.onError(payload.errorMessage);
|
_that.onError(payload.errorMessage);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
console.error("SocketsForCordova: Unknown event type " + payload.type + ", socket key: " + payload.socketKey);
|
console.error("SocketsForCordova: Unknown event type " + payload.type + ", socket key: " + payload.socketKey);
|
||||||
@ -89,13 +43,13 @@ Socket.prototype.open = function (host, port, success, error) {
|
|||||||
|
|
||||||
exec(
|
exec(
|
||||||
function() {
|
function() {
|
||||||
console.debug("SocketsForCordova: Socket successfully opened.");
|
//console.debug("SocketsForCordova: Socket successfully opened.");
|
||||||
window.document.addEventListener(SOCKET_EVENT, socketEventHandler);
|
window.document.addEventListener(SOCKET_EVENT, socketEventHandler);
|
||||||
if (success)
|
if (success)
|
||||||
success();
|
success();
|
||||||
},
|
},
|
||||||
function(errorMessage) {
|
function(errorMessage) {
|
||||||
console.error("SocketsForCordova: Error during opening socket. Error: " + errorMessage);
|
//console.error("SocketsForCordova: Error during opening socket. Error: " + errorMessage);
|
||||||
if (error)
|
if (error)
|
||||||
error(errorMessage);
|
error(errorMessage);
|
||||||
},
|
},
|
||||||
@ -112,12 +66,12 @@ Socket.prototype.write = function (data, success, error) {
|
|||||||
|
|
||||||
exec(
|
exec(
|
||||||
function() {
|
function() {
|
||||||
console.debug("SocketsForCordova: Data successfully written to socket. Number of bytes: " + data.length);
|
//console.debug("SocketsForCordova: Data successfully written to socket. Number of bytes: " + data.length);
|
||||||
if (success)
|
if (success)
|
||||||
success();
|
success();
|
||||||
},
|
},
|
||||||
function(errorMessage) {
|
function(errorMessage) {
|
||||||
console.error("SocketsForCordova: Error during writing data to socket. Error: " + errorMessage);
|
//console.error("SocketsForCordova: Error during writing data to socket. Error: " + errorMessage);
|
||||||
if (error)
|
if (error)
|
||||||
error(errorMessage);
|
error(errorMessage);
|
||||||
},
|
},
|
||||||
@ -134,13 +88,17 @@ Socket._copyToArray = function(array) {
|
|||||||
return outputArray;
|
return outputArray;
|
||||||
};
|
};
|
||||||
|
|
||||||
Socket.prototype.shutdownWrite = function () {
|
Socket.prototype.shutdownWrite = function (success, error) {
|
||||||
exec(
|
exec(
|
||||||
function() {
|
function() {
|
||||||
console.debug("SocketsForCordova: Shutdown write successfully called.");
|
//console.debug("SocketsForCordova: Shutdown write successfully called.");
|
||||||
|
if (success)
|
||||||
|
success();
|
||||||
},
|
},
|
||||||
function(errorMessage) {
|
function(errorMessage) {
|
||||||
console.error("SocketsForCordova: Error when call shutdownWrite on socket. Error: " + errorMessage);
|
//console.error("SocketsForCordova: Error when call shutdownWrite on socket. Error: " + errorMessage);
|
||||||
|
if (error)
|
||||||
|
error(errorMessage);
|
||||||
},
|
},
|
||||||
CORDOVA_SERVICE_NAME,
|
CORDOVA_SERVICE_NAME,
|
||||||
"shutdownWrite",
|
"shutdownWrite",
|
||||||
@ -150,10 +108,14 @@ Socket.prototype.shutdownWrite = function () {
|
|||||||
Socket.prototype.close = function () {
|
Socket.prototype.close = function () {
|
||||||
exec(
|
exec(
|
||||||
function() {
|
function() {
|
||||||
console.debug("SocketsForCordova: Close successfully called.");
|
//console.debug("SocketsForCordova: Close successfully called.");
|
||||||
|
if (success)
|
||||||
|
success();
|
||||||
},
|
},
|
||||||
function(errorMessage) {
|
function(errorMessage) {
|
||||||
console.error("SocketsForCordova: Error when call close on socket. Error: " + errorMessage);
|
//console.error("SocketsForCordova: Error when call close on socket. Error: " + errorMessage);
|
||||||
|
if (error)
|
||||||
|
error(errorMessage);
|
||||||
},
|
},
|
||||||
CORDOVA_SERVICE_NAME,
|
CORDOVA_SERVICE_NAME,
|
||||||
"close",
|
"close",
|
||||||
|
Loading…
Reference in New Issue
Block a user