Skip to content

Commit 6b66285

Browse files
committedMar 12, 2021
many changes and web3modal now registers mobile disconnect
1 parent 4b39ccd commit 6b66285

13 files changed

+243
-180
lines changed
 

‎src/connectClient/WebRtcCommunication.js

+5-14
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ export default class WebRtcCommunication extends MewConnectCommon {
147147
this.p._pc.addEventListener(
148148
'icecandidateerror',
149149
event => {
150-
console.log('ICE CANIDATE ERROR', event); // todo remove dev item
150+
debug('ICE CANIDATE ERROR', event); // todo remove dev item
151151
}
152152
);
153153
}
@@ -198,7 +198,6 @@ export default class WebRtcCommunication extends MewConnectCommon {
198198
try {
199199
this.answerReceived[this.p.peerInstanceId] = true;
200200
this.p.signal(plainTextOffer);
201-
this.p.getStats(console.log)
202201
debug('webRTC answer received and processed');
203202
} catch (e) {
204203
// eslint-disable-next-line
@@ -234,18 +233,19 @@ export default class WebRtcCommunication extends MewConnectCommon {
234233
// Handle Socket Attempting Turn informative signal
235234
// Provide Notice that initial WebRTC connection failed and the fallback method will be used
236235
willAttemptTurn() {
237-
debugStages('TRY TURN CONNECTION');
236+
238237
this.uiCommunicator(this.lifeCycle.UsingFallback);
239238
if(!this.connected && this.tryingTurn && this.usingVersion === 'V2'){
240239
this.refreshQrTimer();
241240
this.refreshEnabled = false;
242241
}
243242
if (!this.tryingTurn && this.usingVersion === 'V2') {
243+
debugStages('[webRTC Comm.] TRY TURN CONNECTION');
244244
debugStages(' TRY TURN V2');
245245
this.tryingTurn = true;
246246
try {
247247
this.useFallback();
248-
this.uiCommunicator(this.lifeCycle.UsingFallback);
248+
// this.uiCommunicator(this.lifeCycle.UsingFallback);
249249
} catch (e) {
250250
// eslint-disable-next-line
251251
console.error(e);
@@ -273,7 +273,7 @@ export default class WebRtcCommunication extends MewConnectCommon {
273273

274274
useFallback() {
275275
if (!this.connected) {
276-
this.emit('useFallback', this.activeInitiatorId);
276+
this.emit(this.lifeCycle.UsingFallback, this.activeInitiatorId);
277277
}
278278
}
279279

@@ -330,8 +330,6 @@ export default class WebRtcCommunication extends MewConnectCommon {
330330

331331
// this.emit('appData', data);
332332
try {
333-
console.log('DATA', data); // todo remove dev item
334-
335333
let decryptedData;
336334
if (this.isJSON(data)) {
337335
decryptedData = await this.mewCrypto.decrypt(
@@ -365,10 +363,8 @@ export default class WebRtcCommunication extends MewConnectCommon {
365363
}
366364

367365
onClose(peerID, data) {
368-
console.log('1'); // todo remove dev item
369366
debugStages('WRTC onClose event');
370367
debug('peerID', peerID);
371-
console.log('onClose', this.connected); // todo remove dev item
372368
if (!this.isAlive()) {
373369
debugStages('WRTC CLOSE', data);
374370
if (this.connected) {
@@ -379,11 +375,6 @@ export default class WebRtcCommunication extends MewConnectCommon {
379375
this.connected = false;
380376
}
381377
}
382-
if (this.connected) {
383-
this.emit(this.lifeCycle.RtcClosedEvent);
384-
this.uiCommunicator(this.lifeCycle.disconnected);
385-
this.connected = false;
386-
}
387378
}
388379

389380
onError(peerID, err) {

‎src/connectClient/initiator/MewConnectInitiator.js

+14-7
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,6 @@ export default class MewConnectInitiator extends MewConnectCommon {
249249
} else {
250250
this.popupCreator.refreshQrcode = this.initiatorStart.bind(this);
251251
this.popupCreator.openPopupWindow(qrCodeString);
252-
// this.popupCreator.container.addEventListener('beforeunload', unloadOrClosed);
253252
this.popupCreator.container.addEventListener(
254253
'mewModalClosed',
255254
unloadOrClosed,
@@ -346,15 +345,24 @@ Keys
346345
debug('REGENERATE'); // todo remove dev item
347346
this.refreshCode();
348347
}
349-
this.V2.on('ShowReload', () => {
350-
this.uiCommunicator('ShowReload');
351-
});
348+
// this.V2.on('ShowReload', () => {
349+
// this.uiCommunicator('ShowReload');
350+
// });
351+
352+
this.V2.on('socketDisconnected', () => {
353+
if(!this.connected){
354+
if(!this.showingRefresh){
355+
this.showingRefresh = true;
356+
this.popupCreator.showRetry(regenerateQRcodeOnClick)
357+
}
358+
}
359+
})
360+
352361
this.webRtcCommunication.on('showRefresh', () => {
353362
if(!this.showingRefresh){
354363
this.showingRefresh = true;
355364
this.popupCreator.showRetry(regenerateQRcodeOnClick)
356365
}
357-
358366
})
359367
} catch (e) {
360368
// eslint-disable-next-line
@@ -378,7 +386,6 @@ Keys
378386

379387
if (this.V1.on) {
380388
this.V1.on('socketPaired', () => {
381-
console.log('socket 1 CONNECTED'); // todo remove dev item
382389
if (this.V2.socketDisconnect) this.V2.socketDisconnect();
383390
this.socketV1Connected = true;
384391
});
@@ -413,9 +420,9 @@ Keys
413420

414421
disconnectRTC() {
415422
debugStages('DISCONNECT RTC');
416-
this.connected = false;
417423
this.uiCommunicator(this.lifeCycle.RtcDisconnectEvent);
418424
this.webRtcCommunication.disconnectRTC();
425+
this.connected = false;
419426
this.instance = null;
420427
}
421428

‎src/connectClient/initiator/MewConnectInitiatorV2.js

+26-17
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,8 @@ export default class MewConnectInitiatorV2 extends MewConnectCommon {
5555
this.iceStates = this.jsonDetails.iceConnectionState;
5656
this.initiatorId = uuid();
5757
this.isActiveInstance = true;
58-
// Socket is abandoned. disconnect.
5958
this.timer = null;
60-
// setTimeout(() => {
61-
// if (this.socket) {
62-
// this.socketDisconnect();
63-
// }
64-
// }, 120000);
59+
6560

6661
// WebRTC options
6762
this.iceTransportPolicy = 'all';
@@ -70,7 +65,7 @@ export default class MewConnectInitiatorV2 extends MewConnectCommon {
7065
debug('constructor error:', e);
7166
}
7267

73-
this.webRtcCommunication.on('useFallback', id => {
68+
this.webRtcCommunication.on(this.lifeCycle.UsingFallback, id => {
7469
debug('USING TURN FALLBACK');
7570
if (this.initiatorId === id) {
7671
this.useFallback();
@@ -159,8 +154,7 @@ export default class MewConnectInitiatorV2 extends MewConnectCommon {
159154
this.mewCrypto = cryptoInstance;
160155
this.uiCommunicator(this.lifeCycle.signatureCheck);
161156
await this.connect(url);
162-
// this.socket = this.socketManager.connect();
163-
this.initiatorConnect();
157+
this.setupListeners();
164158
} catch (e) {
165159
debug('initiatorStart error:', e);
166160
}
@@ -226,7 +220,7 @@ export default class MewConnectInitiatorV2 extends MewConnectCommon {
226220
}
227221
}
228222

229-
initiatorConnect() {
223+
setupListeners() {
230224
try {
231225
debugStages('INITIATOR CONNECT');
232226
this.uiCommunicator(this.lifeCycle.SocketConnectedEvent);
@@ -243,17 +237,32 @@ export default class MewConnectInitiatorV2 extends MewConnectCommon {
243237
// show new QRcode
244238
}
245239
});
246-
247-
this.socketOn(this.signals.initiated, this.initiated.bind(this)); // response
248240
this.socketOn(this.signals.disconnected, data => {
249241
// this.beginRtcSequence(stunServers);
242+
this.emit('socketDisconnected')
250243
}); // response
251244

245+
this.socketOn(this.signals.initiated, this.initiated.bind(this)); // response
246+
247+
252248
this.socketOn(this.signals.confirmation, data => {
253-
this.beginRtcSequence(stunServers);
249+
if(data !== '' && data){
250+
data.iceServers.map(obj => {
251+
const newObject = {};
252+
delete Object.assign(newObject, obj, { ['urls']: obj['url'] })[
253+
'url'
254+
];
255+
return newObject;
256+
})
257+
this.beginRtcSequence(data.iceServers);
258+
} else {
259+
this.beginRtcSequence(stunServers);
260+
}
261+
254262
});
255263
// this.signals.answer
256264
this.socketOn('answer', this.recieveAnswer.bind(this));
265+
// TODO: check if these failure signals are even being used in V2
257266
this.socketOn(
258267
this.signals.confirmationFailedBusy,
259268
this.busyFailure.bind(this)
@@ -276,7 +285,7 @@ export default class MewConnectInitiatorV2 extends MewConnectCommon {
276285
);
277286
this.socketOn(this.signals.turnToken, this.beginTurn.bind(this));
278287
} catch (e) {
279-
debug('initiatorConnect error:', e);
288+
debug('setupListeners error:', e);
280289
}
281290
}
282291

@@ -342,7 +351,7 @@ export default class MewConnectInitiatorV2 extends MewConnectCommon {
342351
debug('beginRtcSequence ');
343352
debug('sendOffer', stunServers);
344353
this.iceServers = null;
345-
this.stunServers = stunServers;
354+
this.stunServers = stunServers !== '' ? this.stunServers : stunServers;
346355
const options = {
347356
servers: this.stunServers,
348357
webRtcConfig: {
@@ -549,7 +558,7 @@ export default class MewConnectInitiatorV2 extends MewConnectCommon {
549558
this.rtcSend(JSON.stringify({ type, data: msg }));
550559
}
551560

552-
async rtcSend(arg) {
561+
/* async rtcSend(arg) {
553562
// if (this.isAlive()) {
554563
// let encryptedSend;
555564
// if (typeof arg === 'string') {
@@ -564,7 +573,7 @@ export default class MewConnectInitiatorV2 extends MewConnectCommon {
564573
// this.uiCommunicator(this.lifeCycle.attemptedDisconnectedSend);
565574
// return false;
566575
// }
567-
}
576+
}*/
568577

569578
rtcDestroy() {
570579
if (this.active) {

0 commit comments

Comments
 (0)
Please sign in to comment.