@@ -6,8 +6,8 @@ const volleyball = require('volleyball')
66
77const express = require ( 'express' ) ;
88const app = express ( ) ;
9-
109const socketio = require ( 'socket.io' ) ;
10+ const chalk = require ( 'chalk' )
1111
1212server . on ( 'request' , app ) ;
1313
@@ -29,8 +29,8 @@ app.use(express.static(path.join(__dirname, '../public')));
2929app . use ( volleyball )
3030
3131io . on ( 'connection' , socket => {
32- console . log ( 'New client connection' ) ;
33- console . log ( socket . id ) ;
32+ console . log ( chalk . blue ( 'New client connection' ) ) ;
33+ console . log ( chalk . blue ( socket . id ) ) ;
3434
3535 // join room on create (room name is passed from client)
3636 socket . on ( 'create' , room => {
@@ -43,28 +43,13 @@ io.on('connection', socket => {
4343 // dispatch the current synths (including self)
4444 io . to ( room ) . emit ( 'populateSynths' , memory [ room ] )
4545
46- // on 'draw' add to memory and draw to others in room
47- // socket.to(room).on('draw', (...payload) => {
48- // memory[room].push(payload);
49- // io.to(room).emit('otherDrawing', ...payload)
50- // })
5146
5247 // on 'draw' add to memory and draw to others in room
5348 socket . to ( room ) . on ( 'mouseDown' , ( inEvent ) => {
54- // const event = {
55- // id: socket.id,
56- // x: inEvent.x,
57- // y: inEvent.y
58- // }
5949 io . to ( room ) . emit ( 'mouseDown' , inEvent )
6050 } )
6151
6252 socket . to ( room ) . on ( 'mouseDrag' , ( inEvent ) => {
63- // const event = {
64- // id: socket.id,
65- // x: inEvent.x,
66- // y: inEvent.y
67- // }
6853 io . to ( room ) . emit ( 'mouseDrag' , inEvent )
6954 } )
7055
@@ -75,11 +60,9 @@ io.on('connection', socket => {
7560 // log on disconnect
7661 socket . on ( 'disconnect' , ( ) => {
7762 socket . leave ( room ) ;
78- console . log ( 'before' , memory [ room ] ) ;
63+ console . log ( chalk . yellow ( `leaving: ${ socket . id } ` ) )
7964 let deleteIndex = memory [ room ] . indexOf ( socket . id )
8065 if ( deleteIndex !== - 1 ) memory [ room ] . splice ( deleteIndex )
81- console . log ( 'after' , memory [ room ] ) ;
82- console . log ( 'disconnect :()' ) ;
8366 } ) ;
8467 } )
8568 } ) ;
0 commit comments