我已经建立了他们对peerjs的示例,在我的Chrome电脑上运行良好,但是我的iPad Pro与safari v12一起使用,只是给我本地流而没有将答案发送给发件人对等
这是我的发件人客户
const peer = new Peer('sender', { host: '100.0.0.98', port: 9000, path: '/',debug: 3 })
var call = document.getElementById('call');
call.addEventListener('click', startChat);
function startChat (){
navigator.mediaDevices.getUserMedia({
video: true
}).then(function(localStream) {
document.getElementById('local').srcObject = localStream;
const call = peer.call('receiver', localStream);
call.on('stream', function(remoteStream) {
document.getElementById('remote').srcObject = remoteStream;
});
});
}
这是我的接收者
const peer = new Peer('receiver', { host: '100.0.0.98', port: 9000, path: '/', debug: 3 })
// var debugElement = domcument.getElementById('debug');
peer.on('call', function (call) {
var conf = confirm('Some one is calling you...')
if (conf) {
navigator.mediaDevices.getUserMedia({
video: true
}).then(function (localStream) {
document.getElementById('local').srcObject = localStream;
call.answer(localStream);
call.on('stream', function (remoteStream) {
document.getElementById('remote').srcObject = remoteStream;
});
}).catch(function (error) { console.log(error); });
}
});
peer.on('error', function (err) {
var node = document.createElement("LI"); // Create a <li> node
var textnode = document.createTextNode(err); // Create a text node
node.appendChild(textnode); // Append the text to <li>
document.getElementById("debug").appendChild(node); // Append <li> to <ul> with id="myList"
});
这是我的服务器
var express = require('express');
var app = express();
var ExpressPeerServer = require('peer').ExpressPeerServer;
var ip = require('ip');
var fs = require('fs');
app.use(express.static(__dirname + '/public'));
var options = {
debug: true
}
var sslOptions = {
key: fs.readFileSync('ssl/key.pem', 'utf8'),
cert: fs.readFileSync('ssl/cert.pem', 'utf8')
};
var server = require('https').createServer(sslOptions,app);
var peerserver = ExpressPeerServer(server, options);
app.use('/scripts', express.static(`${__dirname}/node_modules/`));
app.use(express.static('public'));
app.get('/sender', function (req, res, next) {
// res.render('sender.html');
// res.header("Access-Control-Allow-Origin", "*");
// res.header("Access-Control-Allow-Headers", "X-Requested-With");
res.sendFile(__dirname + '/public/sender.html');
});
app.get('/recived', function (req, res, next) {
// res.render('sender.html');
// res.header("Access-Control-Allow-Origin", "*");
// res.header("Access-Control-Allow-Headers", "X-Requested-With");
res.sendFile(__dirname + '/public/recived.html');
});
app.use('/', peerserver);
server.listen(9000,ip.address(),()=>{
console.log(`server peer on ${ip.address()}:9000`);
});
我正在使用peerjs v0.3.20可以有人帮助我,谢谢
最佳答案
Peerjs使用基于回调的已弃用的api,您可以在https://developer.mozilla.org上看到它,但对此问题https://github.com/peers/peerjs/issues/485