0

认为我一定遗漏了一些东西,但我没有调试能力来检查。Web 应用程序通过 socket.io 将数据传递给 node.js 服务器,但不会返回任何内容。

服务器.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");           // 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});

 // Start EasyRTC server
 var rtc = easyrtc.listen(httpApp, socketServer);

easyrtc.events.on('get_candy', function(easyrtc) {
  easyrtc.events.emit('did it');
});

文件.js

function joined_room() {
easyrtc.sendServerMessage('get_candy', {candy_name:'mars'},
        function(msgType, msgData ) {
           console.log("got candy count of " + msgData.barCount);
        },
        function(errorCode, errorText) {
           console.log("error was " + errorText);
        });
}

easyrtc.setServerListener( function(msgType, msgData, targeting) {
    console.log("The Server sent the following message " + JSON.stringify(msgData));
}, 'get_candy');
4

1 回答 1

0

几个月前我遇到了同样的问题,现在我的解决方案是在服务器上重用 websocket:在客户端:

var socket = io.connect('http://' + document.domain + ':' + location.port);
easyrtc.useThisSocketConnection(socket);

在服务器端:

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

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);

var rtc = easyrtc.listen(webServer, io, null, function(err, rtcRef) {
  rtcRef.events.on('roomCreate', function(appObj, creatorConnectionObj, roomName, roomOptions, callback) {
    console.log('roomCreate fired!');
  });
});

此片段允许您将 websocket 重用于easyRTC。RTC 和其他的签名消息可以使用相同的 websocket。

于 2015-11-20T06:40:34.060 回答