@@ -110,7 +110,7 @@ playerJoined Server All other clients {id, login, avatar_url} Update other
110110gameState Server One client See game state model! Initialize game state for new player that just logged in,
111111 and trigger new gist creation if game is just starting!
112112playerLeft Server All other clients id Update other clients to remove disconnected player
113- turnChange Server All clients null ??? Trigger clients to change the turn
113+ turnChange Server All clients onDisconnect (Boolean) Trigger clients to change the turn
114114newGist Client Server {id, url, owner} Broadcast new Gist data
115115editorTextChange Client Server "just a string!" Broadcast changes to code editor content
116116editorScrollChange Client Server {scrollLeft, scrollTop} Broadcast changes to code editor content
@@ -192,8 +192,8 @@ io.on('connection', function (socket) {
192192 // Restart the timer
193193 timerId = startTurnTimer ( timerId , turnDuration ) ;
194194
195- // Change the turn, including ID of disconnected player to send to clients
196- changeTurn ( socket . id ) ;
195+ // Change the turn, including the onDisconnect=true flag to signal clients NOT to fork/edit the Gist on this turn change
196+ changeTurn ( true ) ;
197197 }
198198
199199 } else {
@@ -261,11 +261,11 @@ io.on('connection', function (socket) {
261261/* -------------------------------------------------
262262 FUNCTIONS
263263---------------------------------------------------- */
264- function changeTurn ( disconnectedPlayerId ) {
264+ function changeTurn ( onDisconnect ) {
265265 gameState . turnIndex = ( gameState . turnIndex + 1 ) % gameState . players . length ;
266266
267267 // Broadcast turnChange to ALL clients, with disconnected player ID (which exists only if current player disconnected):
268- io . emit ( 'turnChange' , disconnectedPlayerId ) ;
268+ io . emit ( 'turnChange' , onDisconnect ) ;
269269}
270270
271271// Initializes the turn and turn timer, returns timerId
0 commit comments