Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
testcenter-frontend
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Contributor analytics
CI/CD analytics
Repository analytics
Insights
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
IQB
discontinued
testcenter-frontend
Commits
e14f88a3
Commit
e14f88a3
authored
4 years ago
by
paf
Browse files
Options
Downloads
Patches
Plain Diff
use provided url for websocket (going to be authetification asd well)
parent
f9f321a0
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/app/group-monitor/websocket-backend.service.ts
+14
-14
14 additions, 14 deletions
src/app/group-monitor/websocket-backend.service.ts
src/app/group-monitor/websocket.service.ts
+18
-25
18 additions, 25 deletions
src/app/group-monitor/websocket.service.ts
with
32 additions
and
39 deletions
src/app/group-monitor/websocket-backend.service.ts
+
14
−
14
View file @
e14f88a3
...
@@ -62,26 +62,26 @@ export abstract class WebsocketBackendService<T> extends WebsocketService implem
...
@@ -62,26 +62,26 @@ export abstract class WebsocketBackendService<T> extends WebsocketService implem
.
get
<
T
>
(
this
.
serverUrl
+
this
.
pollingEndpoint
,
{
observe
:
'
response
'
})
.
get
<
T
>
(
this
.
serverUrl
+
this
.
pollingEndpoint
,
{
observe
:
'
response
'
})
.
pipe
(
.
pipe
(
catchError
((
err
:
ApiError
)
=>
{
catchError
((
err
:
ApiError
)
=>
{
console
.
warn
(
`Api-Error:
${
err
.
code
}
${
err
.
info
}
`
);
console
.
warn
(
`Api-Error:
${
err
.
code
}
${
err
.
info
}
`
);
this
.
connectionStatus$
.
next
(
"
error
"
);
this
.
connectionStatus$
.
next
(
"
error
"
);
return
of
([])
return
of
([])
})
})
)
)
.
subscribe
((
response
:
HttpResponse
<
T
>
)
=>
{
.
subscribe
((
response
:
HttpResponse
<
T
>
)
=>
{
this
.
data$
.
next
(
response
.
body
);
this
.
data$
.
next
(
response
.
body
);
if
(
response
.
headers
.
has
(
'
SubscribeURI
'
))
{
if
(
response
.
headers
.
has
(
'
SubscribeURI
'
))
{
console
.
log
(
'
switch to websocket-mode
'
);
this
.
wsUrl
=
response
.
headers
.
get
(
'
SubscribeURI
'
);
this
.
urlParam
=
response
.
headers
.
get
(
'
SubscribeURI
'
);
console
.
log
(
'
switch to websocket-mode
'
);
this
.
subScribeTo
StatusUpdate
WsChannel
();
this
.
subScribeToWsChannel
();
}
else
{
}
else
{
this
.
connectionStatus$
.
next
(
"
polling-sleep
"
);
this
.
connectionStatus$
.
next
(
"
polling-sleep
"
);
this
.
scheduleNextPoll
();
this
.
scheduleNextPoll
();
}
}
});
});
}
}
...
@@ -122,12 +122,12 @@ export abstract class WebsocketBackendService<T> extends WebsocketService implem
...
@@ -122,12 +122,12 @@ export abstract class WebsocketBackendService<T> extends WebsocketService implem
}
}
private
subScribeTo
StatusUpdate
WsChannel
()
{
private
subScribeToWsChannel
()
{
this
.
wsDataSubscription
=
this
.
getChannel
<
T
>
(
this
.
wsChannelName
)
this
.
wsDataSubscription
=
this
.
getChannel
<
T
>
(
this
.
wsChannelName
)
.
subscribe
((
dataObject
:
T
)
=>
this
.
data$
.
next
(
dataObject
));
// subscribe only next, not complete!
.
subscribe
((
dataObject
:
T
)
=>
this
.
data$
.
next
(
dataObject
));
// subscribe only next, not complete!
this
.
wsConnectionStatusSubscription
=
this
.
s
ervice
Connected$
this
.
wsConnectionStatusSubscription
=
this
.
w
sConnected$
.
pipe
(
.
pipe
(
skipWhile
((
item
:
boolean
)
=>
item
===
null
),
// skip pre-init-state
skipWhile
((
item
:
boolean
)
=>
item
===
null
),
// skip pre-init-state
tap
((
wsConnected
:
boolean
)
=>
{
tap
((
wsConnected
:
boolean
)
=>
{
...
...
This diff is collapsed.
Click to expand it.
src/app/group-monitor/websocket.service.ts
+
18
−
25
View file @
e14f88a3
...
@@ -10,12 +10,11 @@ interface WsMessage {
...
@@ -10,12 +10,11 @@ interface WsMessage {
export
class
WebsocketService
{
export
class
WebsocketService
{
protected
url
=
'
ws://127.0.0.1:3000
'
;
protected
wsUrl
:
string
=
""
;
protected
urlParam
=
"
XYZ
"
;
private
w
ebSocket
Subject$
:
WebSocketSubject
<
any
>
;
private
w
s
Subject$
:
WebSocketSubject
<
any
>
;
public
s
ervice
Connected$
=
new
BehaviorSubject
<
boolean
>
(
null
);
public
w
sConnected$
=
new
BehaviorSubject
<
boolean
>
(
null
);
constructor
(
constructor
(
...
@@ -23,17 +22,13 @@ export class WebsocketService {
...
@@ -23,17 +22,13 @@ export class WebsocketService {
}
}
public
connect
(
urlParam
:
string
,
forceReconnect
:
boolean
=
false
):
WebSocketSubject
<
any
>
{
public
connect
(
)
{
this
.
urlParam
=
urlParam
;
if
(
!
this
.
wsSubject$
)
{
//
cons
t url = 'wss://echo.websocket.org'
;
cons
ole
.
log
(
'
connecting...
'
+
this
.
wsUrl
)
;
if
(
!
this
.
webSocketSubject$
||
forceReconnect
)
{
this
.
wsSubject$
=
webSocket
({
console
.
log
(
'
connecting...
'
+
urlParam
);
this
.
webSocketSubject$
=
webSocket
({
deserializer
(
event
:
MessageEvent
):
any
{
deserializer
(
event
:
MessageEvent
):
any
{
return
JSON
.
parse
(
event
.
data
);
return
JSON
.
parse
(
event
.
data
);
...
@@ -46,50 +41,48 @@ export class WebsocketService {
...
@@ -46,50 +41,48 @@ export class WebsocketService {
openObserver
:
{
openObserver
:
{
next
:
()
=>
{
next
:
()
=>
{
console
.
log
(
'
connection established
'
);
console
.
log
(
'
connection established
'
);
this
.
s
ervice
Connected$
.
next
(
true
);
this
.
w
sConnected$
.
next
(
true
);
}
}
},
},
url
:
this
.
url
+
'
/
'
+
urlParam
url
:
this
.
wsUrl
});
});
this
.
w
ebSocket
Subject$
.
subscribe
(
this
.
w
s
Subject$
.
subscribe
(
()
=>
{},
()
=>
{},
()
=>
{
()
=>
{
console
.
log
(
'
connection error
'
);
console
.
log
(
'
connection error
'
);
this
.
s
ervice
Connected$
.
next
(
false
);
this
.
w
sConnected$
.
next
(
false
);
},
},
()
=>
{
()
=>
{
console
.
log
(
'
connection closed
'
);
console
.
log
(
'
connection closed
'
);
this
.
s
ervice
Connected$
.
next
(
false
);
this
.
w
sConnected$
.
next
(
false
);
}
}
);
);
}
}
return
this
.
webSocketSubject$
;
}
}
public
send
(
event
:
string
,
data
:
any
)
{
public
send
(
event
:
string
,
data
:
any
)
{
if
(
!
this
.
w
ebSocket
Subject$
)
{
if
(
!
this
.
w
s
Subject$
)
{
this
.
connect
(
this
.
urlParam
);
this
.
connect
();
}
}
this
.
w
ebSocket
Subject$
.
next
({
event
,
data
});
this
.
w
s
Subject$
.
next
({
event
,
data
});
}
}
public
getChannel
<
T
>
(
channelName
:
string
):
Observable
<
T
>
{
public
getChannel
<
T
>
(
channelName
:
string
):
Observable
<
T
>
{
if
(
!
this
.
w
ebSocket
Subject$
)
{
if
(
!
this
.
w
s
Subject$
)
{
this
.
connect
(
this
.
urlParam
);
this
.
connect
();
}
}
return
this
.
w
ebSocket
Subject$
return
this
.
w
s
Subject$
.
multiplex
(
.
multiplex
(
()
=>
({
event
:
`subscribe:
${
channelName
}
`
}),
()
=>
({
event
:
`subscribe:
${
channelName
}
`
}),
()
=>
({
event
:
`unsubscribe:
${
channelName
}
`
}),
()
=>
({
event
:
`unsubscribe:
${
channelName
}
`
}),
...
...
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