Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
Menteur
Overview
Overview
Details
Activity
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
PLN
Menteur
Commits
02b95030
Unverified
Commit
02b95030
authored
Apr 19, 2020
by
PLN (Algolia)
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
client: Begin store implem, display last 20 messages
parent
24645257
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
35 deletions
+33
-35
App.vue
client/src/App.vue
+11
-25
Sockets.vue
client/src/Sockets.vue
+13
-8
HelloWorld.vue
client/src/components/HelloWorld.vue
+9
-2
No files found.
client/src/App.vue
View file @
02b95030
<
template
>
<
template
>
<div
id=
"app"
>
<div
id=
"app"
>
<HelloWorld
msg=
"Salut Menteur !"
/>
<HelloWorld
/>
<Sockets/>
<Sockets/>
<div
id=
"game"
>
<div
id=
"game"
>
<label
for=
"messages"
>
Choose a message:
</label>
<label
for=
"messages"
>
Choose a message:
</label>
...
@@ -18,35 +18,15 @@
...
@@ -18,35 +18,15 @@
<
script
>
<
script
>
import
Vue
from
'vue'
import
Vue
from
'vue'
import
Vuex
from
'vuex'
import
'es6-promise/auto'
// Needed for Promise polyfill
import
'es6-promise/auto'
// Needed for Promise polyfill
import
VueSocketIO
from
'vue-socket.io'
import
VueSocketIO
from
'vue-socket.io'
import
Vuex
,
{
mapGetters
,
mapMutations
}
from
'vuex'
;
import
HelloWorld
from
"./components/HelloWorld"
;
import
HelloWorld
from
"./components/HelloWorld"
;
import
Sockets
from
"./Sockets"
;
import
Sockets
from
"./Sockets"
;
import
{
store
}
from
'./vuex-store'
Vue
.
use
(
Vuex
);
Vue
.
use
(
Vuex
);
const
store
=
new
Vuex
.
Store
({
state
:
{
count
:
0
},
mutations
:
{
increment
(
state
)
{
state
.
count
++
},
decrement
(
state
)
{
state
.
count
++
}
}
// TODO: Use actions for VueX-SocketIO integration?
// actions: {
// "
<
ACTION_PREFIX
><
EVENT_NAME
>
"() {
// // do something
// }
// }
});
Vue
.
use
(
new
VueSocketIO
({
Vue
.
use
(
new
VueSocketIO
({
debug
:
true
,
debug
:
true
,
connection
:
'http://localhost:9042'
,
connection
:
'http://localhost:9042'
,
...
@@ -61,6 +41,7 @@
...
@@ -61,6 +41,7 @@
export
default
{
export
default
{
name
:
"App"
,
name
:
"App"
,
store
:
store
,
components
:
{
components
:
{
HelloWorld
,
HelloWorld
,
Sockets
Sockets
...
@@ -70,11 +51,16 @@
...
@@ -70,11 +51,16 @@
message
:
"WAITING"
message
:
"WAITING"
}
}
},
},
computed
:
{
...
mapGetters
([
'isConnected'
,
'name'
,
'socketMessage'
])
},
methods
:
{
methods
:
{
sendMessage: function(message) {
sendMessage
:
function
(
message
)
{
console
.
log
(
"User wants to send"
,
message
);
console
.
log
(
"User wants to send"
,
message
);
this
.
$socket
.
emit
(
"message"
,
message
);
this
.
$socket
.
emit
(
"message"
,
message
);
}
},
...
mapMutations
([
'setName'
]),
// ...mapActions(['setNumberToRemoteValue']),
}
}
};
};
...
...
client/src/Sockets.vue
View file @
02b95030
...
@@ -2,9 +2,16 @@
...
@@ -2,9 +2,16 @@
<div>
<div>
<p
v-if=
"isConnected"
>
We're connected to the server!
</p>
<p
v-if=
"isConnected"
>
We're connected to the server!
</p>
<p
v-if=
"!isConnected"
>
We're not connected yet...
</p>
<p
v-if=
"!isConnected"
>
We're not connected yet...
</p>
<div
v-if=
"socketMessage != null"
>
<p>
Message from server: "
{{
socketMessage
}}
"
</p>
<div
v-if=
"socketMessages.length >= 1"
>
<p>
Messages from server"
</p>
<ul
id=
"messages"
>
<li
v-for=
"message in socketMessages.slice(-20)"
:key=
"message"
>
{{
message
}}
</li>
</ul>
</div>
</div>
<button
@
click=
"pingServer()"
>
Ping Server
</button>
<button
@
click=
"pingServer()"
>
Ping Server
</button>
<button
@
click=
"logOn()"
>
LogOn
</button>
<button
@
click=
"logOn()"
>
LogOn
</button>
<button
@
click=
"logOff()"
>
LogOff
</button>
<button
@
click=
"logOff()"
>
LogOff
</button>
...
@@ -16,7 +23,7 @@
...
@@ -16,7 +23,7 @@
data
()
{
data
()
{
return
{
return
{
isConnected
:
false
,
isConnected
:
false
,
socketMessage
:
null
socketMessage
s
:
[]
}
}
},
},
...
@@ -29,13 +36,11 @@
...
@@ -29,13 +36,11 @@
disconnect
()
{
disconnect
()
{
this
.
isConnected
=
false
;
this
.
isConnected
=
false
;
console
.
log
(
"logoff"
);
console
.
log
(
"logoff"
);
},
this
.
socketMessages
=
[];
customEmit
:
function
(
data
)
{
console
.
log
(
'this method was fired by the socket server. Data:'
,
data
);
},
},
// Fired when the server sends something on the "messageChannel" channel.
// Fired when the server sends something on the "messageChannel" channel.
messageChannel
(
data
)
{
messageChannel
(
data
)
{
this
.
socketMessage
=
data
;
this
.
socketMessage
s
.
push
(
data
)
;
console
.
log
(
"Message received:"
,
data
,
"!"
);
console
.
log
(
"Message received:"
,
data
,
"!"
);
}
}
},
},
...
@@ -58,7 +63,7 @@
...
@@ -58,7 +63,7 @@
},
},
logOff
()
{
logOff
()
{
this
.
$socket
.
ondisconnect
();
this
.
$socket
.
ondisconnect
();
this
.
socketMessage
=
null
;
this
.
socketMessage
=
[]
;
}
}
}
}
}
}
...
...
client/src/components/HelloWorld.vue
View file @
02b95030
<
template
>
<
template
>
<div
class=
"hello"
>
<div
class=
"hello"
>
<h1>
{{
msg
}}
</h1>
<h1>
Salut
{{
this
.
printName
()
}}
!
</h1>
</div>
</div>
</
template
>
</
template
>
...
@@ -8,7 +8,14 @@
...
@@ -8,7 +8,14 @@
export
default
{
export
default
{
name
:
"HelloWorld"
,
name
:
"HelloWorld"
,
props
:
{
props
:
{
msg
:
String
name
:
String
},
methods
:
{
printName
()
{
let
name
=
this
.
$store
.
name
;
console
.
log
(
"Saying hello to "
,
name
);
return
name
}
}
}
};
};
</
script
>
</
script
>
...
...
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