-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsocket.js
More file actions
30 lines (29 loc) · 777 Bytes
/
socket.js
File metadata and controls
30 lines (29 loc) · 777 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// import {
// readFile,
// writeFile
// } from './fs-async.js';
var fss = require('./fs-async.js')
const filePath = `${__dirname}/user.json`
// socket具体业务逻辑
exports.socketHander= {
/**
* [saveUserSocketId 保存用户的id和socketid]
* @param {[type]} userId [用户id]
* @param {[type]} socketId [用户的socketid//目前暂时为昵称]
* @return {[type]} [description]
*/
async saveUserSocketId(userId, socketId) {
let data = await fss.readFile(filePath).catch((err) => {
console.log(err)
})
data[userId] = socketId
fss.writeFile(filePath, data)
},
async readUserSocketId() {
let data = await fss.readFile(filePath).then(data=>{
return data;
}).catch((err) => {
console.log(err)
});
}
}