I follow the manual of this link (step 7). I have successfully installed both node.js or socket.js, but when I go to the page and try to send the image, I get this error on the server
Missing error handler on `socket`.
TypeError: io.sockets.clients is not a function
at Socket.<anonymous> (C:\Users\utente\Projects\webrtc\server.js:30:31)
at emitOne (events.js:77:13)
at Socket.emit (events.js:169:7)
at Socket.onevent (C:\Users\utente\Projects\webrtc\node_modules\socket.io\lib\socket.js:330:8)
at Socket.onpacket (C:\Users\utente\Projects\webrtc\node_modules\socket.io\lib\socket.js:290:12)
at Client.ondecoded (C:\Users\utente\Projects\webrtc\node_modules\socket.io\lib\client.js:193:14)
at Decoder.Emitter.emit (C:\Users\utente\Projects\webrtc\node_modules\socket.io\node_modules\socket.io-parser\node_modules\component-emitter\index.js:134:20)
at Decoder.add (C:\Users\utente\Projects\webrtc\node_modules\socket.io\node_modules\socket.io-parser\index.js:247:12)
at Client.ondata (C:\Users\utente\Projects\webrtc\node_modules\socket.io\lib\client.js:175:18)
at emitOne (events.js:77:13)
my server.js file
var os = require('os');
var static = require('node-static');
var http = require('http');
var socketIO = require('socket.io');
var fileServer = new(static.Server)();
var app = http.createServer(function (req, res) {
fileServer.serve(req, res);
}).listen(2013);
var io = socketIO.listen(app);
io.sockets.on('connection', function (socket){
function log(){
var array = [">>> Message from server:"];
array.push.apply(array, arguments);
socket.emit('log', array);
}
socket.on('message', function (message) {
log('Client said:', message);
socket.broadcast.emit('message', message);
});
socket.on('create or join', function (room) {
log('Request to create or join room ' + room);
var numClients = io.sockets.clients(room).length;
log('Room ' + room + ' has ' + numClients + ' client(s)');
if (numClients === 0){
socket.join(room);
socket.emit('created', room, socket.id);
} else if (numClients === 1) {
socket.join(room);
socket.emit('joined', room, socket.id);
io.sockets.in(room).emit('ready');
} else {
socket.emit('full', room);
}
});
socket.on('ipaddr', function () {
var ifaces = os.networkInterfaces();
for (var dev in ifaces) {
ifaces[dev].forEach(function (details) {
if (details.family=='IPv4' && details.address != '127.0.0.1') {
socket.emit('ipaddr', details.address);
}
});
}
});
});
index.html
<!DOCTYPE html>
<html>
<head>
<meta name="keywords" content="JavaScript, WebRTC" />
<meta name="description" content="WebRTC codelab" />
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1">
<title>WebRTC codelab: step X</title>
<link rel="stylesheet" href="css/main.css">
</head>
<body>
<h1>WebRTC codelab: step X</h1>
<p>
Room URL: <br>
<code id="url">...</code>
</p>
<video class="camera" autoplay></video>
<div class="controls">
<canvas id="photo" style="width: 200px; height: 150px; border: 1px solid #ccc;"></canvas>
<p>
<button id="snap">snap</button>-then-<button id="send">send</button>
<br> - or - <br>
<button id="snapAndSend">snap & send</button>
</p>
</div>
<div class="incoming">
<h2>Incoming photos</h2>
<div id="trail"></div>
</div>
<script src="node_modules\socket.io\node_modules\socket.io-client\socket.io.js"></script>
<script src="js/lib/adapter.js"></script>
<script src="js/main.js"></script>
</body>
any help?
Many thanks
with io.sockets.clients [room] .length; I solved the error, but now I get
Missing error handler on `socket`.
TypeError: Cannot read property '8a675bfe1203e' of undefined
at Socket.<anonymous> (C:\Users\utente\Projects\webrtc\server.js:30:38)
at emitOne (events.js:77:13)
at Socket.emit (events.js:169:7)
at Socket.onevent (C:\Users\utente\Projects\webrtc\node_modules\socket.io\lib\socket.js:330:8)
at Socket.onpacket (C:\Users\utente\Projects\webrtc\node_modules\socket.io\lib\socket.js:290:12)
at Client.ondecoded (C:\Users\utente\Projects\webrtc\node_modules\socket.io\lib\client.js:193:14)
at Decoder.Emitter.emit (C:\Users\utente\Projects\webrtc\node_modules\socket.io\node_modules\socket.io-parser\node_modules\component-emitter\index.js:134:20)
at Decoder.add (C:\Users\utente\Projects\webrtc\node_modules\socket.io\node_modules\socket.io-parser\index.js:247:12)
at Client.ondata (C:\Users\utente\Projects\webrtc\node_modules\socket.io\lib\client.js:175:18)
at emitOne (events.js:77:13)