Added check for active pair in onopen

Because the timeout makes the pair inactive, we should check for this
state in onopen before connecting to the client. Updated tests to set
the proxy pair to active before testing onopen. Also removed a
redundant statement.
This commit is contained in:
Cecylia Bocovich 2019-08-24 19:02:54 -04:00
parent 8a5941daab
commit 16a1b69823
3 changed files with 4 additions and 2 deletions

View file

@ -85,6 +85,9 @@ class ProxyPair {
prepareDataChannel(channel) { prepareDataChannel(channel) {
channel.onopen = () => { channel.onopen = () => {
log('WebRTC DataChannel opened!'); log('WebRTC DataChannel opened!');
if (!this.active) {
return
}
this.running = true; this.running = true;
snowflake.state = Snowflake.MODE.WEBRTC_READY; snowflake.state = Snowflake.MODE.WEBRTC_READY;
snowflake.ui.setActive(true); snowflake.ui.setActive(true);

View file

@ -86,8 +86,6 @@ class Snowflake {
return pair.active = false; return pair.active = false;
} }
}), 20000); // 20 second timeout }), 20000); // 20 second timeout
} else {
return pair.active = false;
} }
}, function() { }, function() {
return pair.active = false; return pair.active = false;

View file

@ -100,6 +100,7 @@ describe('ProxyPair', function() {
it('connects to the relay once datachannel opens', function() { it('connects to the relay once datachannel opens', function() {
spyOn(pp, 'connectRelay'); spyOn(pp, 'connectRelay');
pp.active = true;
pp.client.onopen(); pp.client.onopen();
expect(pp.connectRelay).toHaveBeenCalled(); expect(pp.connectRelay).toHaveBeenCalled();
}); });