1
1
import { Socket , Presence } from 'phoenix'
2
- import updateUsers from './users'
3
-
4
2
const socket = new Socket ( '/socket' , { params : { username : window . pointingParty . username } } )
5
3
socket . connect ( )
6
4
7
- const channel = socket . channel ( 'room:lobby' , { } )
8
- const presence = new Presence ( channel )
9
-
10
- presence . onSync ( ( ) => updateUsers ( presence ) )
11
-
12
- let driving = false
13
-
14
- if ( window . pointingParty . username ) {
15
- channel . join ( )
16
- . receive ( 'ok' , resp => { console . log ( 'Joined successfully' , resp ) } )
17
- . receive ( 'error' , resp => { console . log ( 'Unable to join' , resp ) } )
18
- }
5
+ let driving = false ;
19
6
20
7
const startButton = document . querySelector ( '.start-button' )
21
8
startButton . addEventListener ( 'click' , e => {
22
9
driving = true ;
23
- channel . push ( 'start_pointing' , { } )
10
+ // send 'start_pointing' message to the channel here
24
11
} )
25
12
26
13
const nextCardButtons = document . getElementsByClassName ( 'next-card' )
27
14
for ( let i = 0 ; i < nextCardButtons . length ; i ++ ) {
28
15
nextCardButtons [ i ] . addEventListener ( 'click' , e => {
29
- channel . push ( 'finalized_points' , { points : e . target . value } )
16
+ // send 'finalized_points' message to the channel here
30
17
} )
31
18
}
32
19
33
20
document
34
21
. querySelector ( '.calculate-points' )
35
22
. addEventListener ( 'click' , event => {
36
23
const storyPoints = document . querySelector ( '.story-points' )
37
- channel . push ( 'user_estimated' , { points : storyPoints . value } )
24
+ // send 'user_estimated' to the channel here
38
25
} )
39
26
40
- channel . on ( 'new_card' , state => {
27
+ // call the relevant function defined below when you receive the following events from the channel:
28
+ // 'next_card'
29
+ // 'winner'
30
+ // 'tie'
31
+
32
+ function showCard ( state ) {
41
33
document
42
34
. querySelector ( '.start-button' )
43
35
. style . display = "none"
@@ -59,20 +51,9 @@ channel.on('new_card', state => {
59
51
document
60
52
. querySelector ( '.ticket-description' )
61
53
. innerHTML = state . card . description
62
- } )
63
-
64
- const renderVotingResults = function ( template ) {
65
- const pointContainer = document . querySelector ( '.points-container' )
66
- renderTemplate ( pointContainer , template )
67
-
68
- document
69
- . querySelector ( '.next-card' )
70
- . addEventListener ( 'click' , e => {
71
- channel . push ( 'finalized_points' , { points : e . target . value } )
72
- } )
73
54
}
74
55
75
- channel . on ( 'winner' , state => {
56
+ function showWinner ( state ) {
76
57
document
77
58
. querySelector ( '.winner' )
78
59
. style . display = "block"
@@ -88,9 +69,9 @@ channel.on('winner', state => {
88
69
document
89
70
. querySelector ( '.next-card' )
90
71
. disabled = ! driving
91
- } )
72
+ }
92
73
93
- channel . on ( 'tie' , state => {
74
+ function showTie ( state ) {
94
75
document
95
76
. querySelector ( '.tie' )
96
77
. style . display = "block"
@@ -121,6 +102,6 @@ channel.on('tie', state => {
121
102
. querySelector ( '.tie' )
122
103
. getElementsByClassName ( 'next-card' ) [ 1 ]
123
104
. disabled = ! driving
124
- } )
105
+ }
125
106
126
107
export default socket
0 commit comments