var http = require('http');
var sio = require('socket.io');
var fs = require('fs');
var querystring = require('querystring');
var comModel = require('./model/CommentModel.js');
var LiveModel = require('./model/LiveModel.js');
var server = http.createServer(function(req ,res){
res.writeHead(200,{'content-type':'text/html'});
res.end('');
});
server.listen(8089);
var io = sio.listen(server);
//端口号是否被占用
io.on('error',function(e){
if(e.code == 'EADDRINUSE'){
console.log('端口号被占用');
}
});
var connectionList = {};
io.sockets.on('connection', function (socket) {
//客户端连接时,保存socketId和用户名
var socketId = socket.id;
console.log(socketId);
connectionList[socketId] = {
socket: socket
};
//用户进入聊天室事件,向其他在线用户广播其用户名
socket.on('join', function (data) {
console.log(data);
socket.join(data.productId);
console.log(data.nickname+"进入聊天室"+data.productId);
connectionList[socketId].username = data.nickname;
connectionList[socketId].userno = data.userno;
connectionList[socketId].productID = data.productId;
//socket.broadcast.emit('thisroom', data);
// io.sockets.in(data.productId).emit('initroom',socketId);
}
}