Skip to content

Commit

Permalink
optim/compat begin: do not execute ssl tests in browser.
Browse files Browse the repository at this point in the history
  • Loading branch information
dskvr committed Jan 16, 2024
1 parent f8b848c commit e68b574
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
27 changes: 24 additions & 3 deletions packages/nocap/src/classes/Base.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ export default class {
* @returns {Promise<*>} - The result of the check
*/
async _check(key){
if(!this.can_check(key)) return
this.logger.debug(`${key}: check()`)
this.defaultAdapters()
const precheck = await this.start(key).catch( err => this.logger.debug(err) )
Expand All @@ -126,6 +127,14 @@ export default class {
return result
}

can_check(key){
if(this.is_browser() && key === 'ssl') {
this.logger.err('Cannot check SSL from browser')
return
}
return true
}

/**
* maybeTimeoutReject
* Creates a reject function for a timeout scenario
Expand Down Expand Up @@ -986,8 +995,20 @@ export default class {
* @param {Error} error - The error to throw
* @returns {Promise<*>} - A promise that rejects with the provided error
*/
throw(error){
return Promise.reject(error);
}
throw(error){
return Promise.reject(error);
}

/**
* is_browser
* Returns true if in a browser environment
*
* @private
* @returns {boolean}
*/
is_browser(){
(typeof window !== 'undefined' && typeof document !== 'undefined')
}

}

2 changes: 2 additions & 0 deletions packages/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ let { DAEMON_PUBKEY } = process.env;
DAEMON_PUBKEY = DAEMON_PUBKEY? DAEMON_PUBKEY : 'WARNING_DAEMON_PUBKEY_UNSET';
export { DAEMON_PUBKEY }

export const isBrowser = () => (typeof window !== 'undefined' && typeof document !== 'undefined')

export const parseRelayNetwork = network.parseRelayNetwork
export const relaysSerializedByNetwork = network.relaysSerializedByNetwork

Expand Down

0 comments on commit e68b574

Please sign in to comment.