Skip to content

Instantly share code, notes, and snippets.

@brunocarvalhodearaujo
Created July 26, 2017 17:58
Show Gist options
  • Save brunocarvalhodearaujo/c612b91a07681deba33dbc751c8b4871 to your computer and use it in GitHub Desktop.
Save brunocarvalhodearaujo/c612b91a07681deba33dbc751c8b4871 to your computer and use it in GitHub Desktop.
import socket from 'socket.io'
/**
* @type {socket}
*/
const io = socket()
/**
* @param {number} code dsadsad as
* @param {socket} socket - dsads dsad as
*/
function connection (code, socket) {
}
/**
* @typedef {{ [id: string]: socket }} client
* @type {client} client -dsadslapdlsa
*/
const clients = {}
io.sockets.on('connection', client => {
client.on('join', name => {})
clients[ client.id ] = client
client.emit('update', 'you have connected to the server')
client.broadcast.emit('update', `${client.id} has joined the server`)
client.on('send', message => {
client.broadcast.emit('chat', clients[client.id], message)
})
})
export default io
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment