UNPKG

@metamask/snaps-rpc-methods

Version:
39 lines 1.35 kB
import { providerErrors } from "@metamask/rpc-errors"; import { SnapEndowments } from "../endowments/index.mjs"; const hookNames = { hasPermission: true, getWebSockets: true, }; /** * Handler for the `snap_getWebSockets` method. */ export const 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(SnapEndowments.NetworkAccess)) { return end(providerErrors.unauthorized()); } try { res.result = getWebSockets(); } catch (error) { return end(error); } return end(); } //# sourceMappingURL=getWebSockets.mjs.map