加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
io.js 1.69 KB
一键复制 编辑 原始数据 按行查看 历史
橘子皮儿 提交于 2018-08-08 15:25 . update
//see https://github.com/facundoolano/socketio-auth
/**
*
*
// send to current request socket client
socket.emit('message', "this is a test");
// sending to all clients except sender
socket.broadcast.emit('message', "this is a test");
// sending to all clients in 'game' room(channel) except sender
socket.broadcast.to('game').emit('message', 'nice game');
// sending to all clients, include sender
io.sockets.emit('message', "this is a test");
// sending to all clients in 'game' room(channel), include sender
io.sockets.in('game').emit('message', 'cool game');
// sending to individual socketid
io.sockets.socket(socketid).emit('message', 'for your eyes only');
socket.leave(data.room);
*/
import SocketIO from 'socket.io';
import fs from 'fs-extra';
module.exports = app => {
let io = new SocketIO(app.server);
io.on('connection', async (socket) => {
console.log("on connection, socket id is ", socket.id)
socket.on('disconnect', () => {
});
socket.on('leave', (msg) => {
});
socket.on('m:msg', async(msg) => {
console.log("message is coming, the content is "+msg)
});
socket.on('m:delete_voice', async(filepath) => {
console.log("delete file commond is comming "+filepath)
if(fs.existsSync(filepath)){
setTimeout(() => {
fs.removeSync(filepath);
console.log("delete file commond is deleted: "+filepath)
}, 10000);
}
});
// socket.on('m:play_finished', async(filepath) => {
// global.is_playing = false;
// });
});
return io;
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化