* other value will be changed automatically.
*/
export class Rpc {
- #u: URL
- #n?: string
+ #apiUrl: URL
+ #apiKeyName?: string
+ #wsUrl?: URL
+
+ get apiUrl (): URL { return this.#apiUrl }
+ get apiKeyName (): string | undefined { return this.#apiKeyName }
+ get websocketUrl (): URL | undefined { return this.#wsUrl }
/**
- * @param {(string|URL)} url
+ * @param {(string | URL)} url
* @param {string} [apiKeyName]
*/
- constructor (url: string | URL, apiKeyName?: string) {
- this.#u = new URL(url)
- this.#u.protocol = 'https:'
- this.#n = apiKeyName
+ constructor (apiUrl: string | URL, apiKeyName?: string, websocketUrl?: string | URL) {
+ this.#apiUrl = new URL(apiUrl)
+ this.#apiUrl.protocol = 'https:'
+ this.#apiKeyName = apiKeyName
+ if (websocketUrl != null) {
+ this.#wsUrl = new URL(websocketUrl)
+ this.#wsUrl.protocol = 'wss:'
+ }
}
/**
this.#validate(action)
const headers: { [key: string]: string } = {}
headers['Content-Type'] = 'application/json'
- if (this.#n && process?.env?.LIBNEMO_RPC_API_KEY) {
- headers[this.#n] = process.env.LIBNEMO_RPC_API_KEY
+ if (this.#apiKeyName && process?.env?.LIBNEMO_RPC_API_KEY) {
+ headers[this.#apiKeyName] = process.env.LIBNEMO_RPC_API_KEY
}
data ??= {}
.replaceAll('\\', '\\u005c')
const aborter = new AbortController()
- const req = new Request(this.#u, {
+ const req = new Request(this.#apiUrl, {
signal: aborter.signal,
method: 'POST',
headers,