MCPcopy Create free account
hub / github.com/ShareDropio/sharedrop / WebRTC

Function WebRTC

app/services/web-rtc.js:8–48  ·  view source on GitHub ↗
(id, options)

Source from the content-addressed store, hash-verified

6import File from './file';
7
8const 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
50WebRTC.CHUNK_MTU = 16000;
51WebRTC.CHUNKS_PER_ACK = 64;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected