mirror of
https://github.com/szimek/sharedrop.git
synced 2026-06-13 21:03:07 +08:00
File transfer seems to work
This commit is contained in:
parent
16854d3350
commit
005f1828c6
@ -2,10 +2,12 @@ ShareDrop.App.ApplicationController = Ember.Controller.extend({
|
||||
init: function () {
|
||||
this._super();
|
||||
|
||||
var you = ShareDrop.App.User.create({
|
||||
uuid: ShareDrop.App.userId,
|
||||
var id = ShareDrop.App.userId,
|
||||
you = ShareDrop.App.User.create({
|
||||
uuid: id,
|
||||
email: localStorage.email || null
|
||||
});
|
||||
you.set('peer.id', id);
|
||||
|
||||
this.set('you', you);
|
||||
this.handlePersonaAuth();
|
||||
|
||||
@ -12,7 +12,6 @@ ShareDrop.App.IndexController = Ember.ArrayController.extend({
|
||||
$.subscribe('user_removed.room', this._onRoomUserRemoved.bind(this));
|
||||
|
||||
// Handle peer events
|
||||
$.subscribe('connected.server.peer', this._onPeerServerConnected.bind(this));
|
||||
$.subscribe('incoming_connection.p2p.peer', this._onPeerP2PIncomingConnection.bind(this));
|
||||
$.subscribe('outgoing_connection.p2p.peer', this._onPeerP2POutgoingConnection.bind(this));
|
||||
$.subscribe('disconnected.p2p.peer', this._onPeerP2PDisconnected.bind(this));
|
||||
@ -22,15 +21,17 @@ ShareDrop.App.IndexController = Ember.ArrayController.extend({
|
||||
$.subscribe('file_received.p2p.peer', this._onPeerP2PFileReceived.bind(this));
|
||||
$.subscribe('file_sent.p2p.peer', this._onPeerP2PFileSent.bind(this));
|
||||
|
||||
// Connect to PeerJS server first,
|
||||
// so that we already have peer ID when later joining a room.
|
||||
this.set('webrtc', new ShareDrop.WebRTC());
|
||||
// Join the room
|
||||
var room = new ShareDrop.Room(ShareDrop.App.ref);
|
||||
room.join(this.get('you').serialize());
|
||||
this.set('room', room);
|
||||
|
||||
this._super();
|
||||
},
|
||||
|
||||
_onRoomConnected: function (event, data) {
|
||||
var you = this.get('you');
|
||||
var you = this.get('you'),
|
||||
room = this.get('room');
|
||||
|
||||
you.get('peer').setProperties(data.peer);
|
||||
delete data.peer;
|
||||
@ -38,6 +39,12 @@ ShareDrop.App.IndexController = Ember.ArrayController.extend({
|
||||
|
||||
// Find and set your local IP
|
||||
this._setUserLocalIP();
|
||||
|
||||
// Initialize WebRTC
|
||||
this.set('webrtc', new ShareDrop.WebRTC(you.get('uuid'), {
|
||||
room: room.name,
|
||||
firebaseRef: ShareDrop.App.ref
|
||||
}));
|
||||
},
|
||||
|
||||
_onRoomUserAdded: function (event, data) {
|
||||
@ -75,18 +82,6 @@ ShareDrop.App.IndexController = Ember.ArrayController.extend({
|
||||
this.removeObject(peer);
|
||||
},
|
||||
|
||||
_onPeerServerConnected: function (event, data) {
|
||||
var you = this.get('you');
|
||||
|
||||
// you.set('isConnected', true);
|
||||
you.set('peer.id', data.id);
|
||||
|
||||
// Join room and broadcast your attributes
|
||||
var room = new ShareDrop.Room(ShareDrop.App.ref);
|
||||
room.join(you.serialize());
|
||||
this.set('room', room);
|
||||
},
|
||||
|
||||
_onPeerP2PIncomingConnection: function (event, data) {
|
||||
var connection = data.connection,
|
||||
peer = this.findBy('peer.id', connection.peer);
|
||||
|
||||
@ -1,34 +1,20 @@
|
||||
// TODO: provide TURN server config
|
||||
// once it's possible to create rooms with custom names.
|
||||
ShareDrop.WebRTC = function (options) {
|
||||
this.conn = new Peer({ // PeerJS client library
|
||||
host: 'file-drop-peer-server.herokuapp.com',
|
||||
port: 80,
|
||||
ShareDrop.WebRTC = function (id, options) {
|
||||
var defaults = {
|
||||
config: {'iceServers': [
|
||||
{ url: 'stun:stun.l.google.com:19302' }
|
||||
]},
|
||||
debug: 3
|
||||
});
|
||||
};
|
||||
|
||||
this.conn = new Peer(id, $.extend(defaults, options));
|
||||
|
||||
this.files = {
|
||||
outgoing: {},
|
||||
incoming: {}
|
||||
};
|
||||
|
||||
// When connected to PeerJS server
|
||||
this.conn.on('open', function (id) {
|
||||
var self = this;
|
||||
|
||||
$.publish('connected.server.peer', {id: id});
|
||||
console.log('Peer:\t Connected to server with ID: ', id);
|
||||
|
||||
// TODO: cancel on error/disconnect
|
||||
// Ping WebSocket server to prevent timeout on Heroku
|
||||
window.setInterval(function () {
|
||||
self.socket.send({type: 'ping'});
|
||||
}, 5000);
|
||||
});
|
||||
|
||||
// Listen for incoming connections
|
||||
this.conn.on('connection', function (connection) {
|
||||
$.publish('incoming_connection.p2p.peer', {connection: connection});
|
||||
|
||||
@ -4,10 +4,14 @@ ShareDrop.App.User = ShareDrop.App.Peer.extend({
|
||||
local_ip = this.get('local_ip'),
|
||||
label;
|
||||
|
||||
if (email) {
|
||||
if (email && local_ip) {
|
||||
label = email + ' (' + local_ip + ')';
|
||||
} else {
|
||||
} else if (local_ip) {
|
||||
label = local_ip;
|
||||
} else if (email) {
|
||||
label = email;
|
||||
} else {
|
||||
label = null;
|
||||
}
|
||||
|
||||
return label;
|
||||
|
||||
1178
app/scripts/vendor/peer.js
vendored
1178
app/scripts/vendor/peer.js
vendored
File diff suppressed because it is too large
Load Diff
19
todo.txt
19
todo.txt
@ -1,19 +0,0 @@
|
||||
# V1
|
||||
- persona + email update
|
||||
- fix broadcasting emails on page load
|
||||
- ensure that socket.io has the most recent version with emails
|
||||
- tooltips
|
||||
|
||||
# V2 (needs changes to PeerJS library)
|
||||
- serialize files asynchronously
|
||||
- show progress bar for sender and recipient
|
||||
|
||||
# V3:
|
||||
- set email from Persona on server side to avoid faking it
|
||||
- send multiple files (one after another)
|
||||
- allow to get room name from URL (provided or generated) for wan connections; don't get public IP in this case
|
||||
|
||||
# Firebase (?)
|
||||
- use Firebase instead of socket.io for room server
|
||||
- initial vs new peers https://groups.google.com/forum/#!topic/firebase-talk/iZ3eLYAZBkU
|
||||
- less hosting issues, but only max 50 connections on free plan...
|
||||
Loading…
Reference in New Issue
Block a user