Skip to content

Instantly share code, notes, and snippets.

@isuvorov
Created September 30, 2016 10:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isuvorov/03b91fae3a733bbd87edcf042b4137d1 to your computer and use it in GitHub Desktop.
Save isuvorov/03b91fae3a733bbd87edcf042b4137d1 to your computer and use it in GitHub Desktop.
const SocketManager = {
// unmapper: {
// socket: ['Post_1', 'Post_2']
// },
mapper: {
'Post_1': [ {socket, events:[]}, socket2, socket3 ],
'Post_2': [],
},
subscribe: (model, socket) => {
// socket.on('disconnect', () => {} )
}
}
// post = SocketManager.extend('mongoose', post)
//
const post = {}
post.method.emit = (...params) => {
SocketManager.emit(SocketManager.getMongooseId(this), ...params)
}
post.method.subscribe = (...params) => {
SocketManager.subscribe(SocketManager.getMongooseId(this), ...params)
}
// при удалении компонента, будет удалена переменная сокета, проверить что произошел дисконнект
ctx.io.of('/api/v1/post/1').on('connection', (socket) => {
// socket.TOKEN !!!!!
//
// SocketManager.subscribe(post, socket)
post.subscribe(socket, ['create', 'addCommenct', '*'])
SocketManager.subscribe(SocketManager.getMongooseId(post), socket)
})
api.post('/post/1/comment', async () => {
const post = {}
const comment = {}
await post.save()
// SocketManager.emit(SocketManager.getMongooseId(post), 'addComment', {comment, post})
post.emit('addComment', {comment, post})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment