<commit_before>var peer = require('./peer');

var textOT = require('ottypes').text
var gulf = require('gulf');
var bindEditor = require('gulf-textarea');
var textarea = document.querySelector('textarea#doc');
var textareaDoc = bindEditor(textarea);
var text = 'hello';

var path = 'chat.sock';
// var transport = require('./transports/socket')(path);
// var transport = require('./transports/mdns')({ port: 4321, name: 'nybblr' });
var transport = require('./transports/webrtc')();

peer(transport).then(stream => {
  console.log('started');
  console.log(stream.server ? 'master' : 'slave');
  window.stream = stream;

  var textareaMaster = textareaDoc.masterLink();

  if (stream.server) {
    // master
    gulf.Document.create(new gulf.MemoryAdapter, textOT, text, (err, doc) => {
      var slave1 = doc.slaveLink();
      stream.pipe(slave1).pipe(stream);

      var slave2 = doc.slaveLink();
      textareaMaster.pipe(slave2).pipe(textareaMaster);
    });
  } else {
    // slave
    textareaMaster.pipe(stream).pipe(textareaMaster);
  }
});
<commit_msg>Tidy doc representation into swappable one-liner.<commit_after>var peer = require('./peer');

var textOT = require('ottypes').text
var gulf = require('gulf');
var text = 'hello';

var doc = require('gulf-textarea')(
  document.querySelector('textarea#doc')
);

var path = 'chat.sock';
// var transport = require('./transports/socket')(path);
// var transport = require('./transports/mdns')({ port: 4321, name: 'nybblr' });
var transport = require('./transports/webrtc')();

peer(transport).then(stream => {
  console.log('started');
  console.log(stream.server ? 'master' : 'slave');
  window.stream = stream;

  var textareaMaster = doc.masterLink();

  if (stream.server) {
    // master
    gulf.Document.create(new gulf.MemoryAdapter, textOT, text, (err, master) => {
      var slave1 = master.slaveLink();
      stream.pipe(slave1).pipe(stream);

      var slave2 = master.slaveLink();
      textareaMaster.pipe(slave2).pipe(textareaMaster);
    });
  } else {
    // slave
    textareaMaster.pipe(stream).pipe(textareaMaster);
  }
});

{'fraction_non_alphanumeric': 0.1779257849666984, 'fraction_numerical': 0.007611798287345386, 'mean_word_length': 4.092009685230024, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '1397142', 'n_tokens_mistral': 682, 'n_tokens_neox': 655, 'n_words': 134}