1 Star 0 Fork 0

mouse/webrtc-server

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
index.js 1.71 KB
一键复制 编辑 原始数据 按行查看 历史
hewx 提交于 2021-11-18 18:13 . websocket
'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);
});
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/dmouse6/webrtc-server.git
git@gitee.com:dmouse6/webrtc-server.git
dmouse6
webrtc-server
webrtc-server
master

搜索帮助