Skip to content

Instantly share code, notes, and snippets.

@probablycorey
Created July 19, 2013 00:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save probablycorey/6034261 to your computer and use it in GitHub Desktop.
Save probablycorey/6034261 to your computer and use it in GitHub Desktop.
A bug in peer js
<!DOCTYPE HTML>
<html lang="en">
<head>
<title>PeerJS Issue</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Language" content="en-us">
<script type="text/javascript" src="http://cdn.peerjs.com/0/peer.js"></script>
<script type="text/javascript" src="http://coffeescript.org/extras/coffee-script.js"></script>
<script type="text/coffeescript">
window.host = ->
peer = new Peer("host", key: '0njqmaln320dlsor')
peer.on 'open', (id) ->
console.log(id)
peer.on 'connection', (connection) ->
if connection.label == 'first'
window.firstConnection = connection
connection.on 'open', ->
message = "This will be received by the guest"
console.log "first-connnection: open and sending: #{message}"
connection.send message
else if connection.label == 'second'
window.secondConnection = connection
connection.on 'open', ->
message = "This does not arrive"
console.log "seccond: open and sending: #{message}"
connection.send message
setTimeout (-> connection.send "Try after 1ms", message), 1
setTimeout (-> connection.send "Try after 10ms", message), 10
setTimeout (-> connection.send "Try after 25ms", message), 25
setTimeout (-> connection.send "Try after 50ms", message), 50
setTimeout (-> connection.send "Try after 1s", message), 1000
window.join = ->
peer = new Peer('guest', key: '0njqmaln320dlsor')
window.firstConnection = peer.connect('host', label: 'first')
firstConnection.on 'open', ->
console.log "first-connnection: open"
firstConnection.on 'data', (data) -> console.log "first-connnection: data", data
window.secondConnection = peer.connect('host', label: 'second')
secondConnection.on 'open', ->
console.log "second-connnection: open"
secondConnection.on 'data', (data) -> console.log "second-connnection: data", data
</script>
</head>
<body>
<h1>LOOK IN THE CONSOLE!!!!</h1>
<button onclick='window.host()'>Host</button>
<button onclick='window.join()'>Join</button>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment