Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
U
ulakbus-ui
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ulakbus
ulakbus-ui
Commits
a90072a7
Commit
a90072a7
authored
Apr 07, 2016
by
Evren Kutar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
FIX improve websocket for no internet, reconnect, ping etc error cases
ADD task_list dynamic dispatch function
parent
0324659d
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
4 deletions
+19
-4
socket.js
app/zetalib/socket.js
+19
-4
No files found.
app/zetalib/socket.js
View file @
a90072a7
...
@@ -25,7 +25,7 @@ angular.module('ulakbus')
...
@@ -25,7 +25,7 @@ angular.module('ulakbus')
/**
/**
* WSOps operates all websocket interactions
* WSOps operates all websocket interactions
*/
*/
.
factory
(
'WSOps'
,
function
(
WSUri
,
$q
,
$log
,
$rootScope
,
$timeout
,
ErrorService
,
WS
)
{
.
factory
(
'WSOps'
,
function
(
WSUri
,
$q
,
$log
,
$rootScope
,
$timeout
,
ErrorService
,
WS
,
IsOnline
)
{
$rootScope
.
$on
(
'ws_turn_on'
,
function
()
{
$rootScope
.
$on
(
'ws_turn_on'
,
function
()
{
generate_ws
();
generate_ws
();
});
});
...
@@ -71,10 +71,20 @@ angular.module('ulakbus')
...
@@ -71,10 +71,20 @@ angular.module('ulakbus')
};
};
var
wsOps
=
{};
var
wsOps
=
{};
var
pingCounter
=
0
;
var
checkPing
=
function
()
{
if
(
pingCounter
>
2
)
{
websocket
.
close
();
$log
.
debug
(
"websocket not pong"
);
pingCounter
=
0
;
}
};
var
keepAlivePing
=
function
(
interval
)
{
var
keepAlivePing
=
function
(
interval
)
{
return
setInterval
(
function
()
{
return
setInterval
(
function
()
{
if
(
$rootScope
.
websocketIsOpen
)
{
if
(
$rootScope
.
websocketIsOpen
&&
IsOnline
.
get_status
()
)
{
wsOps
.
doSend
(
angular
.
toJson
({
data
:
{
view
:
"ping"
}}));
wsOps
.
doSend
(
angular
.
toJson
({
data
:
{
view
:
"ping"
}}));
pingCounter
+=
1
;
checkPing
();
}
else
{
}
else
{
$timeout
(
function
()
{
$timeout
(
function
()
{
this
(
interval
);
this
(
interval
);
...
@@ -85,7 +95,7 @@ angular.module('ulakbus')
...
@@ -85,7 +95,7 @@ angular.module('ulakbus')
wsOps
.
onOpen
=
function
(
evt
)
{
wsOps
.
onOpen
=
function
(
evt
)
{
$rootScope
.
websocketIsOpen
=
true
;
$rootScope
.
websocketIsOpen
=
true
;
$log
.
info
(
"CONNECTED"
,
evt
);
$log
.
info
(
"CONNECTED"
,
evt
);
keepAlivePing
(
3
0000
);
keepAlivePing
(
2
0000
);
wsOps
.
loggedOut
=
false
;
wsOps
.
loggedOut
=
false
;
};
};
wsOps
.
onClose
=
function
(
event
)
{
wsOps
.
onClose
=
function
(
event
)
{
...
@@ -106,6 +116,8 @@ angular.module('ulakbus')
...
@@ -106,6 +116,8 @@ angular.module('ulakbus')
callback
.
resolve
(
data
);
callback
.
resolve
(
data
);
}
else
{
}
else
{
$log
.
info
(
"Data without callback: %o"
,
data
);
$log
.
info
(
"Data without callback: %o"
,
data
);
// if pong in msg
if
(
msg_data
.
msg
===
'pong'
)
{
pingCounter
-=
1
;}
}
}
},
},
error
:
function
()
{
error
:
function
()
{
...
@@ -118,6 +130,9 @@ angular.module('ulakbus')
...
@@ -118,6 +130,9 @@ angular.module('ulakbus')
var
callback
=
wsOps
.
callbacks
[
msg_data
.
callbackID
];
var
callback
=
wsOps
.
callbacks
[
msg_data
.
callbackID
];
delete
wsOps
.
callbacks
[
msg_data
.
callbackID
];
delete
wsOps
.
callbacks
[
msg_data
.
callbackID
];
callback
.
resolve
(
msg_data
);
callback
.
resolve
(
msg_data
);
},
task_list
:
function
()
{
$rootScope
.
$broadcast
(
'task_list'
,
msg_data
[
"task_list"
]);
}
}
};
};
// do_action is the dispatcher function for incoming events
// do_action is the dispatcher function for incoming events
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment