JSFiddle - React, Tailwind, and code Playground

by Yoshiharu Kamata

HTML

<script src="https://cdn.rawgit.com/jeromeetienne/jquery-qrcode/master/jquery.qrcode.min.js"></script>
<script src="http://cdn.peerjs.com/0.3/peer.js"></script>
<textarea name="text" id="" cols="30" rows="10"></textarea>
<button>send</button>
<ul id="log"></ul>
<div id="qrcode"></div>

CoffeeScript

other_id = location.hash.replace '#', ''
conn = null
peer = new Peer
  host:'peerjs-kamata.herokuapp.com'
  secure:true
  port:443
  key: 'peerjs'
  debug: 3
log = (text)->
  $("<li>").text(text).appendTo('#log')
readyConn = (conn)->
  conn.on 'data', (text)->
    log text
if other_id
  log other_id
  conn = peer.connect other_id
  readyConn conn
else
  peer.on 'open', (id)->
    url = "#{location.href}##{id}"
    log url    
    $("#qrcode").qrcode
      width: 128
      height: 128
      text: url
  peer.on 'connection', (con)->
    log "connection"    
    conn = con
    readyConn con
$('button').on 'click', ->
  text = $("textarea").val()
  if text
    conn?.send text