···6677 if (typeof window !== 'undefined' && window.PATCHBAY_REMOTE) {
88 remote = window.PATCHBAY_REMOTE
99-1010- if (typeof localStorage !== 'undefined') {
1111- try { localStorage.remote = remote } catch (e) {}
1212- }
1313- } else if (typeof localStorage !== 'undefined') {
1414- try {
1515- remote = localStorage.remote || null
1616- } catch (e) {
1717- remote = null
1818- }
199 }
20102111 return remote
···2515 if (!remote || typeof window === 'undefined' || !window.location) return remote
26162717 try {
2828- var parts = remote.split('~')
2929- var base = parts[0]
3030- var suffix = parts.length > 1 ? '~' + parts.slice(1).join('~') : ''
1818+ var shsIndex = remote.indexOf('~shs:')
1919+ if (shsIndex === -1) return remote
31203232- var u = URL.parse(base)
3333-3434- if (!u || !u.protocol || !/^wss?:$/.test(u.protocol)) return remote
3535-3636- // Only rewrite when the remote thinks it's localhost
3737- if (u.hostname !== 'localhost' && u.hostname !== '127.0.0.1') return remote
3838-2121+ var key = remote.substring(shsIndex + 5)
3922 var loc = window.location
40234141- // Use the page's hostname, keep the original port
4242- u.protocol = loc.protocol === 'https:' ? 'wss:' : 'ws:'
4343- u.hostname = loc.hostname
4444- if (!u.port) {
4545- u.port = loc.port || (loc.protocol === 'https:' ? '443' : '80')
4646- }
2424+ var proto = loc.protocol === 'https:' ? 'wss' : 'ws'
2525+ var host = loc.host || (loc.hostname + (loc.port ? ':' + loc.port : ''))
47264848- var formatted = URL.format(u)
4949- if (formatted.charAt(formatted.length - 1) === '/')
5050- formatted = formatted.slice(0, -1)
5151-5252- return formatted + suffix
2727+ return proto + '://' + host + '~shs:' + key
5328 } catch (e) {
5429 return remote
5530 }
+1-11
patchbay/modules_basic/invite.js
···6060 function next () {
6161 onProgress('following...')
62626363- //remove the seed from the shs address.
6464- //then it's correct address.
6565- //this should make the browser connect to this as remote.
6666- //we don't want to do this if when using this locally, though.
6767- if(process.title === 'browser')
6868- localStorage.remote = data.remote
6969-7063 api.sbot_publish({
7164 type: 'contact',
7265 contact: data.key,
···115108 })
116109 }
117110118118- // If we are in the browser,
119119- // and do not already have a remote set, automatically trigger the invite.
120120- if(process.title == 'browser' && !localStorage.remote) attempt()
111111+ // If we are in the browser, the user can click "accept" to trigger the invite.
121112122113 return div
123114 }
124115 }
125116}
126126-
-10
patchbay/modules_extra/key.js
···3434 }
35353636 var importKey = h('textarea', {placeholder: 'import an existing public/private key', name: 'textarea'})
3737- var importRemote = h('textarea', {placeholder: 'import an existing remote', name: 'textarea'})
3837 var content = h('div.column.scroller__content')
3938 var div = h('div.column.scroller',
4039 {style: {'overflow':'auto'}},
···4847 localStorage['browser/.ssb/secret'] = importKey.value.replace(/\s+/g, ' ')
4948 alert('Your public/private key has been updated')
5049 e.preventDefault()
5151- }}, 'Import'),
5252- h('p', {innerHTML: 'Your ws remote is: <pre>' + localStorage.remote + '</pre>'}),
5353- h('form',
5454- importRemote,
5555- h('button', {onclick: function (e){
5656- localStorage.remote = importRemote.value
5757- alert('Your websocket remote has been updated')
5858- e.preventDefault()
5950 }}, 'Import')
6060- )
6151 )
6252 )
6353 )