简体   繁体   中英

Node.js EasyRTC Errors Related to Setup

I'm busy working through some EasyRTC documentation in order to come to terms with how it works. I'm having some trouble though calling the EasyRTC functions (easyApp, joinRoom etc). I'm certain it has something to do with the way I've set it up but not sure why.

I have my node.js server file set up as follows (index.js)

////
// setup main
var express = require("express");
var http = require("http");
var socketio = require("socket.io");
var easyrtc = require("easyrtc");
var app = express();
var rootdir = "/opt/dev/nodejs/easyrtc/v100";

////
// middleware
app.use("/public", express.static(rootdir + "/public"));
app.set("view engine", "ejs");
app.set("views", rootdir + "/public/views");

////
// web server and socket server
var httpserver = http.createServer(app);
httpserver.listen(3000, function() { console.log("Server Started : Port 3000"); });
var socketioserver = socketio.listen(httpserver, {"log level":1});

////
// easyrtc server (extract from easyrtc example file)
easyrtc.setOption("logLevel", "debug");
var easyrtcserver = easyrtc.listen(app, socketioserver, null, function(err, rtcRef) {

   rtcRef.events.on ("roomCreate", function(appObj, creatorConnectionObj, roomName, roomOptions, callback) {
      appObj.events.defaultListeners.roomCreate (
         appObj, creatorConnectionObj, roomName, roomOptions, callback
      );
   });

});

////
// routes
var main_route = require("./public/logic/main/main_route.js");
app.use(main_route.router(express, easyrtc));

This seems to be working ok because I can see the server's output messages to the console.

info    - EasyRTC: Starting EasyRTC Server (v1.1.0) on Node (v8.7.0)
debug   - EasyRTC: Emitting event 'startup'
debug   - EasyRTC: Running func 'onStartup'
Server Started : Port 3000
debug   - EasyRTC: Configuring Http server
debug   - EasyRTC: Setting up demos to be accessed from '/demos/'
debug   - EasyRTC: Setting up API files to be accessed from '/easyrtc/'
debug   - EasyRTC: Configuring Socket server
debug   - EasyRTC: Creating application: 'default'
debug   - EasyRTC: [default] Room [default] Running func 'onRoomCreate'
debug   - EasyRTC: Creating room: 'default' with options: {}
info    - EasyRTC: EasyRTC Server Ready For Connections (v1.1.0)

So I'm happy with that but the problem comes when I try to interact with the server with my main page (main_route.js)

exports.router = function(express, easyrtc) {

   var router = express.Router();
   router.get("/", function(req, res) { f_main(res, easyrtc); });
   return router;

}

function f_main(res, easyrtc) {

   ////
   // render the gui
   res.render("main/main.ejs");

   ////
   // execute something to test although this fails
   easyrtc.joinRoom("Nothing", null, function() {}, function() {});

}

The function is being passed the easyrtc object created by the server and if I echo it I can see that it is a valid object but if I call joinRoom or anything of the other functions I am getting the following error

TypeError: easyrtc.joinRoom is not a function

I don't know why this is though, I'm certain I'm doing something very silly

You can invoke the function joinRoom on the application object.

var easyrtcServer = easyrtc.listen(app, socketServer, null,
    function(err, rtc) {
        if (err) console.log(err);
        rtc.createApp(
            "rtcApp", null, rtcAppCallback
        );
});

var rtcAppCallback = function(err, appObj) {
    if (err) console.log(err);
    app.use('/', router(appObj));
};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM