Skip to content

Commit ede2119

Browse files
committed
Fixes for PR webtorrent#128
1 parent 5d4cf75 commit ede2119

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

client.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -87,24 +87,25 @@ function Client (peerId, port, torrent, opts) {
8787
} else if (protocol === 'udp:' && typeof UDPTracker === 'function') {
8888
return new UDPTracker(self, announceUrl)
8989
} else if ((protocol === 'ws:' || protocol === 'wss:') && webrtcSupport) {
90-
// Don't try to add http tracker on an https website
91-
if (protocol === 'ws:' && location && location.protocol && location.protocol === 'https:') {
92-
process.nextTick(function () {
93-
var err = new Error('unsupported http tracker on https: ' + announceUrl)
94-
self.emit('warning', err)
95-
})
90+
// Skip ws:// trackers on https:// sites because they throw SecurityError
91+
if (protocol === 'ws:' && typeof window !== 'undefined' &&
92+
window.location.protocol === 'https:') {
93+
nextTickWarn(new Error('Unsupported tracker protocol: ' + announceUrl))
9694
return null
9795
}
9896
return new WebSocketTracker(self, announceUrl)
9997
} else {
100-
process.nextTick(function () {
101-
var err = new Error('unsupported tracker protocol for ' + announceUrl)
102-
self.emit('warning', err)
103-
})
98+
nextTickWarn(new Error('Unsupported tracker protocol: ' + announceUrl))
99+
return null
104100
}
105-
return null
106101
})
107102
.filter(Boolean)
103+
104+
function nextTickWarn (err) {
105+
process.nextTick(function () {
106+
self.emit('warning', err)
107+
})
108+
}
108109
}
109110

110111
/**

0 commit comments

Comments
 (0)