UNPKG

webrtc-scalable-broadcast

Version:

Scalable WebRTC peer-to-peer broadcasting demo.

52 lines (42 loc) 1.56 kB
// Muaz Khan - www.MuazKhan.com // MIT License - www.WebRTC-Experiment.com/licence // Source Code - https://github.com/muaz-khan/WebRTC-Scalable-Broadcast var fs = require("fs"); var path = require('path'); var app = require('http').createServer(function (request, response) { var uri = require('url').parse(request.url).pathname, filename = path.join(process.cwd(), uri); var isWin = !!process.platform.match(/^win/); if (fs.statSync(filename).isDirectory()) { if(!isWin) filename += '/index.html'; else filename += '\\index.html'; } fs.exists(filename, function (exists) { if (!exists) { response.writeHead(404, { "Content-Type": "text/plain" }); response.write('404 Not Found: ' + filename + '\n'); response.end(); return; } fs.readFile(filename, 'binary', function (err, file) { if (err) { response.writeHead(500, { "Content-Type": "text/plain" }); response.write(err + "\n"); response.end(); return; } response.writeHead(200); response.write(file, 'binary'); response.end(); }); }); }); app = app.listen(process.env.PORT || 8888, process.env.IP || "0.0.0.0", function() { var addr = app.address(); console.log("Server listening at", addr.address + ":" + addr.port); }); require('./WebRTC-Scalable-Broadcast.js')(app);