webRTC(六),⾯试⾼频题⽬logger.debug(‘the number of user in room is:’+users)
//处理⼀对⼀通信
if (users<USERCOUNT) {
//给本⼈回信息
if(users>1){
<(room).emit(‘otherjoin’,room,socket.id);
}
}else{
socket.leave(room);
}
//给本⼈回信息
//it(‘joined’,room,socket.id);
//给房间除⾃⼰以外所有⼈回
// (room).emit(‘joined’,room,socket.id);
//给房间所有⼈回
// io.in(room).emit(‘joined’,room,socket.id);
//除⾃⼰所有站点回
// it(‘joined’,room,socket.id)
});
//⽤户离开
<(‘leave’,(room)=>{
var myRoom = io.s[room];
var users =(myRoom)?Object.keys(myRoom.sockets).length:0;
//users-1
logger.debug(‘the number of user in room is:’+(users-1));
<(room).emit(‘bye’,room,socket.id);
//给本⼈回信息
//it(‘leaved’,room,socket.id);
//给房间除⾃⼰以外所有⼈回
//(room).emit(‘leaved’,room,socket.id) //给房间所有⼈回
/
/io.in(room).emit(‘leaved’,room,socket.id);
//除⾃⼰所有站点回
//it(‘leaved’,room,socket.id) });
});
服务器全部代码
‘use strict’
var http = require(‘http’);
var https = require(‘https’);
var fs = require(‘fs’);
var express= require(‘express’);
var serveIndex=require(‘serve-index’);
var USERCOUNT=3;
//命令服务器
var socketIo =require(‘socket.io’);
var log4js = require(‘log4js’);
appenders:{
file:{
type:‘file’,
filename:‘app.log’,
layout:{
type:‘pattern’,
pattern:’%r %p - %m’,
}
}
},
categories:{
default:{
appenders:[‘file’],
level:‘debug’
}
}
});
var logger = Logger();
var app=express();
app.use(serveIndex(’./public’));
app.use(express.static(’./public’));
//http server
var http_ateServer(app);
//-----------------------------------------------------------------------//
var options={
adFileSync(’./cert/3435783_huangxiaoguo.club.key’),
adFileSync(’./cert/3435783_huangxiaoguo.club.pem’)
}
/
/https server
var https_ateServer(options,app);
//命令服务器绑定https
var io = socketIo.listen(https_server);
(‘connection’,(socket)=>{
logger.debug(“connection”);
//转发信息
<(‘message’, (room, data)=>{
logger.debug("message data “+socket.id+” "+room,data);
<(room).emit(‘message’, room, socket.id, data)//房间内所有⼈,除⾃⼰外});
//⽤户加⼊
应届生web前端面试题<(‘join’,(room)=>{
logger.debug(“join”,",room = “, room,”,socket.id = ", socket.id);
socket.join(room);
var myRoom = io.s[room];
var users =(myRoom)?Object.keys(myRoom.sockets).length:0;
logger.debug(‘the number of user in room is:’+users)
//处理⼀对⼀通信
if (users<USERCOUNT) {
//给本⼈回信息
if(users>1){
<(room).emit(‘otherjoin’,room,socket.id);
}
}else{
socket.leave(room);
}
//给本⼈回信息
//it(‘joined’,room,socket.id);
//给房间除⾃⼰以外所有⼈回
// (room).emit(‘joined’,room,socket.id);
//给房间所有⼈回
/
/ io.in(room).emit(‘joined’,room,socket.id);
//除⾃⼰所有站点回
// it(‘joined’,room,socket.id)
});
//⽤户离开
<(‘leave’,(room)=>{
var myRoom = io.s[room];
var users =(myRoom)?Object.keys(myRoom.sockets).length:0; //users-1
logger.debug(‘the number of user in room is:’+(users-1)); (room).emit(‘bye’,room,socket.id);
//给本⼈回信息
/
/it(‘leaved’,room,socket.id);
//给房间除⾃⼰以外所有⼈回
//(room).emit(‘leaved’,room,socket.id)
//给房间所有⼈回
//io.in(room).emit(‘leaved’,room,socket.id);
//除⾃⼰所有站点回
//it(‘leaved’,room,socket.id)
});
});
https_server.listen(443, ‘0.0.0.0’);
http_server.listen(80,‘0.0.0.0’);
利⽤socketio实现简单聊天室
页⾯
Chat Room
UserName:
尾声
以薪资待遇为基础,以发展为最终⽬标,要在⾼薪资的地⽅,谋求最好的发展!
下⾯是有⼏位Android⾏业⼤佬对应上⽅技术点整理的⼀些进阶资料。有**。希望能够帮助到⼤家提升技术。如果⼤家想要获取的话,可以私信我【666】免费获取哦**
以薪资待遇为基础,以发展为最终⽬标,要在⾼薪资的地⽅,谋求最好的发展!
下⾯是有⼏位Android⾏业⼤佬对应上⽅技术点整理的⼀些进阶资料。有**。希望能够帮助到⼤家提升技术。如果⼤家想要获取的话,可以私信我【666】免费获取哦**
[外链图⽚转存中…(img-vyKoKqP1-1644921132745)]
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论