Skip to content

Commit

Permalink
- added: touch handler cancel operation
Browse files Browse the repository at this point in the history
- added: ws_fallback function in controller
  • Loading branch information
infinity0n3 committed Jan 23, 2017
1 parent 186f31e commit df24c29
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 20 deletions.
4 changes: 0 additions & 4 deletions assets/js/jogtouch.js
Original file line number Diff line number Diff line change
Expand Up @@ -407,10 +407,6 @@

/*$document.on(EVENT_MOUSE_MOVE, (this._move = proxy(this.move, this))).*/

/*if ($.isFunction(options.touch)) {
$this.on(EVENT_TOUCH, options.touch);
}*/

$window.on(EVENT_RESIZE, (this._resize = proxy(this.resize, this)));
},

Expand Down
6 changes: 3 additions & 3 deletions assets/js/jquery.WebSocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@

// send data via jQuery ajax()
$.ajax({
async: false,
async: true, // changed from false to true because it blocked the UI, success will always be returned as true
type: ajax_method,
url: ajax_url,
data:ajax_data,
Expand Down Expand Up @@ -746,8 +746,8 @@
var ws, isNative = true;

// websocket support built in?
if (window.WebSocket) {
//if (false) {
//if (window.WebSocket) {
if (false) {
// in firefox we use MozWebSocket (but it seems that from now (FF 17) MozWebsocket is removed)
if (typeof(MozWebSocket) == 'function') {
ws = new MozWebSocket(url);
Expand Down
51 changes: 45 additions & 6 deletions controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -528,12 +528,51 @@ public function startTask()

public function ws_fallback()
{
$response['type'] = 'debug';
$response['data'] = array(
'message' => 'this is websocket fallback',
'method' => $this->input->method(true),
'data-get' => $this->input->get(),
'data-post' => $this->input->post() );
$method = $this->input->method(true);

$response = array("type" => "unknown", "data" => "");

if($method == "GET")
{
/*$request = $this->input->get();
$requestData = json_decode($request, true);*/

}
else if($method == "POST")
{
$request = $this->input->post("data");
$requestData = json_decode($request, true);

if(isset($requestData['function'])){
$function = $requestData['function'];
$functionParams = isset($requestData['params']) ? $requestData['params'] : '';

switch($function)
{
case "serial": {
$this->load->library('JogFactory', '', 'jogFactory');
$jogFactory = $this->jogFactory;

$method = $functionParams['method'];
$methodParam = $functionParams['value'];
$methodStamp = $functionParams['stamp'];

/*unset($data['method']);
unset($data['value']);
unset($data['stamp']);*/

if(method_exists($jogFactory, $method)){ //if method exists than do it
$response['data'] = $jogFactory = $this->jogFactory->$method($methodParam, $methodStamp);
$response['type'] = 'jog';
}
}
break;


}
}

}

$this->output->set_content_type('application/json')->set_output(json_encode($response));
}
Expand Down
13 changes: 6 additions & 7 deletions views/make/js.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
wsApp = (function(app) {

app.mytemp = 0;
app.ws = null;
app.socket = null;
app.ws_callbacks = {}

app.setMytest = function(value) {
Expand Down Expand Up @@ -51,14 +51,14 @@
'params' : data
};

ws.send( JSON.stringify(messageToSend) );

if($.isFunction(callback))
{
app.ws_callbacks[stamp] = callback;
console.log('adding callback for', stamp, app.ws_callbacks);
//~ console.log('=== adding callback for', stamp, app.ws_callbacks);
}

app.socket.send( JSON.stringify(messageToSend) );

return stamp;
};

Expand Down Expand Up @@ -94,7 +94,7 @@
//~ arguments: {arg1:"test1", arg2:"test2"}
};

app.ws = ws = $.WebSocket ('ws://'+socket_host+':'+socket_port, null, options);
app.socket = ws = $.WebSocket ('ws://'+socket_host+':'+socket_port, null, options);

// WebSocket onerror event triggered also in fallback
ws.onerror = function (e) {
Expand All @@ -105,11 +105,10 @@
// if connection is opened => start opening a pipe (multiplexing)
ws.onopen = function () {
console.log("ws: opened as ", ws.fallback?"fallback":"websocket");
//ws.send( JSON.stringify({data:'my data'}) );
};

ws.onmessage = function (e) {
//console.log(e.data);
//console.log('>> ws.onmessage', e);
try {

var obj = jQuery.parseJSON(e.data);
Expand Down
3 changes: 3 additions & 0 deletions views/std/jog_setup_js.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ function rotation(value)

function jogAction(e)
{
console.log("== jog_busy", jog_busy);
if(jog_busy)
return false;

Expand Down Expand Up @@ -174,9 +175,11 @@ function jogAction(e)
//fabApp.jogMdi(cmd);

jog_busy = true;
console.log("== jog_busy set to BUSY", jog_busy);
wsApp.jogMdi(cmd, function(e) {
console.log("wsApp, COMMAND COMPLETED", e);
jog_busy = false;
console.log("== jog_busy set to READY", jog_busy);
});

/*fabApp.jogMdi(cmd, function(e) {
Expand Down

0 comments on commit df24c29

Please sign in to comment.