File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -8,6 +8,8 @@ const App = () => {
88 console . log ( socket . id ) ;
99 } ) ;
1010
11+ socket . on ( "message" , ( data ) => console . log ( data ) ) ;
12+
1113 return < > </ > ;
1214} ;
1315
Original file line number Diff line number Diff line change @@ -10,11 +10,17 @@ const io = new Server(server, {
1010 } ,
1111} ) ;
1212
13- app . get ( '/' , ( req , res ) => {
14- res . send ( '<h1>Hello world</h1>' ) ;
15- } ) ;
13+ io . on ( 'connection' , ( socket ) => {
14+ console . log ( `Client connected: ${ socket . id } ` ) ;
15+
16+ socket . on ( 'message' , ( { from, message } ) => {
17+ socket . broadcast . emit ( 'message' , { from, message } ) ;
18+ } ) ;
1619
17- io . on ( 'connection' , ( socket ) => console . log ( 'a user is connected' ) ) ;
20+ socket . on ( 'disconnect' , ( ) => {
21+ console . log ( `Client disconnected: ${ socket . id } ` ) ;
22+ } ) ;
23+ } ) ;
1824
1925server . listen ( 3000 , ( ) => {
2026 console . log ( 'server running at http://localhost:3000' ) ;
You can’t perform that action at this time.
0 commit comments