const typing = require('../socket_routes/typing');
const conversationRooms = require('../socket_routes/conversationRooms');
module.exports = {
	init (app, server, session) {
		let io = require('socket.io')(server)
		function setIoSockets (socket) {
			let users = app.get('io-users')
		}

		app.set('io-users', {})

		//io.use((socket, next) => {
		//	session(socket.handshake, {}, next)
		//})

		io.on('connection', socket => {
			setIoSockets(socket)

			socket.on('join', room => {
				socket.join(room)
			})

			socket.on('leave', room => {
				socket.leave(room)
			})

			socket.on('accountEvent', _ => {
				socket.disconnect()
			})
			// socket.on('disconnect', () => { removeIoUser(socket); });

			socket.on('joinConversation', data => { conversationRooms.join(data, socket) });
			socket.on('leaveConversation', data => { conversationRooms.leave(data, socket) });

			socket.on('startTyping', data => { typing('startTyping', data, socket) });
			socket.on('stopTyping', data => { typing('stopTyping', data, socket) });
		})

		app.set('io', io)
	}
}
