diff --git a/packages/server/packages/play-node-go/play-node-go/src/pages/Home/Home.js b/packages/server/packages/play-node-go/play-node-go/src/pages/Home/Home.js
index 8d6dc14..d7d85d8 100644
--- a/packages/server/packages/play-node-go/play-node-go/src/pages/Home/Home.js
+++ b/packages/server/packages/play-node-go/play-node-go/src/pages/Home/Home.js
@@ -2,11 +2,18 @@ import React, { useEffect } from 'react';
import './Home.scss';
import roomsServices from '../../services/api/roomsServices';
import RoomButton from '../../components/Button/Room/Room';
+import socketIOClient from 'socket.io-client';
+import config from '../../config';
+
+// ! [start] roomSocket stub
+const roomId = 1
+const roomSocket = socketIOClient(`${config.socketAddress}/${roomId}`)
+// ! [end]
const Home = props => {
- const state = props.state;
+ const state = props.state || {};
const dispatch = props.dispatch;
-
+
const renderRooms = () => {
const rooms = state.rooms || [];
if (rooms.length) {
@@ -31,11 +38,24 @@ const Home = props => {
return dispatch(action)
}
}
-
+
useEffect(() => {
fetchRoomsAPI();
}, [])
+ // ! [start] roomSocket stub
+ const roomSocketConnect = () => {
+ roomSocket.emit('connect');
+ // roomSocket.on('connected', data => setSocketData('room socket connected'));
+ // roomSocket.on('connect_error', err => setError([...error, err]));
+ // roomSocket.on('error', err => setError([...error, err]))
+ }
+
+ useEffect(() => {
+ roomSocketConnect();
+ }, [])
+ // ! [end]
+
return (
diff --git a/packages/server/packages/play-node-go/server/bin/www b/packages/server/packages/play-node-go/server/bin/www
index 581db1e..8a453ea 100755
--- a/packages/server/packages/play-node-go/server/bin/www
+++ b/packages/server/packages/play-node-go/server/bin/www
@@ -89,6 +89,5 @@ function onListening() {
debug('Listening on ' + bind);
}
-const socketIO = require('socket.io')
-const enableSocket = require('../socket').enableSocket;
-const io = enableSocket(socketIO(server, { cookie: false }));
+const socket = require('../socket');
+socket.io.attach(server);
\ No newline at end of file
diff --git a/packages/server/packages/play-node-go/server/controllers/api/apiRoom.js b/packages/server/packages/play-node-go/server/controllers/api/apiRoom.js
index 20e7028..bc08296 100644
--- a/packages/server/packages/play-node-go/server/controllers/api/apiRoom.js
+++ b/packages/server/packages/play-node-go/server/controllers/api/apiRoom.js
@@ -1,9 +1,11 @@
const roomQueries = require('../../data/queries/room');
+const {enableRoomSocket} = require('../../socket');
const roomIndex = async (req, res, next) => {
try {
// TODO eventually add check for user's private rooms
const publicRooms = await roomQueries.findPublicRooms();
+ enableRoomSocket(1)
res.status(200).json({rooms: publicRooms})
}
diff --git a/packages/server/packages/play-node-go/server/socket.js b/packages/server/packages/play-node-go/server/socket.js
index 4708e7d..d709ebc 100644
--- a/packages/server/packages/play-node-go/server/socket.js
+++ b/packages/server/packages/play-node-go/server/socket.js
@@ -1,13 +1,20 @@
// TODO const someSocketLogic = require('./middleware/socketssockets/...');
+const socketIO = require('socket.io');
+const io = socketIO({ cookie: false });
+
+io.on('connection', ()=> {
+ io.emit('connected', {message: 'socket connected'});
+})
+
+enableRoomSocket = (roomId) => {
+ const roomSocket = io.of(roomId);
+ roomSocket.on('connection', () => {
+ console.log(`Socket connected at room ${roomId}`);
+ });
+ return roomSocket;
+}
module.exports = {
- enableSocket: io => {
- io.on('connection', ()=> {
- io.emit('connected', {message: 'socket connected'});
- })
-
- // TODO io = someSocketLogic(io);
-
- return io;
- }
+ io,
+ enableRoomSocket
}
\ No newline at end of file