message: added web socket hearbeat
diff: @@ -10,13 +10,19 @@ function SocketBot(configuration) {
  var controller = Botkit(configuration || {});
  +
  controller.openSocketServer = function(server) {
  // create the socket server along side the existing webserver.
  var wss = new WebSocket.Server({ server });
  - wss.on('connection', function connection(ws) {
  + function heartbeat() {
  + this.isAlive = true;
  + }
  + wss.on('connection', function connection(ws) {
  + ws.isAlive = true;
  + ws.on('pong', heartbeat);
  // search through all the convos, if a bot matches, update its ws
  var bot = controller.spawn();
  bot.ws = ws;
  @@ -72,6 +78,14 @@ function SocketBot(configuration) {
  });
  });
  +
  + var interval = setInterval(function ping() {
  + wss.clients.forEach(function each(ws) {
  + if (ws.isAlive === false) return ws.terminate()
  + ws.isAlive = false;
  + ws.ping('', false, true);
  + });
  + }, 30000);
  }
  