Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
ehasa-frontend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue 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
WIMMA Lab 2019
Overflow
ehasa-frontend
Commits
c51cfb89
Commit
c51cfb89
authored
5 years ago
by
Ronnie Friman
Browse files
Options
Downloads
Patches
Plain Diff
added socket listener
parent
6d963478
No related branches found
No related tags found
2 merge requests
!31
Development
,
!27
Socket update
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/App.js
+5
-0
5 additions, 0 deletions
src/App.js
src/components/Socket.js
+42
-0
42 additions, 0 deletions
src/components/Socket.js
with
47 additions
and
0 deletions
src/App.js
+
5
−
0
View file @
c51cfb89
...
@@ -3,6 +3,7 @@ import "../node_modules/leaflet-draw/dist/leaflet.draw.css";
...
@@ -3,6 +3,7 @@ import "../node_modules/leaflet-draw/dist/leaflet.draw.css";
import
"
./App.css
"
;
import
"
./App.css
"
;
import
UserMap
from
"
./components/UserMap
"
;
import
UserMap
from
"
./components/UserMap
"
;
import
Header
from
"
./components/Header
"
;
import
Header
from
"
./components/Header
"
;
import
ClientSocket
from
"
./components/Socket
"
;
class
App
extends
Component
{
class
App
extends
Component
{
constructor
()
{
constructor
()
{
...
@@ -57,6 +58,10 @@ class App extends Component {
...
@@ -57,6 +58,10 @@ class App extends Component {
handleLayerChange
=
{
this
.
handleLayerChange
}
handleLayerChange
=
{
this
.
handleLayerChange
}
handleGameChange
=
{
this
.
handleGameChange
}
handleGameChange
=
{
this
.
handleGameChange
}
/
>
/
>
,
{
this
.
state
.
currentGameId
&&
(
<
ClientSocket
gameId
=
{
this
.
state
.
currentGameId
}
/
>
)}
<
/div
>
<
/div
>
);
);
}
}
...
...
This diff is collapsed.
Click to expand it.
src/components/Socket.js
0 → 100644
+
42
−
0
View file @
c51cfb89
import
React
from
"
react
"
;
import
io
from
"
socket.io-client
"
;
const
socketUrl
=
process
.
env
.
REACT_APP_API_URL
;
export
default
class
ClientSocket
extends
React
.
Component
{
constructor
(
props
)
{
super
(
props
);
this
.
state
=
{
// stores the socket object for notifications
sock
:
null
,
// stores updates sent by socket
update
:
null
};
}
// iniate the socket on component mount
componentWillMount
()
{
console
.
log
(
"
iniated socket
"
);
this
.
initSocket
();
}
// disconnect the socket on component dismount
componentWillUnmount
()
{
this
.
state
.
sock
.
disconnect
();
}
initSocket
=
()
=>
{
const
socket
=
io
(
socketUrl
);
// set the socket to listen gameId-thread
socket
.
on
(
this
.
props
.
gameId
,
data
=>
{
// check socket update type
this
.
setState
({
update
:
data
});
console
.
log
(
this
.
state
.
update
);
});
this
.
setState
({
sock
:
socket
});
};
render
()
{
return
null
;
}
}
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