我正尝试使用从开发人员githubs之一克隆的Kurento Media Server框架修改源代码。
我唯一更改的是媒体的IP地址用于websocket,并将new
关键字添加到var wss = ws.Server({ port: 8080 });
但是我遇到未定义的错误
/home/adam/rtpend/node_modules/express-session/index.js:180 如果(要求会话){ ^
TypeError:无法读取未定义的属性“会话” 在会话中(/home/adam/rtpend/node_modules/express-session/index.js:180:13) 在WebSocketServer.connect(/home/adam/rtpend/server.js:47:5) 在WebSocketServer.emit(events.js:182:13) 在WebSocketServer.EventEmitter.emit(domain.js:442:20) 在handleUpgrade(/home/adam/rtpend/node_modules/ws/lib/websocket-server.js:82:18) 在WebSocketServer.completeUpgrade(/home/adam/rtpend/node_modules/ws/lib/websocket-server.js:294:5) 在WebSocketServer.handleUpgrade(/home/adam/rtpend/node_modules/ws/lib/websocket-server.js:233:10) 在Server.upgrade(/home/adam/rtpend/node_modules/ws/lib/websocket-server.js:81:16) 在Server.emit(events.js:182:13) 在Server.EventEmitter.emit(domain.js:442:20)
大约3个星期前,我问过开发人员,但尚未收到任何回复,因此,我感谢您的投入。
var express = require('express');
var session = require('express-session')
var ws = require('ws');
var KurentoClient = require('./Kurento/KurentoClient');
var fs = require('fs');
const KURENTO_WS_URL = 'ws://192.168.6.20:8888/kurento';
//
// Express
//
var app = express();
var sessionHandler = session({
secret : 'none',
rolling : true,
resave : true,
saveUninitialized : true
});
app.use(sessionHandler);
//
// Static
//
app.use(express.static('client'));
app.listen(3000, function(){
console.log('listenning at 3000');
});
//
// Web Socket
//
var wss = ws.Server({
port: 8080,
});
wss.on('connection', function connect(newSocket, req){
//let sessionId = newSocket.upgradeReq.session.id;
let sessionId;
let request = newSocket.upgradeReq;
let response = {
writeHead : {}
};
sessionHandler(request, response, function(err) {
sessionId = request.session.id;
console.log('Connection received with sessionId ' + sessionId);
});
// create a new KurentoClient for each client
let kClient = new KurentoClient(KURENTO_WS_URL, newSocket);
newSocket.on('open', function(){
console.log(`connected to ${req.connection.remoteAddress}`);
});
newSocket.on('close', function(){
console.log('disconnected');
kClient.destroyPipeline(sessionId);
});
newSocket.on('error', function(err){
console.log(err);
kClient.destroyPipeline(sessionId);
});
//
// Message
//
newSocket.on('message', function onMessage(msg){
var parsedMsg = JSON.parse(msg);
switch(parsedMsg.id){
case 'start':
console.log('received "start" message ');
kClient.createPipeline(sessionId, parsedMsg.sdpOffer, function(err, sdpAnswer){
let response;
if(err){
console.error(err);
response = JSON.stringify({
id: 'error',
message: err
});
}
else{
if(parsedMsg.sdpOffer != null){
response = JSON.stringify({
id: 'sdpAnswer',
sdpAnswer: sdpAnswer
});
}
else {
console.log('f');
response = JSON.stringify({});
}
}
return newSocket.send(response);
});
break;
case 'stop':
kClient.destroyPipeline(sessionId);
break;
case 'iceCandidate':
console.log('received ice candidate');
kClient.addClientIceCandidate(sessionId, parsedMsg.candidate);
break;
default:
newSocket.send(JSON.stringify({
id: 'error',
message: 'Invalid message '
}));
break;
}
});
});