/* a fake api-ng
  create conversation rules from recorded messages
  match op only
*/

var Answer = require('..').Answer;
var conv = require('./conversation.json');
var answer = new Answer(conv);

answer.match = function sameOp(a, b) {
  if ('op' in a && 'op' in b) {
    return a.op === b.op;
  } else {
    return false;
  }
};

var port = process.argv[2] || 4444;
var io = require('socket.io').listen(port);

console.log('socket.io server listening on: ' + port);

io.sockets.on('connection', function(socket) {
  socket.on('api', function(data) {
    var ans = answer.to(data);
    if (ans) {
      socket.emit('api', ans);
    } else {
      console.warn('no answer for: ' + JSON.stringify(data));
    }
  });
});

@@ -709,12 +709,601 @@
 %7D%0A  %7D);%0A
+  // hard coded repeating publish%0A  // toggling attended status%0A  var attended = true;%0A  setInterval(function() %7B%0A    attended = !attended;%0A    socket.emit('api', %7B%0A      op: 'pub',%0A      payload: %7B%0A        %22id%22: 11,%0A        %22alias%22: %22guest1%22,%0A        %22version%22: 2,%0A        %22type%22: %22Guest%22,%0A        %22doc%22: %7B%0A          %22firstname%22: %22James%22,%0A          %22lastname%22: %22Zhu%22,%0A          %22photo%22: %22upload/photos/2014_3_11/34af3d5e-9d71-454a-af8b-b559aceb03f6.jpg%22,%0A          %22attended%22: attended%0A        %7D,%0A        %22state%22: %22updated%22,%0A        %22displayName%22: %22James Zhu%22%0A      %7D%0A    %7D);%0A  %7D, 5000);%0A
 %7D);%0A

add hardcoded repeator