代码拉取完成,页面将自动刷新
'use strict'
var express = require('express');
var fs = require('fs');
var url = require('url')
let options={
key: fs.readFileSync('./dev/dev.mouse6.games.key'),
cert: fs.readFileSync('./dev/dev.mouse6.games.pem')
}
var app = express();
var https = require('https').createServer(options,app);
// var io = require('socket.io')(http);
var io = require('socket.io')(https);
app.use('/css',express.static('css'));
app.use('/js',express.static('js'));
app.use('/img',express.static('img'));
app.get('/',function(request,response){
response.sendFile(__dirname +'/index.html');
});
app.get('/alice',function(request,response){
response.sendFile(__dirname+"/alice.html")
});
app.get('/bob',function(request,response){
response.sendFile(__dirname+"/bob.html")
});
io.on('connection',function(socket){
socket.on('signal',function(message){
socket.to('room').emit('signal',message);
});
socket.on('ice',function(message){
socket.to('room').emit('ice',message);
});
socket.on('create or join',function(room){
var clientsInRoom = io.sockets.adapter.rooms.get(room);
console.log(clientsInRoom)
var numClients = clientsInRoom ? clientsInRoom.size : 0;
if(numClients===0){
socket.join(room);
socket.emit('create', room, socket.id);
console.log('caller joined');
}else if(numClients===1){
socket.join(room);
socket.to('room').emit('call');
console.log('callee joined');
}
});
});
var server = https.listen(8080,'0.0.0.0',function(){
var host = server.address().address;
var port = server.address().port;
console.log('listening on:http://s%:s%',host,port);
});
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。