Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
Papermerge.Js
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
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
Jonas Leder
Papermerge.Js
Commits
e8b80f40
Commit
e8b80f40
authored
3 years ago
by
Eugen Ciur
Browse files
Options
Downloads
Patches
Plain Diff
basic handling of websockets
parent
0e494433
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
app/components/viewer/index.js
+11
-0
11 additions, 0 deletions
app/components/viewer/index.js
app/services/websockets.js
+37
-0
37 additions, 0 deletions
app/services/websockets.js
config/environment.js
+3
-1
3 additions, 1 deletion
config/environment.js
with
51 additions
and
1 deletion
app/components/viewer/index.js
+
11
−
0
View file @
e8b80f40
...
...
@@ -6,6 +6,17 @@ import { inject as service } from '@ember/service';
export
default
class
ViewComponent
extends
Component
{
@
service
requests
;
@
service
websockets
;
constructor
(
owner
,
args
)
{
super
(
owner
,
args
);
this
.
websockets
.
addHandler
(
this
.
messageHandler
,
this
);
}
messageHandler
(
message
)
{
console
.
log
(
message
);
}
@
action
onRunOCR
()
{
...
...
This diff is collapsed.
Click to expand it.
app/services/websockets.js
0 → 100644
+
37
−
0
View file @
e8b80f40
import
ENV
from
'
papermerge/config/environment
'
;
import
Service
from
'
@ember/service
'
;
export
default
class
Websockets
extends
Service
{
constructor
(
owner
,
args
)
{
super
(
owner
,
args
);
let
that
=
this
;
this
.
_socket
=
new
WebSocket
(
this
.
base_url
);
this
.
_handlers
=
[];
this
.
_socket
.
onmessage
=
function
(
event
)
{
that
.
_handlers
.
forEach
((
item
)
=>
{
let
json_data
;
try
{
json_data
=
JSON
.
parse
(
event
.
data
);
item
.
handler
.
apply
(
item
.
context
,
[
json_data
,
event
]);
}
catch
(
err
)
{
console
.
log
(
`Error while parsing incoming data:
${
event
.
data
}
`
);
}
});
}
}
get
base_url
()
{
return
`
${
ENV
.
APP
.
WS_HOST
}
/
${
ENV
.
APP
.
WS_NAMESPACE
}
`
;
}
addHandler
(
handler
,
context
)
{
this
.
_handlers
.
push
({
handler
,
context
});
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
config/environment.js
+
3
−
1
View file @
e8b80f40
...
...
@@ -18,7 +18,8 @@ module.exports = function (environment) {
},
APP
:
{
NAMESPACE
:
'
api
'
NAMESPACE
:
'
api
'
,
WS_NAMESPACE
:
'
ws/document
'
// websockets namespace
// Here you can pass flags/options to your application instance
// when it is created
},
...
...
@@ -26,6 +27,7 @@ module.exports = function (environment) {
if
(
environment
===
'
development
'
)
{
ENV
.
APP
.
HOST
=
'
http://127.0.0.1:8000
'
ENV
.
APP
.
WS_HOST
=
'
ws://127.0.0.1:8000
'
//websockets
// ENV.APP.LOG_RESOLVER = true;
// ENV.APP.LOG_ACTIVE_GENERATION = true;
// ENV.APP.LOG_TRANSITIONS = true;
...
...
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