Peerjs Не удалось установить локальное предложение sdp - PullRequest
0 голосов
/ 12 ноября 2018

Хорошо .... поэтому я последовал руководству и создал сайт, на котором вы можете кодировать и делиться своим редактором кодовых зеркал и видеозвонком с другим пользователем. Я использую peer js и загрузил проект на heroku для тестирования.

Сайт работает, но есть проблемы: Когда я звоню другому пользователю, его видео видно в моем браузере, но он не может видеть мое видео, только свое собственное видео. Я получаю следующую ошибку в консоли:

PeerJS:  Failed to setLocalDescription,  (OperationError) Failed to set local offer sdp: Called in wrong state: kHaveRemoteOffer

Я использую версию peerjs 0.3.8, так как последние версии только что разорвали соединения. Ниже приведен код для моего однорангового сервера:

const express = require('express');
const path = require('path');
const http = require('http');
const cors = require('cors');
const errorhandler = require('errorhandler');
var ExpressPeerServer = require('peer').ExpressPeerServer;

var options = {
  debug: true
};

var app = express();
var server = http.createServer(app);

var port = process.env.PORT || '3000';

app.set('port', port);
app.use(cors());
app.use(express.static(path.join(__dirname, 'public')));
app.use('/peerjs', ExpressPeerServer(server, options));
app.use(errorhandler());

process.on('uncaughtException', function(exc) {
  console.error(exc);
});

server.listen(port);

Я использую следующий скрипт в файле task.hbs для создания соединения:

  // PeerJS
  // Compatibility shim
  navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
  // PeerJS object
  var peer = new Peer(username + roomId, {
    host: 'stark-waters-87626.herokuapp.com',
    path: '/peerjs',
    port: 443,
    secure: true,
    debug: true
  });

  peer.on('open', function () {
    $('#my-id').text(peer.id);
  });

  // Receiving a call
  peer.on('call', function (call) {
    // Answer the call automatically (instead of prompting user) for demo purposes
    call.answer(window.localStream);
    step3(call);
  });

  peer.on('error', function (err) {
    alert(err.message);
    // Return to step 2 if error occurs
    step2();
  });

  // Click handlers setup
  $(function () {
    $('#make-call').click(function () {
      // Initiate a call!
      var call = peer.call($('#callto-id').val(), window.localStream);
      step3(call);
    });
    $('#end-call').click(function () {
      window.existingCall.close();
      step2();
    });
    step1();
  });
  function step1() {
    // Get audio/video stream
    navigator.getUserMedia({ audio: true, video: true }, function (stream) {
      // Set your video displays
      $('#my-video').prop('src', URL.createObjectURL(stream));
      window.localStream = stream;
      step2();
    }, function () { $('#step1-error').show(); });
  }

  function step2() {
    $('#step1, #step3').hide();
    $('#step2').show();
  }

  function step3(call) {
    // Hang up on an existing call if present
    if (window.existingCall) {
      window.existingCall.close();
    }
    // Wait for stream on the call, then set peer video display
    call.on('stream', function (stream) {
      $('#second-video').prop('src', URL.createObjectURL(stream));
    });
    // UI stuff
    window.existingCall = call;
    $('#second-id').text(call.peer);
    call.on('close', step2);
    $('#step1, #step2').hide();
    $('#step3').show();
  }

Вот скриншоты того, как это выглядит в моем окне, где я могу видеть удаленного пользователя:

enter image description here

В другом окне браузера, которое я открыл, видео удаленного пользователя не появляется:

enter image description here

...