<commit_before>'use strict';
/**
 * Module dependencies.
 */

var express = require('express')
  , routes = require('./routes')
  , http = require('http')
  , path = require('path')
  , app = express()
  , server = http.createServer(app)
  , WebSocketServer = require('ws').Server
  , wss = new WebSocketServer({server: server})
  , sockets = [];
  ;

var videoStream = (function init() {
    var arDrone = require('ar-drone'),
        tcpVideoStream = new arDrone.Client.PngStream.TcpVideoStream({timeout: 4000}),
        Parser = require('./lib/PaVEParser'),
        p = new Parser();

    tcpVideoStream.connect(function () {
        tcpVideoStream.pipe(p);
    });

   return p; 
})();

videoStream.on('data', function (data) {
  sockets.forEach(function(socket) {
    socket.send(data, {binary: true});
  });
});


wss.on('connection', function (socket) {
  sockets.push(socket);

  socket.on("close", function() {
    console.log("Closing socket");
    sockets = sockets.filter(function(el) {
      return el !== socket;
    });
  });
});


app.configure(function () {
    app.set('port', process.env.PORT || 3000);
    app.set('views', __dirname + '/views');
    app.set('view engine', 'jade', { pretty: true });<commit_msg>Automatically re-connecting the video stream on error.<commit_after>'use strict';
/**
 * Module dependencies.
 */

var express = require('express')
  , routes = require('./routes')
  , http = require('http')
  , path = require('path')
  , app = express()
  , server = http.createServer(app)
  , WebSocketServer = require('ws').Server
  , wss = new WebSocketServer({server: server})
  , sockets = []
  , Parser = require('./lib/PaVEParser')
  , arDrone = require('ar-drone')
  ;

function init() {
    var tcpVideoStream = new arDrone.Client.PngStream.TcpVideoStream({timeout: 4000})
      , p = new Parser();

    console.log("Connecting to stream");

    tcpVideoStream.connect(function () {
        tcpVideoStream.pipe(p);
    });

    tcpVideoStream.on("error", function(err) {
      console.log("There was an error: %s", err.message);
      tcpVideoStream.end();
      tcpVideoStream.emit("end");
      init();
    });

    p.on('data', function (data) {
      sockets.forEach(function(socket) {
        socket.send(data, {binary: true});
      });
    });
}
init();

wss.on('connection', function (socket) {
  sockets.push(socket);

  socket.on("close", function() {
    console.log("Closing socket");
    sockets = sockets.filter(function(el) {
      return el !== socket;
    });
  });
});


app.configure(function () {
    app.set('port', process.env.PORT || 3000);
    app.set('views', __dirname + '/views');
    app.set('view engine', 'jade', { pretty: true });
{'fraction_non_alphanumeric': 0.18541820873427092, 'fraction_numerical': 0.005921539600296077, 'mean_word_length': 3.331730769230769, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2411881', 'n_tokens_mistral': 887, 'n_tokens_neox': 854, 'n_words': 169}