Skip to content

Commit

Permalink
allow mirror network to be unimplemented
Browse files Browse the repository at this point in the history
  • Loading branch information
mehcode committed Nov 12, 2020
1 parent e75bd2a commit aa26da4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/client/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,10 @@ export default class Client {

/**
* @abstract
* @returns {(address: string) => MirrorChannelT}
* @returns {((address: string) => MirrorChannelT)?}
*/
_createMirrorNetworkChannel() {
throw new Error("not implemented");
// throw new Error("not implemented");
return null;
}
}
14 changes: 12 additions & 2 deletions src/client/MirrorNetwork.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import MirrorNode from "../MirrorNode.js";
*/
export default class MirrorNetwork {
/**
* @param {(address: string) => MirrorChannel} channelInitFunction
* @param {((address: string) => MirrorChannel)?} channelInitFunction
*/
constructor(channelInitFunction) {
/**
Expand All @@ -33,14 +33,20 @@ export default class MirrorNetwork {

this.index = 0;

/** @type {(address: string) => MirrorChannel} */
/** @type {((address: string) => MirrorChannel)?} */
this._channelInitFunction = channelInitFunction;
}

/**
* @param {string[]} network
*/
setMirrorNetwork(network) {
if (this._channelInitFunction == null) {
// silently fail on client boot if mirror network is not
// supported
return;
}

this.close();
this.network = network;

Expand All @@ -58,6 +64,10 @@ export default class MirrorNetwork {
* @returns {MirrorNode}
*/
getNextMirrorNode() {
if (this._channelInitFunction == null) {
throw new Error("mirror network not supported on browser");
}

const node = this.network[this.index];
this.index = (this.index + 1) % this.network.length;
return /** @type {MirrorNode} */ (this.networkNodes.get(node));
Expand Down

0 comments on commit aa26da4

Please sign in to comment.