Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
558 views
in Technique[技术] by (71.8m points)

EasyRTC command questions

I am attempting WebRTC using the EasyRTC API. I find the documentation of EasyRTC a bit confusing and fragmented. Basically I wish to perform some actions upon receipt of certain HTTP request(s). I want to create a new 'room' (if it doesn't already exist) and/or check the room occupants if a 'room' does already exist, and limit the number of occupants to only two people.

I am aware of the 'roomJoin' command, however I am having difficulty figuring how to check if a room already exists, creating a new room, and checking number of room occupants.

My code is similar to the following:

// Load required modules
var https   = require("https");     // https server core module
var fs      = require("fs");        // file system core module

//****

const PORTX = process.env.PORT || 8443;

//****Use Express module

var express = require("express");   // web framework external module
var app = express();
var io = require("socket.io"); // web socket external module
var easyrtc = require("easyrtc");   // EasyRTC external module

//****GLOBAL VARIABLES

var easy_options = {
  logLevel: "debug",
  appDefaultName: "WebRTC_App",
  demosEnable: false,
  logDateEnable: true, 
  appAutoCreateEnable: false,
  roomAutoCreateEnable: false, 
  roomDefaultEnable: false
};

//*****SERVER CODE

//Temporary home page
app.get('/', function (req, res) {

  res.render('pages/_splash');

});

//****HTTP REQUESTS/CALLS FROM CLIENT(S)...

app.post('/p2p/calls/:name/token/:passkey', jsonParser, function (req, res) {

//'unknown' commands needed here...
//check if a 'room' exists, if not create it...
//if a room does exist, check number of occupants
//limit room occupants to two people

})

//****

//Start Express https server on port 8443
var webServer = https.createServer(
 {
 key:  fs.readFileSync("/pathtokeys/domain.key"),
 cert: fs.readFileSync("/pathtokeys/domain.crt")
 }, app).listen(PORTX);

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

//****STARTUP EASYRTC SERVER UPON SERVER INITIALIZATION/RESTARTS...

// Start EasyRTC server
easyrtc.listen(app, socketServer, easy_options, function(err, pub) {

 if (err) {
  return callback(err);
 }

console.log("EasyRTC Server is listening");

 easyrtc.events.on('connection', function(socket, easyrtcid, next) {
  console.log('------>>>>> Connection from easyrtcid', easyrtcid);

 });

 easyrtc.events.on('disconnect', function(connectionObj, next) {
  console.log('------>>>>> Disconnect from ', connectionObj.getEasyrtcid());

 });

 easyrtc.events.on('roomJoin', function(connectionObj, roomName, roomParameter, callback) {
  console.log('------>>>>> ROOM JOIN for ', connectionObj.getEasyrtcid());
  console.log('------>>>>> ROOM JOINED is: ', roomName);

 });

 easyrtc.events.on('roomLeave', function(connectionObj, roomName, next) {
  console.log('------>>>>> ROOM LEAVE for ', connectionObj.getEasyrtcid());
  console.log('------>>>>> ROOM LEFT is: ', roomName);

 });


});

If anybody has previous experience with EasyRTC and has some advice I would greatly appreciate it. I thank you in advance. Regards.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...