Created
September 30, 2016 10:28
-
-
Save isuvorov/03b91fae3a733bbd87edcf042b4137d1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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