无法使用 EasyRTC 连接到 Xirsys STUN 和 TURN 服务器
Unable to Connect to Xirsys STUN and TURN servers using EasyRTC
我正在使用 EasyRTC 和 Xirsys 开发视频聊天应用程序。它自己运行良好(使用 Google STUN 服务器),但当我为 getIceConfig 事件创建侦听器时失败。 EasyRTC 服务器在端口 8080 上,我还有一个 Apache 服务器 运行 在端口 80 上。我已经设置了我的 server.js 文件如下:
// Load required modules
var http = require("http"); // http server core module
var express = require("express"); // web framework external module
var io = require("socket.io"); // web socket external module
var easyrtc = require("../"); // EasyRTC external module
// Setup and configure Express http server. Expect a subfolder called "static" to be the web root.
var httpApp = express();
httpApp.use(express.static(__dirname + "/static/"));
// Start Express http server on port 8080
var webServer = http.createServer(httpApp).listen(8080);
// Start Socket.io so it attaches itself to Express server
var socketServer = io.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(httpApp, 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);
});
});
easyrtc.on("getIceConfig", function(connectionObj, callback) {
// This object will take in an array of XirSys STUN and TURN servers
var iceConfig = [];
request({
url: 'https://service.xirsys.com/ice',
qs: {
ident: "***",
secret: "***",
domain: "***",
application: "default",
room: "default",
secure: 1
},
function (error, response, body) {
if (!error && response.statusCode == 200) {
// body.d.iceServers is where the array of ICE servers lives
iceConfig = body.d.iceServers;
console.log(iceConfig);
callback(null, iceConfig);
}
}
});
});
调试错误信息如下:
info - EasyRTC: Starting EasyRTC Server (v1.0.15) on Node (v4.4.5)
debug - EasyRTC: Emitting event 'startup'
debug - EasyRTC: Running func 'onStartup'
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.0.15)
Initiated
debug - EasyRTC: [U0LMzF8jbIBdxq3sGtxP] Socket connected
debug - EasyRTC: Emitting event 'connection'
debug - EasyRTC: Running func 'onConnection'
debug - EasyRTC: [U0LMzF8jbIBdxq3sGtxP] Running func 'onEasyrtcAuth'
debug - EasyRTC: Attempt to request non-existent application name: 'easyrtc.audioVideoSimple'
debug - EasyRTC: Emitting Authenticate
debug - EasyRTC: Creating application: 'easyrtc.audioVideoSimple'
roomCreate fired! Trying to create: default
debug - EasyRTC: [easyrtc.audioVideoSimple] Room [default] Running func 'onRoomCreate'
debug - EasyRTC: Creating room: 'default' with options: {}
[U0LMzF8jbIBdxq3sGtxP] Credential retrieved! null
debug - EasyRTC: [easyrtc.audioVideoSimple][U0LMzF8jbIBdxq3sGtxP] Running func 'onRoomJoin'
debug - EasyRTC: [easyrtc.audioVideoSimple][U0LMzF8jbIBdxq3sGtxP] Room [default] Running func 'connectionRoomObj.emitRoomDataDelta'
debug - EasyRTC: [easyrtc.audioVideoSimple][U0LMzF8jbIBdxq3sGtxP] Room [default] Running func 'connectionRoomObj.generateRoomDataDelta'
debug - EasyRTC: [easyrtc.audioVideoSimple][U0LMzF8jbIBdxq3sGtxP] Running func 'onSendToken'
C:\Users\Jamie\nodes\easyrtc\node_modules\easyrtc\server_example\server.js:58
request({
^
ReferenceError: request is not defined
at EventEmitter.<anonymous> (C:\Users\Jamie\nodes\easyrtc\node_modules\easyrtc\server_example\server.js:58:5)
at emitTwo (events.js:87:13)
at EventEmitter.emit (events.js:172:7)
at C:\Users\Jamie\nodes\easyrtc\node_modules\easyrtc\lib\easyrtc_default_event_listeners.js:1057:34
at fn (C:\Users\Jamie\nodes\easyrtc\node_modules\easyrtc\node_modules\async\lib\async.js:582:34)
at Immediate._onImmediate (C:\Users\Jamie\nodes\easyrtc\node_modules\easyrtc\node_modules\async\lib\async.js:498:34)
at processImmediate [as _immediateCallback] (timers.js:383:17)
info - EasyRTC: Starting EasyRTC Server (v1.0.15) on Node (v4.4.5)
debug - EasyRTC: Emitting event 'startup'
debug - EasyRTC: Running func 'onStartup'
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.0.15)
Initiated
debug - EasyRTC: [YBCNOMSW7zbRXF0IH_g2] Socket connected
debug - EasyRTC: Emitting event 'connection'
debug - EasyRTC: Running func 'onConnection'
debug - EasyRTC: [YBCNOMSW7zbRXF0IH_g2] Running func 'onEasyrtcAuth'
debug - EasyRTC: Attempt to request non-existent application name: 'easyrtc.audioVideoSimple'
debug - EasyRTC: Emitting Authenticate
debug - EasyRTC: Creating application: 'easyrtc.audioVideoSimple'
roomCreate fired! Trying to create: default
debug - EasyRTC: [easyrtc.audioVideoSimple] Room [default] Running func 'onRoomCreate'
debug - EasyRTC: Creating room: 'default' with options: {}
[YBCNOMSW7zbRXF0IH_g2] Credential retrieved! null
debug - EasyRTC: [easyrtc.audioVideoSimple][YBCNOMSW7zbRXF0IH_g2] Running func 'onRoomJoin'
debug - EasyRTC: [easyrtc.audioVideoSimple][YBCNOMSW7zbRXF0IH_g2] Room [default] Running func 'connectionRoomObj.emitRoomDataDelta'
debug - EasyRTC: [easyrtc.audioVideoSimple][YBCNOMSW7zbRXF0IH_g2] Room [default] Running func 'connectionRoomObj.generateRoomDataDelta'
debug - EasyRTC: [easyrtc.audioVideoSimple][YBCNOMSW7zbRXF0IH_g2] Running func 'onSendToken'
[...path]\node_modules\easyrtc\server_example\server.js:58
request({
^
ReferenceError: request is not defined
at EventEmitter.<anonymous> ([...path]\node_modules\easyrtc\server_example\server.js:58:5)
at emitTwo (events.js:87:13)
at EventEmitter.emit (events.js:172:7)
at [...path]\node_modules\easyrtc\lib\easyrtc_default_event_listeners.js:1057:34
at fn (C[...path]\node_modules\easyrtc\node_modules\async\lib\async.js:582:34)
at Immediate._onImmediate ([...path]\node_modules\easyrtc\node_modules\async\lib\async.js:498:34)
at processImmediate [as _immediateCallback] (timers.js:383:17)
关于造成这种情况的原因有什么想法吗?它发生在 chrome 和 firefox 中。谢谢。
这是你的错误:
ReferenceError: request is not defined
您忘记使用 http 对象调用 request
。
这是您的解决方法:
改变这个:
request({
url: 'https://service.xirsys.com/ice',
...
变成这样:
http.request({
url: 'https://service.xirsys.com/ice',
...
我正在使用 EasyRTC 和 Xirsys 开发视频聊天应用程序。它自己运行良好(使用 Google STUN 服务器),但当我为 getIceConfig 事件创建侦听器时失败。 EasyRTC 服务器在端口 8080 上,我还有一个 Apache 服务器 运行 在端口 80 上。我已经设置了我的 server.js 文件如下:
// Load required modules
var http = require("http"); // http server core module
var express = require("express"); // web framework external module
var io = require("socket.io"); // web socket external module
var easyrtc = require("../"); // EasyRTC external module
// Setup and configure Express http server. Expect a subfolder called "static" to be the web root.
var httpApp = express();
httpApp.use(express.static(__dirname + "/static/"));
// Start Express http server on port 8080
var webServer = http.createServer(httpApp).listen(8080);
// Start Socket.io so it attaches itself to Express server
var socketServer = io.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(httpApp, 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);
});
});
easyrtc.on("getIceConfig", function(connectionObj, callback) {
// This object will take in an array of XirSys STUN and TURN servers
var iceConfig = [];
request({
url: 'https://service.xirsys.com/ice',
qs: {
ident: "***",
secret: "***",
domain: "***",
application: "default",
room: "default",
secure: 1
},
function (error, response, body) {
if (!error && response.statusCode == 200) {
// body.d.iceServers is where the array of ICE servers lives
iceConfig = body.d.iceServers;
console.log(iceConfig);
callback(null, iceConfig);
}
}
});
});
调试错误信息如下:
info - EasyRTC: Starting EasyRTC Server (v1.0.15) on Node (v4.4.5)
debug - EasyRTC: Emitting event 'startup'
debug - EasyRTC: Running func 'onStartup'
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.0.15)
Initiated
debug - EasyRTC: [U0LMzF8jbIBdxq3sGtxP] Socket connected
debug - EasyRTC: Emitting event 'connection'
debug - EasyRTC: Running func 'onConnection'
debug - EasyRTC: [U0LMzF8jbIBdxq3sGtxP] Running func 'onEasyrtcAuth'
debug - EasyRTC: Attempt to request non-existent application name: 'easyrtc.audioVideoSimple'
debug - EasyRTC: Emitting Authenticate
debug - EasyRTC: Creating application: 'easyrtc.audioVideoSimple'
roomCreate fired! Trying to create: default
debug - EasyRTC: [easyrtc.audioVideoSimple] Room [default] Running func 'onRoomCreate'
debug - EasyRTC: Creating room: 'default' with options: {}
[U0LMzF8jbIBdxq3sGtxP] Credential retrieved! null
debug - EasyRTC: [easyrtc.audioVideoSimple][U0LMzF8jbIBdxq3sGtxP] Running func 'onRoomJoin'
debug - EasyRTC: [easyrtc.audioVideoSimple][U0LMzF8jbIBdxq3sGtxP] Room [default] Running func 'connectionRoomObj.emitRoomDataDelta'
debug - EasyRTC: [easyrtc.audioVideoSimple][U0LMzF8jbIBdxq3sGtxP] Room [default] Running func 'connectionRoomObj.generateRoomDataDelta'
debug - EasyRTC: [easyrtc.audioVideoSimple][U0LMzF8jbIBdxq3sGtxP] Running func 'onSendToken'
C:\Users\Jamie\nodes\easyrtc\node_modules\easyrtc\server_example\server.js:58
request({
^
ReferenceError: request is not defined
at EventEmitter.<anonymous> (C:\Users\Jamie\nodes\easyrtc\node_modules\easyrtc\server_example\server.js:58:5)
at emitTwo (events.js:87:13)
at EventEmitter.emit (events.js:172:7)
at C:\Users\Jamie\nodes\easyrtc\node_modules\easyrtc\lib\easyrtc_default_event_listeners.js:1057:34
at fn (C:\Users\Jamie\nodes\easyrtc\node_modules\easyrtc\node_modules\async\lib\async.js:582:34)
at Immediate._onImmediate (C:\Users\Jamie\nodes\easyrtc\node_modules\easyrtc\node_modules\async\lib\async.js:498:34)
at processImmediate [as _immediateCallback] (timers.js:383:17)
info - EasyRTC: Starting EasyRTC Server (v1.0.15) on Node (v4.4.5)
debug - EasyRTC: Emitting event 'startup'
debug - EasyRTC: Running func 'onStartup'
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.0.15)
Initiated
debug - EasyRTC: [YBCNOMSW7zbRXF0IH_g2] Socket connected
debug - EasyRTC: Emitting event 'connection'
debug - EasyRTC: Running func 'onConnection'
debug - EasyRTC: [YBCNOMSW7zbRXF0IH_g2] Running func 'onEasyrtcAuth'
debug - EasyRTC: Attempt to request non-existent application name: 'easyrtc.audioVideoSimple'
debug - EasyRTC: Emitting Authenticate
debug - EasyRTC: Creating application: 'easyrtc.audioVideoSimple'
roomCreate fired! Trying to create: default
debug - EasyRTC: [easyrtc.audioVideoSimple] Room [default] Running func 'onRoomCreate'
debug - EasyRTC: Creating room: 'default' with options: {}
[YBCNOMSW7zbRXF0IH_g2] Credential retrieved! null
debug - EasyRTC: [easyrtc.audioVideoSimple][YBCNOMSW7zbRXF0IH_g2] Running func 'onRoomJoin'
debug - EasyRTC: [easyrtc.audioVideoSimple][YBCNOMSW7zbRXF0IH_g2] Room [default] Running func 'connectionRoomObj.emitRoomDataDelta'
debug - EasyRTC: [easyrtc.audioVideoSimple][YBCNOMSW7zbRXF0IH_g2] Room [default] Running func 'connectionRoomObj.generateRoomDataDelta'
debug - EasyRTC: [easyrtc.audioVideoSimple][YBCNOMSW7zbRXF0IH_g2] Running func 'onSendToken'
[...path]\node_modules\easyrtc\server_example\server.js:58
request({
^
ReferenceError: request is not defined
at EventEmitter.<anonymous> ([...path]\node_modules\easyrtc\server_example\server.js:58:5)
at emitTwo (events.js:87:13)
at EventEmitter.emit (events.js:172:7)
at [...path]\node_modules\easyrtc\lib\easyrtc_default_event_listeners.js:1057:34
at fn (C[...path]\node_modules\easyrtc\node_modules\async\lib\async.js:582:34)
at Immediate._onImmediate ([...path]\node_modules\easyrtc\node_modules\async\lib\async.js:498:34)
at processImmediate [as _immediateCallback] (timers.js:383:17)
关于造成这种情况的原因有什么想法吗?它发生在 chrome 和 firefox 中。谢谢。
这是你的错误:
ReferenceError: request is not defined
您忘记使用 http 对象调用 request
。
这是您的解决方法:
改变这个:
request({
url: 'https://service.xirsys.com/ice',
...
变成这样:
http.request({
url: 'https://service.xirsys.com/ice',
...