(id, options)
| 6 | import File from './file'; |
| 7 | |
| 8 | const WebRTC = function (id, options) { |
| 9 | const defaults = { |
| 10 | config: { iceServers: [{ urls: 'stun:stun.l.google.com:19302' }] }, |
| 11 | debug: 3, |
| 12 | }; |
| 13 | |
| 14 | this.conn = new window.Peer(id, $.extend(defaults, options)); |
| 15 | |
| 16 | this.files = { |
| 17 | outgoing: {}, |
| 18 | incoming: {}, |
| 19 | }; |
| 20 | |
| 21 | // Listen for incoming connections |
| 22 | this.conn.on('connection', (connection) => { |
| 23 | $.publish('incoming_peer_connection.p2p', { connection }); |
| 24 | |
| 25 | connection.on('open', () => { |
| 26 | console.log('Peer:\t Data channel connection opened: ', connection); |
| 27 | $.publish('incoming_dc_connection.p2p', { connection }); |
| 28 | }); |
| 29 | |
| 30 | connection.on('error', (error) => { |
| 31 | console.log('Peer:\t Data channel connection error', error); |
| 32 | $.publish('incoming_dc_connection_error.p2p', { |
| 33 | connection, |
| 34 | error, |
| 35 | }); |
| 36 | }); |
| 37 | |
| 38 | this._onConnection(connection); |
| 39 | }); |
| 40 | |
| 41 | this.conn.on('close', () => { |
| 42 | console.log('Peer:\t Connection to server closed.'); |
| 43 | }); |
| 44 | |
| 45 | this.conn.on('error', (error) => { |
| 46 | console.log('Peer:\t Error while connecting to server: ', error); |
| 47 | }); |
| 48 | }; |
| 49 | |
| 50 | WebRTC.CHUNK_MTU = 16000; |
| 51 | WebRTC.CHUNKS_PER_ACK = 64; |
nothing calls this directly
no outgoing calls
no test coverage detected