Skip to content

Commit

Permalink
add multiple default stun server address
Browse files Browse the repository at this point in the history
Signed-off-by: Yilun <zyl.skysniper@gmail.com>
  • Loading branch information
yilunzhang committed May 8, 2024
1 parent a79bfff commit 595f167
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 15 deletions.
6 changes: 3 additions & 3 deletions dist/nkn.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const Action = {
* @param {string} [options.rpcServerAddr='https://mainnet-rpc-node-0001.nkn.org/mainnet/api/wallet'] - RPC server address used to join the network.
* @param {boolean} [options.webrtc=undefined] - Force to use/not use web rtc if defined. By default, webrtc is used only in https location when tls is undefined.
* @param {boolean} [options.tls=undefined] - Force to use ws or wss if defined. This option is only used when webrtc is not used. Default is true in https location, otherwise false.
* @param {string} [options.stunServerAddr='stun:stun.l.google.com:19302'] - Stun server address for webrtc.
* @param {string} [options.stunServerAddr=["stun:stun.l.google.com:19302","stun:stun.cloudflare.com:3478","stun:stunserver.stunprotocol.org:3478"]] - Stun server address for webrtc.
* @param {boolean|function} [options.worker=false] - Whether to use web workers (if available) to compute signatures. Can also be a function that returns web worker. Typically you only need to set it to a function if you import nkn-sdk as a module and are NOT using browserify or webpack worker-loader to bundle js file. The worker file is located at `lib/worker/webpack.worker.js`.
*/

Expand Down Expand Up @@ -1246,8 +1246,8 @@ const defaultOptions = {
msgHoldingSeconds: 0,
encrypt: true,
rpcServerAddr: "https://mainnet-rpc-node-0001.nkn.org/mainnet/api/wallet",
worker: false,
stunServerAddr: "stun:stun.l.google.com:19302"
stunServerAddr: ["stun:stun.l.google.com:19302", "stun:stun.cloudflare.com:3478", "stun:stunserver.stunprotocol.org:3478"],
worker: false
};
exports.defaultOptions = defaultOptions;
const defaultPublishOptions = {
Expand Down
2 changes: 1 addition & 1 deletion dist/nkn.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1019,7 +1019,7 @@ <h3 class='fl m0' id='client'>
<tr>
<td class='break-word'><span class='code bold'>options.stunServerAddr</span> <code class='quiet'><a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String">string</a></code>

(default <code>&#39;stun:stun.l.google.com:19302&#39;</code>)
(default <code>[&quot;stun:stun.l.google.com:19302&quot;,&quot;stun:stun.cloudflare.com:3478&quot;,&quot;stun:stunserver.stunprotocol.org:3478&quot;]</code>)
</td>
<td class='break-word'><span>Stun server address for webrtc.
</span></td>
Expand Down
2 changes: 1 addition & 1 deletion lib/client/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const Action = {
* @param {string} [options.rpcServerAddr='https://mainnet-rpc-node-0001.nkn.org/mainnet/api/wallet'] - RPC server address used to join the network.
* @param {boolean} [options.webrtc=undefined] - Force to use/not use web rtc if defined. By default, webrtc is used only in https location when tls is undefined.
* @param {boolean} [options.tls=undefined] - Force to use ws or wss if defined. This option is only used when webrtc is not used. Default is true in https location, otherwise false.
* @param {string} [options.stunServerAddr='stun:stun.l.google.com:19302'] - Stun server address for webrtc.
* @param {string} [options.stunServerAddr=["stun:stun.l.google.com:19302","stun:stun.cloudflare.com:3478","stun:stunserver.stunprotocol.org:3478"]] - Stun server address for webrtc.
* @param {boolean|function} [options.worker=false] - Whether to use web workers (if available) to compute signatures. Can also be a function that returns web worker. Typically you only need to set it to a function if you import nkn-sdk as a module and are NOT using browserify or webpack worker-loader to bundle js file. The worker file is located at `lib/worker/webpack.worker.js`.
*/

Expand Down
4 changes: 2 additions & 2 deletions lib/client/consts.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ const defaultOptions = {
msgHoldingSeconds: 0,
encrypt: true,
rpcServerAddr: "https://mainnet-rpc-node-0001.nkn.org/mainnet/api/wallet",
worker: false,
stunServerAddr: "stun:stun.l.google.com:19302"
stunServerAddr: ["stun:stun.l.google.com:19302", "stun:stun.cloudflare.com:3478", "stun:stunserver.stunprotocol.org:3478"],
worker: false
};
exports.defaultOptions = defaultOptions;
const defaultPublishOptions = {
Expand Down
6 changes: 3 additions & 3 deletions src/client/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const Action = {
* @param {string} [options.rpcServerAddr='https://mainnet-rpc-node-0001.nkn.org/mainnet/api/wallet'] - RPC server address used to join the network.
* @param {boolean} [options.webrtc=undefined] - Force to use/not use web rtc if defined. By default, webrtc is used only in https location when tls is undefined.
* @param {boolean} [options.tls=undefined] - Force to use ws or wss if defined. This option is only used when webrtc is not used. Default is true in https location, otherwise false.
* @param {string} [options.stunServerAddr='stun:stun.l.google.com:19302'] - Stun server address for webrtc.
* @param {string} [options.stunServerAddr=["stun:stun.l.google.com:19302","stun:stun.cloudflare.com:3478","stun:stunserver.stunprotocol.org:3478"]] - Stun server address for webrtc.
* @param {boolean|function} [options.worker=false] - Whether to use web workers (if available) to compute signatures. Can also be a function that returns web worker. Typically you only need to set it to a function if you import nkn-sdk as a module and are NOT using browserify or webpack worker-loader to bundle js file. The worker file is located at `lib/worker/webpack.worker.js`.
*/
export default class Client {
Expand All @@ -51,7 +51,7 @@ export default class Client {
rpcServerAddr: string,
tls?: boolean,
webrtc?: boolean,
stunServerAddr?: string,
stunServerAddr?: string | Array<string>,
worker: boolean | (() => Worker | Promise<Worker>),
};
key: common.Key;
Expand Down Expand Up @@ -107,7 +107,7 @@ export default class Client {
rpcServerAddr?: string,
tls?: boolean,
worker?: boolean | (() => Worker | Promise<Worker>),
stunServerAddr?: string,
stunServerAddr?: string | Array<string>,
webrtc?: boolean,
} = {},
) {
Expand Down
6 changes: 5 additions & 1 deletion src/client/consts.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@ export const defaultOptions = {
msgHoldingSeconds: 0,
encrypt: true,
rpcServerAddr: "https://mainnet-rpc-node-0001.nkn.org/mainnet/api/wallet",
stunServerAddr: [
"stun:stun.l.google.com:19302",
"stun:stun.cloudflare.com:3478",
"stun:stunserver.stunprotocol.org:3478",
],
worker: false,
stunServerAddr: "stun:stun.l.google.com:19302",
};

export const defaultPublishOptions = {
Expand Down
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2955,9 +2955,9 @@ camelcase@^5.0.0, camelcase@^5.3.1:
integrity sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg==

caniuse-lite@^1.0.30001219, caniuse-lite@^1.0.30001286:
version "1.0.30001473"
resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001473.tgz"
integrity sha512-ewDad7+D2vlyy+E4UJuVfiBsU69IL+8oVmTuZnH5Q6CIUbxNfI50uVpRHbUPDD6SUaN2o0Lh4DhTrvLG/Tn1yg==
version "1.0.30001616"
resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001616.tgz"
integrity sha512-RHVYKov7IcdNjVHJFNY/78RdG4oGVjbayxv8u5IO74Wv7Hlq4PnJE6mo/OjFijjVFNy5ijnCt6H3IIo4t+wfEw==

capture-exit@^2.0.0:
version "2.0.0"
Expand Down

0 comments on commit 595f167

Please sign in to comment.