UNPKG

@simplito/privmx-webendpoint

Version:

PrivMX Web Endpoint library

76 lines (73 loc) 3.24 kB
"use strict"; /*! PrivMX Web Endpoint. Copyright © 2024 Simplito sp. z o.o. This file is part of the PrivMX Platform (https://privmx.dev). This software is Licensed under the PrivMX Free License. See the License for the specific language governing permissions and limitations under the License. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.ConnectionNative = void 0; const BaseNative_1 = require("./BaseNative"); class ConnectionNative extends BaseNative_1.BaseNative { lastConnectionId = -1; userVerifierPtr = -1; async newApi(_connectionPtr) { throw new Error("Use the newConnection() - specialized version of method instead."); } async deleteApi(ptr) { await this.runAsync((taskId) => this.api.lib.Connection_deleteConnection(taskId, ptr)); this.deleteApiRef(); } async newConnection() { return this.runAsync((taskId) => this.api.lib.Connection_newConnection(taskId)); } async deleteConnection(ptr) { await this.runAsync((taskId) => this.api.lib.Connection_deleteConnection(taskId, ptr)); this.deleteApiRef(); } async connect(ptr, args) { await this.runAsync((taskId) => this.api.lib.Connection_connect(taskId, ptr, args)); await this.getConnectionId(ptr, []); } async connectPublic(ptr, args) { return this.runAsync((taskId) => this.api.lib.Connection_connectPublic(taskId, ptr, args)); } async getConnectionId(ptr, args) { if (this.lastConnectionId < 0) { this.lastConnectionId = await this.runAsync((taskId) => this.api.lib.Connection_getConnectionId(taskId, ptr, args)); } return this.lastConnectionId; } async listContexts(ptr, args) { return this.runAsync((taskId) => this.api.lib.Connection_listContexts(taskId, ptr, args)); } async getContextUsers(ptr, args) { return this.runAsync((taskId) => this.api.lib.Connection_getContextUsers(taskId, ptr, args)); } async disconnect(ptr, args) { await this.runAsync((taskId) => this.api.lib.Connection_disconnect(taskId, ptr, args)); } async setUserVerifier(_ptr, args) { if (this.userVerifierPtr > -1) { await this.deleteUserVerifierInterface(this.userVerifierPtr); this.userVerifierPtr = -1; } const [connectionPtr, verifierInterface] = args; window.userVierifier_verify = async (request) => { if (verifierInterface && typeof verifierInterface.verify === "function") { return verifierInterface.verify(request); } throw new Error("Call on UserVerifierInterface with missing implementation"); }; this.userVerifierPtr = await this.runAsync((taskId) => this.api.lib.Connection_newUserVerifierInterface(taskId, connectionPtr)); } async newUserVerifierInterface(connectionPtr) { return this.runAsync((taskId) => this.api.lib.Connection_newUserVerifierInterface(taskId, connectionPtr)); } async deleteUserVerifierInterface(ptr) { await this.runAsync((taskId) => this.api.lib.Connection_deleteUserVerifierInterface(taskId, ptr)); } } exports.ConnectionNative = ConnectionNative;