Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Cesium
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
clients
Cesium-grp
Cesium
Commits
abfcd34c
Commit
abfcd34c
authored
7 years ago
by
Benoit Lavenier
Browse files
Options
Downloads
Patches
Plain Diff
[fix] reopen websocket when closing by navigator or server - fix
#535
[fix] Network: do not try to access a node without valid host - fix
#537
parent
e3e81f4d
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
www/js/services/bma-services.js
+3
-3
3 additions, 3 deletions
www/js/services/bma-services.js
www/js/services/http-services.js
+52
-19
52 additions, 19 deletions
www/js/services/http-services.js
www/js/services/network-services.js
+2
-2
2 additions, 2 deletions
www/js/services/network-services.js
with
57 additions
and
24 deletions
www/js/services/bma-services.js
+
3
−
3
View file @
abfcd34c
...
...
@@ -193,12 +193,12 @@ angular.module('cesium.bma.services', ['ngApi', 'cesium.http.services', 'cesium.
// Override close methods (add a usage counter)
sock
.
_counter
=
1
;
var
c
lose
=
sock
.
close
;
var
inheritedC
lose
=
sock
.
close
;
sock
.
close
=
function
()
{
sock
.
_counter
--
;
if
(
sock
.
_counter
<=
0
)
{
console
.
debug
(
'
[BMA]
Stopp
ing websocket [
'
+
path
+
'
]
'
);
c
lose
();
console
.
debug
(
'
[BMA]
Clos
ing websocket [
'
+
path
+
'
]
'
);
inheritedC
lose
();
delete
that
.
cache
.
wsByPath
[
path
];
}
};
...
...
This diff is collapsed.
Click to expand it.
www/js/services/http-services.js
+
52
−
19
View file @
abfcd34c
...
...
@@ -63,6 +63,10 @@ angular.module('cesium.http.services', ['cesium.cache.services'])
}
function
getResource
(
host
,
port
,
path
,
useSsl
,
forcedTimeout
)
{
// Make sure host is defined - fix #537
if
(
!
host
)
{
return
$q
.
reject
(
'
[http] invalid URL from host:
'
+
host
);
}
var
url
=
getUrl
(
host
,
port
,
path
,
useSsl
);
return
function
(
params
)
{
return
$q
(
function
(
resolve
,
reject
)
{
...
...
@@ -149,35 +153,64 @@ angular.module('cesium.http.services', ['cesium.cache.services'])
throw
'
calling csHttp.ws without path argument
'
;
}
var
uri
=
getWsUrl
(
host
,
port
,
path
,
useSsl
);
var
sock
=
null
;
var
delegate
=
null
;
var
callbacks
=
[];
function
_waitOpen
()
{
if
(
!
sock
)
throw
new
Error
(
'
Websocket not opened
'
);
if
(
sock
.
readyState
==
1
)
{
return
$q
.
when
(
sock
);
if
(
!
delegate
)
throw
new
Error
(
'
Websocket not opened
'
);
if
(
delegate
.
readyState
==
1
)
{
return
$q
.
when
(
delegate
);
}
if
(
sock
.
readyState
==
3
)
{
return
$q
.
reject
(
'
Unable to connect to Websocket [
'
+
sock
.
url
+
'
]
'
);
if
(
delegate
.
readyState
==
3
)
{
return
$q
.
reject
(
'
Unable to connect to Websocket [
'
+
delegate
.
url
+
'
]
'
);
}
return
$timeout
(
_waitOpen
,
100
);
console
.
debug
(
'
[http] Waiting websocket [
'
+
path
+
'
] openning...
'
);
return
$timeout
(
_waitOpen
,
200
);
}
function
_open
(
self
,
callback
,
params
)
{
if
(
!
sock
)
{
if
(
!
delegate
)
{
self
.
path
=
path
;
prepare
(
uri
,
params
,
{},
function
(
uri
)
{
console
.
debug
(
'
[http] Listening on websocket [
'
+
path
+
'
]...
'
);
sock
=
new
WebSocket
(
uri
);
sock
.
onerror
=
function
(
e
)
{
sock
.
readyState
=
3
;
delegate
=
new
WebSocket
(
uri
);
delegate
.
onerror
=
function
(
e
)
{
delegate
.
readyState
=
3
;
};
sock
.
onmessage
=
function
(
e
)
{
delegate
.
onmessage
=
function
(
e
)
{
var
obj
=
JSON
.
parse
(
e
.
data
);
_
.
forEach
(
callbacks
,
function
(
callback
)
{
callback
(
obj
);
});
};
delegate
.
onopen
=
function
(
e
)
{
console
.
debug
(
'
[http] Listening on websocket [
'
+
path
+
'
]...
'
);
sockets
.
push
(
self
);
delegate
.
openTime
=
new
Date
().
getTime
();
};
delegate
.
onclose
=
function
()
{
// Remove from sockets arrays
var
index
=
_
.
findIndex
(
sockets
,
function
(
socket
){
return
socket
.
path
===
path
;});
if
(
index
>=
0
)
{
sockets
.
splice
(
index
,
1
);
}
// If close event comes from Cesium
if
(
delegate
.
closing
)
{
delegate
=
null
;
}
// If unexpected close event, reopen the socket (fix #535)
else
{
console
.
debug
(
'
[http] Unexpected close of websocket [
'
+
path
+
'
] (open
'
+
(
new
Date
().
getTime
()
-
delegate
.
openTime
)
+
'
ms ago): re-opening...
'
);
delegate
=
null
;
// Loop, but without the already registered callback
_open
(
self
,
null
,
params
);
}
};
});
}
if
(
callback
)
callbacks
.
push
(
callback
);
...
...
@@ -194,14 +227,14 @@ angular.module('cesium.http.services', ['cesium.cache.services'])
send
:
function
(
data
)
{
return
_waitOpen
()
.
then
(
function
(){
sock
.
send
(
data
);
delegate
.
send
(
data
);
});
},
close
:
function
()
{
if
(
sock
)
{
console
.
debug
(
'
[http] Stopping websocket [
'
+
path
+
'
]...
'
)
;
sock
.
close
(
);
sock
=
null
;
if
(
delegate
)
{
delegate
.
closing
=
true
;
console
.
debug
(
'
[http] Closing websocket [
'
+
path
+
'
]...
'
);
delegate
.
close
()
;
callbacks
=
[];
}
}
...
...
This diff is collapsed.
Click to expand it.
www/js/services/network-services.js
+
2
−
2
View file @
abfcd34c
...
...
@@ -308,7 +308,7 @@ angular.module('cesium.network.services', ['ngApi', 'cesium.bma.services', 'cesi
// Apply filter
if
(
!
applyPeerFilter
(
peer
))
return
$q
.
when
();
if
(
!
data
.
filter
.
online
||
(
data
.
filter
.
online
===
'
all
'
&&
peer
.
status
===
'
DOWN
'
))
{
if
(
!
data
.
filter
.
online
||
(
data
.
filter
.
online
===
'
all
'
&&
peer
.
status
===
'
DOWN
'
)
||
!
peer
.
getHost
()
/*fix #537*/
)
{
peer
.
online
=
false
;
return
$q
.
when
(
peer
);
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment