[FIX] point_of_sale: prevent barcode scanner connection loss
bzr revid: fva@openerp.com-20140127123614-vjrcwgh7s8rs2y2u
This commit is contained in:
parent
c9879fcd1e
commit
85daaccb61
|
@ -129,6 +129,8 @@ function openerp_pos_devices(instance,module){ //module is instance.point_of_sal
|
||||||
this.set_connection_status('disconnected');
|
this.set_connection_status('disconnected');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// connects to the specified url
|
||||||
connect: function(url){
|
connect: function(url){
|
||||||
var self = this;
|
var self = this;
|
||||||
this.connection = new instance.web.Session(undefined,url);
|
this.connection = new instance.web.Session(undefined,url);
|
||||||
|
@ -149,35 +151,43 @@ function openerp_pos_devices(instance,module){ //module is instance.point_of_sal
|
||||||
console.error('Could not connect to the Proxy');
|
console.error('Could not connect to the Proxy');
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
autoconnect: function(opts){
|
|
||||||
|
// find a proxy and connects to it. for options see find_proxy
|
||||||
|
autoconnect: function(options){
|
||||||
var self = this;
|
var self = this;
|
||||||
this.set_connection_status('connecting',{});
|
this.set_connection_status('connecting',{});
|
||||||
var success = new $.Deferred();
|
var success = new $.Deferred();
|
||||||
this.find_proxy(opts)
|
this.find_proxy(options)
|
||||||
.then(function(proxies){
|
.then(function(proxies){
|
||||||
if(proxies.length > 0){
|
if(proxies.length > 0){
|
||||||
self.connect(proxies[0])
|
self.connect(proxies[0])
|
||||||
.then(function(){
|
.then(function(){
|
||||||
success.resolve();
|
success.resolve();
|
||||||
},function(){
|
},function(){
|
||||||
|
self.set_connection_status('disconnected');
|
||||||
success.reject();
|
success.reject();
|
||||||
});
|
});
|
||||||
}else{
|
}else{
|
||||||
|
self.set_connection_status('disconnected');
|
||||||
success.reject();
|
success.reject();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return success;
|
return success;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// starts a loop that updates the connection status
|
||||||
keepalive: function(){
|
keepalive: function(){
|
||||||
var self = this;
|
var self = this;
|
||||||
if(!this.keptalive){
|
if(!this.keptalive){
|
||||||
this.keptalive = true;
|
this.keptalive = true;
|
||||||
function status(){
|
function status(){
|
||||||
self.connection.rpc('/hw_proxy/status_json',{})
|
self.connection.rpc('/hw_proxy/status_json',{},{timeout:500})
|
||||||
.then(function(driver_status){
|
.then(function(driver_status){
|
||||||
self.set_connection_status('connected',driver_status);
|
self.set_connection_status('connected',driver_status);
|
||||||
},function(){
|
},function(){
|
||||||
self.set_connection_status('disconnected');
|
if(self.get('status').status !== 'connecting'){
|
||||||
|
self.set_connection_status('disconnected');
|
||||||
|
}
|
||||||
}).always(function(){
|
}).always(function(){
|
||||||
setTimeout(status,5000);
|
setTimeout(status,5000);
|
||||||
});
|
});
|
||||||
|
@ -185,6 +195,7 @@ function openerp_pos_devices(instance,module){ //module is instance.point_of_sal
|
||||||
status();
|
status();
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
message : function(name,params){
|
message : function(name,params){
|
||||||
var callbacks = this.notifications[name] || [];
|
var callbacks = this.notifications[name] || [];
|
||||||
for(var i = 0; i < callbacks.length; i++){
|
for(var i = 0; i < callbacks.length; i++){
|
||||||
|
@ -197,18 +208,15 @@ function openerp_pos_devices(instance,module){ //module is instance.point_of_sal
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
test_connection: function(host,timeout){
|
// returns as a deferred a list of valid hosts urls that can be used as proxy.
|
||||||
return $.ajax({
|
// options:
|
||||||
url: host + '/hw_proxy/hello',
|
// - port: what port to listen to (default 8069)
|
||||||
method: 'GET',
|
// - force_ip : limit the search to the specified ip
|
||||||
timeout: timeout || 10000,
|
// - progress(fac) : callback for search progress ( fac in [0,1] )
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
find_proxy: function(options){
|
find_proxy: function(options){
|
||||||
options = options || {};
|
options = options || {};
|
||||||
var self = this;
|
var self = this;
|
||||||
var port = ':8069';
|
var port = ':' + (options.port || '8069');
|
||||||
var urls = [];
|
var urls = [];
|
||||||
var found = false;
|
var found = false;
|
||||||
var proxies = [];
|
var proxies = [];
|
||||||
|
@ -249,8 +257,11 @@ function openerp_pos_devices(instance,module){ //module is instance.point_of_sal
|
||||||
if(!url){
|
if(!url){
|
||||||
done.resolve();
|
done.resolve();
|
||||||
}
|
}
|
||||||
var c = self.test_connection(url, 300)
|
var c = $.ajax({
|
||||||
.done(function(){
|
url: url + '/hw_proxy/hello',
|
||||||
|
method: 'GET',
|
||||||
|
timeout: 300,
|
||||||
|
}).done(function(){
|
||||||
found = true;
|
found = true;
|
||||||
update_progress();
|
update_progress();
|
||||||
proxies.push(url);
|
proxies.push(url);
|
||||||
|
@ -757,10 +768,10 @@ function openerp_pos_devices(instance,module){ //module is instance.point_of_sal
|
||||||
disconnect: function(){
|
disconnect: function(){
|
||||||
$('body').off('keypress', this.handler)
|
$('body').off('keypress', this.handler)
|
||||||
},
|
},
|
||||||
disconnect_from_proxy: function(){
|
|
||||||
this.remote_scanning = false;
|
// the barcode scanner will listen on the hw_proxy/scanner interface for
|
||||||
},
|
// scan events until disconnect_from_proxy is called
|
||||||
connect_to_proxy: function(){ //FIXME prevent connection losses
|
connect_to_proxy: function(){
|
||||||
var self = this;
|
var self = this;
|
||||||
this.remote_scanning = true;
|
this.remote_scanning = true;
|
||||||
if(this.remote_active >= 1){
|
if(this.remote_active >= 1){
|
||||||
|
@ -769,17 +780,18 @@ function openerp_pos_devices(instance,module){ //module is instance.point_of_sal
|
||||||
this.remote_active = 1;
|
this.remote_active = 1;
|
||||||
|
|
||||||
function waitforbarcode(){
|
function waitforbarcode(){
|
||||||
return self.proxy.connection.rpc('/hw_proxy/scanner',{}).then(function(barcode){
|
return self.proxy.connection.rpc('/hw_proxy/scanner',{},{timeout:7500})
|
||||||
self.scan(barcode);
|
.then(function(barcode){
|
||||||
if(!self.remote_scanning){
|
if(!self.remote_scanning){
|
||||||
this.remote_active = 0;
|
self.remote_active = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
self.scan(barcode);
|
||||||
waitforbarcode();
|
waitforbarcode();
|
||||||
},
|
},
|
||||||
function(){
|
function(){
|
||||||
if(!self.remote_scanning){
|
if(!self.remote_scanning){
|
||||||
this.remote_active = 0;
|
self.remote_active = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setTimeout(waitforbarcode,5000);
|
setTimeout(waitforbarcode,5000);
|
||||||
|
@ -787,6 +799,11 @@ function openerp_pos_devices(instance,module){ //module is instance.point_of_sal
|
||||||
}
|
}
|
||||||
waitforbarcode();
|
waitforbarcode();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// the barcode scanner will stop listening on the hw_proxy/scanner remote interface
|
||||||
|
disconnect_from_proxy: function(){
|
||||||
|
this.remote_scanning = false;
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue