WebRTC не видно удаленую сторону [помощь]
#39030022
Ссылка:
Ссылка на сообщение:
Ссылка с названием темы:
Ссылка на профиль пользователя:
|
Участник
Откуда: от верблюда
Сообщения: 142
|
|
Здравствуйте
Помогите пожалуйста понять как это должно заработать, не имею опыта в этом.
Я сделал все как описано в пошаговой инструкции :
1) установил the node.js на debian 8:
1. 2. 3. 4.
apt-get install curl
curl --silent --location https://deb.nodesource.com/setup_0.12 | bash -
apt-get install --yes nodejs
apt-get install --yes build-essential
2) Установил следящие в папке предложение:
1. 2.
npm install socket.io
npm install node-static
3) Запустил сервер
Но проблема в том что не видно удалённое видео. Может я что то не доделал? http://wdd.co.il:1234
Сервер server.js:
1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. 43. 44. 45. 46. 47. 48.
var static = require('node-static');
var http = require('http');
var file = new(static.Server)();
var app = http.createServer(function (req, res) {
file.serve(req, res);
}).listen(1234);
var io = require('socket.io').listen(app);
io.sockets.on('connection', function (socket) {
function log() {
var array = [">>> "];
for(var i = 0; i < arguments.length; i++) {
array.push(arguments[i]);
}
socket.emit('log', array);
}
socket.on('message', function (message) {
log('Got message: ', message);
socket.broadcast.emit('message', message); // should be room only
});
socket.on('create or join', function (room) {
var numClients = io.sockets.clients(room).length;
log('Room ' + room + ' has ' + numClients + ' client(s)');
log('Request to create or join room', room);
if(numClients == 0) {
socket.join(room);
socket.emit('created', room);
}
else if(numClients == 1) {
io.sockets.in(room).emit('join', room);
socket.join(room);
socket.emit('joined', room);
}
else { // max two clients
socket.emit('full', room);
}
socket.emit('emit(): client ' + socket.id + ' joined room ' + room);
socket.broadcast.emit('broadcast(): client ' + socket.id + ' joined room ' + room);
});
});
Клиент index.html:
1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. 43. 44. 45. 46. 47. 48. 49. 50. 51. 52. 53. 54. 55. 56. 57. 58. 59. 60. 61. 62. 63. 64. 65. 66. 67. 68. 69. 70. 71. 72. 73. 74. 75. 76. 77. 78. 79. 80. 81. 82. 83. 84. 85. 86. 87. 88. 89. 90. 91. 92. 93. 94. 95. 96. 97. 98. 99. 100. 101. 102. 103. 104. 105. 106. 107. 108. 109. 110. 111.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style type="text/css">
html { height: 100%; }
body { height: 100%; margin: 0; background: #111; text-align: center; }
#remoteVideo { height: 70%; margin-top: 5%; background: #000; }
#localVideo { width: 20%; position: absolute; right: 1.1em; bottom: 1em; border: 1px solid #333; background: #000; }
#callButton { position: absolute; display: none; left: 50%; font-size: 2em; bottom: 5%; border-radius: 1em; }
</style>
</head>
<script src="/socket.io/socket.io.js"></script>
<video id="localVideo" autoplay muted></video>
<video id="remoteVideo" autoplay></video>
<button id="callButton" onclick="createOffer()">✆</button>
<script>
var PeerConnection = window.mozRTCPeerConnection || window.webkitRTCPeerConnection;
var IceCandidate = window.mozRTCIceCandidate || window.RTCIceCandidate;
var SessionDescription = window.mozRTCSessionDescription || window.RTCSessionDescription;
navigator.getUserMedia = navigator.getUserMedia || navigator.mozGetUserMedia || navigator.webkitGetUserMedia;
var pc; // PeerConnection
// Step 1. getUserMedia
navigator.getUserMedia(
{ audio: true, video: true },
gotStream,
function(error) { console.log(error) }
);
function gotStream(stream) {
document.getElementById("callButton").style.display = 'inline-block';
document.getElementById("localVideo").src = URL.createObjectURL(stream);
pc = new PeerConnection(null);
pc.addStream(stream);
pc.onicecandidate = gotIceCandidate;
pc.onaddstream = gotRemoteStream;
}
// Step 2. createOffer
function createOffer() {
pc.createOffer(
gotLocalDescription,
function(error) { console.log(error) },
{ 'mandatory': { 'OfferToReceiveAudio': true, 'OfferToReceiveVideo': true } }
);
}
// Step 3. createAnswer
function createAnswer() {
pc.createAnswer(
gotLocalDescription,
function(error) { console.log(error) },
{ 'mandatory': { 'OfferToReceiveAudio': true, 'OfferToReceiveVideo': true } }
);
}
function gotLocalDescription(description){
pc.setLocalDescription(description);
sendMessage(description);
}
function gotIceCandidate(event){
if (event.candidate) {
sendMessage({
type: 'candidate',
label: event.candidate.sdpMLineIndex,
id: event.candidate.sdpMid,
candidate: event.candidate.candidate
});
}
}
function gotRemoteStream(event){
document.getElementById("remoteVideo").src = URL.createObjectURL(event.stream);
}
////////////////////////////////////////////////
// Socket.io
var socket = io.connect('http://wdd.co.il', {port: 1234});
function sendMessage(message){
socket.emit('message', message);
}
socket.on('message', function (message){
if (message.type === 'offer') {
pc.setRemoteDescription(new SessionDescription(message));
createAnswer();
}
else if (message.type === 'answer') {
pc.setRemoteDescription(new SessionDescription(message));
}
else if (message.type === 'candidate') {
var candidate = new IceCandidate({sdpMLineIndex: message.label, candidate: message.candidate});
pc.addIceCandidate(candidate);
}
});
</script>
</html>
|
|