UNPKG

@metamask/snaps-rpc-methods

Version:
42 lines 1.49 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getWebSocketsHandler = void 0; const rpc_errors_1 = require("@metamask/rpc-errors"); const endowments_1 = require("../endowments/index.cjs"); const hookNames = { hasPermission: true, getWebSockets: true, }; /** * Handler for the `snap_getWebSockets` method. */ exports.getWebSocketsHandler = { methodNames: ['snap_getWebSockets'], implementation: getWebSocketsImplementation, hookNames, }; /** * The `snap_getWebSockets` method implementation. * * @param _req - The JSON-RPC request object. Not used by this function. * @param res - The JSON-RPC response object. * @param _next - The `json-rpc-engine` "next" callback. Not used by this function. * @param end - The `json-rpc-engine` "end" callback. * @param hooks - The RPC method hooks. * @param hooks.hasPermission - The function to check if a snap has the `endowment:network-access` permission. * @param hooks.getWebSockets - The function to get the connected WebSockets for the origin. * @returns Nothing. */ function getWebSocketsImplementation(_req, res, _next, end, { hasPermission, getWebSockets }) { if (!hasPermission(endowments_1.SnapEndowments.NetworkAccess)) { return end(rpc_errors_1.providerErrors.unauthorized()); } try { res.result = getWebSockets(); } catch (error) { return end(error); } return end(); } //# sourceMappingURL=getWebSockets.cjs.map