mirror of https://github.com/kern/filepizza
Use a local PeerJS server.
parent
22ecf9cb12
commit
3da3b2d443
@ -1,13 +0,0 @@
|
|||||||
import DownloadActions from './actions/DownloadActions';
|
|
||||||
import Peer from 'peerjs';
|
|
||||||
import PeerActions from './actions/PeerActions';
|
|
||||||
|
|
||||||
var peer = module.exports = new Peer({ key: '8w3x9m637e0o1or' });
|
|
||||||
|
|
||||||
peer.on('open', function () {
|
|
||||||
PeerActions.setPeerID(peer.id);
|
|
||||||
});
|
|
||||||
|
|
||||||
peer.on('connection', function (conn) {
|
|
||||||
DownloadActions.beginDownload(conn);
|
|
||||||
});
|
|
||||||
@ -1,19 +1,30 @@
|
|||||||
|
import Peer from 'peerjs';
|
||||||
import PeerActions from '../actions/PeerActions';
|
import PeerActions from '../actions/PeerActions';
|
||||||
import alt from '../alt';
|
import alt from '../alt';
|
||||||
|
import uuid from 'node-uuid';
|
||||||
|
|
||||||
export default alt.createStore(class PeerStore {
|
let id = uuid.v4();
|
||||||
|
let peer = new Peer(id, {
|
||||||
|
host: window.location.hostname,
|
||||||
|
port: window.location.port,
|
||||||
|
path: '/peer'
|
||||||
|
});
|
||||||
|
|
||||||
constructor() {
|
peer.on('connection', (conn) => {
|
||||||
this.bindActions(PeerActions);
|
PeerActions.peerConnected(conn);
|
||||||
this.peerID = null;
|
});
|
||||||
}
|
|
||||||
|
export default alt.createStore(class PeerStore {
|
||||||
|
|
||||||
onSetPeerID(id) {
|
static connect(peerID, metadata) {
|
||||||
this.peerID = id;
|
return peer.connect(peerID, {
|
||||||
|
reliable: true,
|
||||||
|
metadata: metadata
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
static getPeerID() {
|
static getPeerID() {
|
||||||
return this.getState().peerID;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue