(application)
| 7 | import Analytics from '../services/analytics'; |
| 8 | |
| 9 | export function initialize(application) { |
| 10 | function checkWebRTCSupport() { |
| 11 | return new Promise((resolve, reject) => { |
| 12 | // window.util is a part of PeerJS library |
| 13 | if (window.util.supports.sctp) { |
| 14 | resolve(); |
| 15 | } else { |
| 16 | // eslint-disable-next-line prefer-promise-reject-errors |
| 17 | reject('browser-unsupported'); |
| 18 | } |
| 19 | }); |
| 20 | } |
| 21 | |
| 22 | function clearFileSystem() { |
| 23 | return new Promise((resolve, reject) => { |
| 24 | // TODO: change File into a service and require it here |
| 25 | FileSystem.removeAll() |
| 26 | .then(() => { |
| 27 | resolve(); |
| 28 | }) |
| 29 | .catch(() => { |
| 30 | // eslint-disable-next-line prefer-promise-reject-errors |
| 31 | reject('filesystem-unavailable'); |
| 32 | }); |
| 33 | }); |
| 34 | } |
| 35 | |
| 36 | function authenticateToFirebase() { |
| 37 | return new Promise((resolve, reject) => { |
| 38 | const xhr = $.getJSON('/auth'); |
| 39 | xhr.then((data) => { |
| 40 | const ref = new window.Firebase(config.FIREBASE_URL); |
| 41 | // eslint-disable-next-line no-param-reassign |
| 42 | application.ref = ref; |
| 43 | // eslint-disable-next-line no-param-reassign |
| 44 | application.userId = data.id; |
| 45 | // eslint-disable-next-line no-param-reassign |
| 46 | application.publicIp = data.public_ip; |
| 47 | |
| 48 | ref.authWithCustomToken(data.token, (error) => { |
| 49 | if (error) { |
| 50 | reject(error); |
| 51 | } else { |
| 52 | resolve(); |
| 53 | } |
| 54 | }); |
| 55 | }); |
| 56 | }); |
| 57 | } |
| 58 | |
| 59 | // TODO: move it to a separate initializer |
| 60 | function trackSizeOfReceivedFiles() { |
| 61 | $.subscribe('file_received.p2p', (event, data) => { |
| 62 | Analytics.trackEvent('received', { |
| 63 | event_category: 'file', |
| 64 | event_label: 'size', |
| 65 | value: Math.round(data.info.size / 1000), |
| 66 | }); |
nothing calls this directly
no test coverage detected