2

サーバーで webrtc / socket.io / nodejs を実行しています。https://domain.com:8080 にアクセスしてビデオ会議をテストすると、すべて正常に動作します。

しかし、スクリプトを自分の Web サーバー /public_html/ で実行したい

しかし、8080 サーバーに接続していない理由がわかりません。「socket.io.js GET https://domain.com/socket.io/?EIO=3&transport=polling&t=LPgZs2K 404 (見つかりません)」

私のサーバー (server.js)

// Load required modules
var https    = require("https");              // http server core module
var express = require("express");           // web framework external module
var serveStatic = require('serve-static');  // serve static files
var socketIo = require("socket.io");        // web socket external module
var easyrtc = require("../");   
const fs = require('fs');            // EasyRTC external module

const options = {
  key: fs.readFileSync('key.pem'),
  cert: fs.readFileSync('cert.pem')
};

// Set process name
process.title = "node-easyrtc";

// Setup and configure Express http server. Expect a subfolder called "static" to be the web root.
var app = express();
app.use(serveStatic('static', {'index': ['index.html']}));

// Start Express http server on port 8080
var webServer = https.createServer(options, app).listen(8080);

// Start Socket.io so it attaches itself to Express server
var socketServer = socketIo.listen(webServer, {"log level":1});

easyrtc.setOption("logLevel", "debug");

// Overriding the default easyrtcAuth listener, only so we can directly access its callback
easyrtc.events.on("easyrtcAuth", function(socket, easyrtcid, msg, socketCallback, callback) {
    easyrtc.events.defaultListeners.easyrtcAuth(socket, easyrtcid, msg, socketCallback, function(err, connectionObj){
        if (err || !msg.msgData || !msg.msgData.credential || !connectionObj) {
            callback(err, connectionObj);
            return;
        }

        connectionObj.setField("credential", msg.msgData.credential, {"isShared":false});

        console.log("["+easyrtcid+"] Credential saved!", connectionObj.getFieldValueSync("credential"));

        callback(err, connectionObj);
    });
});

// To test, lets print the credential to the console for every room join!
easyrtc.events.on("roomJoin", function(connectionObj, roomName, roomParameter, callback) {
    console.log("["+connectionObj.getEasyrtcid()+"] Credential retrieved!", connectionObj.getFieldValueSync("credential"));
    easyrtc.events.defaultListeners.roomJoin(connectionObj, roomName, roomParameter, callback);
});

// Start EasyRTC server
var rtc = easyrtc.listen(app, socketServer, null, function(err, rtcRef) {
    console.log("Initiated");

    rtcRef.events.on("roomCreate", function(appObj, creatorConnectionObj, roomName, roomOptions, callback) {
        console.log("roomCreate fired! Trying to create: " + roomName);

        appObj.events.defaultListeners.roomCreate(appObj, creatorConnectionObj, roomName, roomOptions, callback);
    });
});

//listen on port 8080
webServer.listen(8080, function () {
    console.log('listening on http://localhost:8080');
});

WEBサーバー上の私のhtmlファイル。このような構造https://domain.com/test.html

<!DOCTYPE html>
<html>
  <head>
    <title>EasyRTC Demo:EasyRTC Demo: Video+Audio HD 720</title>
    <link rel="stylesheet" type="text/css" href="/easyrtc/easyrtc.css" />
    <script src="js/socket.io.js"></script>
    <script type="text/javascript" src="js/easyrtc.js"></script>
    <script type="text/javascript" src="js/video.js"></script>
 <script>
var selfEasyrtcid = "";


function connect() {
  easyrtc.setVideoDims(1280,720);
  easyrtc.enableDebug(false);
  easyrtc.setRoomOccupantListener(convertListToButtons);
  easyrtc.easyApp("easyrtc.videoChatHd", "selfVideo", ["callerVideo"], loginSuccess, loginFailure);
}


function clearConnectList() {
  var otherClientDiv = document.getElementById("otherClients");
  while (otherClientDiv.hasChildNodes()) {
    otherClientDiv.removeChild(otherClientDiv.lastChild);
  }
}


function convertListToButtons (roomName, data, isPrimary) {
  clearConnectList();
  var otherClientDiv = document.getElementById("otherClients");
  for(var easyrtcid in data) {
    var button = document.createElement("button");
    button.onclick = function(easyrtcid) {
      return function() {
        performCall(easyrtcid);
      };
    }(easyrtcid);

    var label = document.createTextNode(easyrtc.idToName(easyrtcid));
    button.appendChild(label);
    button.className = "callbutton";
    otherClientDiv.appendChild(button);
  }
}


function performCall(otherEasyrtcid) {
  easyrtc.hangupAll();
  var acceptedCB = function(accepted, caller) {
    if( !accepted ) {
      easyrtc.showError("CALL-REJECTED", "Sorry, your call to " + easyrtc.idToName(caller) + " was rejected");
    }
  };
  var successCB = function() {};
  var failureCB = function() {};
  easyrtc.call(otherEasyrtcid, successCB, failureCB, acceptedCB);
}


function loginSuccess(easyrtcid) {
  selfEasyrtcid = easyrtcid;
  document.getElementById("iam").innerHTML = "I am " + easyrtc.cleanId(easyrtcid);
}


function loginFailure(errorCode, message) {
  easyrtc.showError(errorCode, message);
}


// Sets calls so they are automatically accepted (this is default behaviour)
easyrtc.setAcceptChecker(function(caller, cb) {
  cb(true);
} );
 </script>
  </head>

  <body  onload="connect();">
        <h1>EasyRTC Demo: Video+Audio HD 720p</h1>
        <div id="demoContainer">
          <div>
          Note: your own image will show up postage stamp sized, while the other party"s video will be shown in high-definition (1280x720). Note: not all webcams are seen by WebRTC as providing high-definition video; the fallback is to use standard definition (640x480).
          </div>
           <div id="connectControls">
            <div id="iam">Not yet connected...</div>
            <br />
            <strong>Connected users:</strong>
            <div id="otherClients"></div>
          </div>
          <div id="videos">

            <div style="position:relative;float:left;" width="1282" height="722">
              <video autoplay="autoplay" id="callerVideo"></video>
              <video  class="easyrtcMirror" autoplay="autoplay" id="selfVideo" muted="true" volume="0" ></video>
            </div>
            <!-- each caller video needs to be in it"s own div so it"s close button can be positioned correctly -->
          </div>
        </div>
  </body>
</html>

Socket.io.js: http://81.171.38.245/js/socket.io.js

4

0 に答える 0