Update http-external-ws.js

use classic functions instead of es6
fix peers.find should be peers.findIndex for splice.
This commit is contained in:
d3x0r 2016-12-26 22:33:46 -08:00 committed by GitHub
parent 85ae140512
commit 4a5ab4122b

View File

@ -42,13 +42,13 @@ function acceptConnection( connection ) {
gunPeers.push( connection );
gun.on('out', (msg)=>{
msg = JSON.stringify({headers:{},body:msg});
gunPeers.forEach( (peer)=>{ peer.send( msg ) })
gunPeers.forEach( function(peer){ peer.send( msg ) })
})
connection.on( 'error',(error)=>{console.log( "WebSocket Error:", error } );
connection.on( 'message',(msg)=>{gun.on('in',JSON.parse( msg.utf8Data).body)})
connection.on( 'close', (reason,desc)=>{
connection.on( 'error',function(error){console.log( "WebSocket Error:", error } );
connection.on( 'message',function(msg){gun.on('in',JSON.parse( msg.utf8Data).body)})
connection.on( 'close', function(reason,desc){
// gunpeers gone.
var i = peers.find( p=>p===connection );
var i = peers.findIndex( function(p){return p===connection} );
if( i >= 0 )
gunPeers.splice( i, 1 );