const path = require('path'); const url = require('url'); const express = require('express'); const fs = require('fs'); const http = require('http'); const io = require('socket.io'); const app = express(); const port = 8443; const server = http.createServer(app).listen(port, function() { console.log('Open http://localhost:' + port + '/ with a browser'); }); // CORS app.use((req, res, next) => { res.setHeader('Access-Control-Allow-Origin', '*'); next(); }); app.use(express.static(path.join(__dirname, 'static'))); const socket = io(server); let blobs = []; socket.on('connection', (socket) => { console.log('Connected ' + socket.id); socket.on('error', (error) => { console.error('Connection ' + socket.id + ' error', error); }); socket.on('disconnect',(socket) => { console.log('Connection ' + socket.id + ' closed'); }); socket.on('blob', (data) =>{ console.log('new blob'); // Send via socket //socket.broadcast.emit('newBlob', data); // Save to file fs.appendFileSync('new.webm', data); }); });