Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@pbkit/wrp

Package Overview
Dependencies
Maintainers
2
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@pbkit/wrp - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

glue/parent.d.ts

2

glue/child-window.d.ts
import { Closer, Socket } from "../socket";
export interface CreateChildWindowSocketConfig {
child: Window;
childOrigin: string;
childWindowOrigin: string;
onClosed?: () => void;
}
export declare function createChildWindowSocket(config: CreateChildWindowSocketConfig): Promise<Closer & Socket>;

@@ -8,4 +8,4 @@ "use strict";

async function createChildWindowSocket(config) {
const { child, childOrigin, onClosed } = config;
await handshake(child, childOrigin);
const { child, childWindowOrigin, onClosed } = config;
await handshake(child, childWindowOrigin);
const healthcheckId = setInterval(healthcheck, 100);

@@ -19,3 +19,3 @@ const glue = (0, index_1.createGlue)();

target: child,
targetOrigin: childOrigin,
targetOrigin: childWindowOrigin,
payload: data,

@@ -41,3 +41,3 @@ });

// wait syn -> send syn-ack -> wait ack
async function handshake(child, childOrigin) {
async function handshake(child, childWindowOrigin) {
let synAcked = false;

@@ -88,3 +88,3 @@ const wait = (0, observer_1.defer)();

target: child,
targetOrigin: childOrigin,
targetOrigin: childWindowOrigin,
payload: "syn",

@@ -91,0 +91,0 @@ });

@@ -11,3 +11,3 @@ "use strict";

child: iframeWindow,
childOrigin: iframeOrigin,
childWindowOrigin: iframeOrigin,
onClosed,

@@ -14,0 +14,0 @@ });

import { Closer, Socket } from "../socket";
export interface CreateParentWindowSocketConfig {
parent?: Window | null;
parentOrigin: string;
parentWindowOrigin: string;
onClosed?: () => void;
}
export declare function createParentWindowSocket(config: CreateParentWindowSocketConfig): Promise<Closer & Socket>;

@@ -7,3 +7,3 @@ "use strict";

async function createParentWindowSocket(config) {
const { parent = globalThis.parent, parentOrigin, onClosed } = config;
const { parent = globalThis.parent, parentWindowOrigin, onClosed } = config;
if (!(parent === null || parent === void 0 ? void 0 : parent.postMessage))

@@ -25,3 +25,3 @@ throw new Error("There is no parent window.");

target: parent,
targetOrigin: parentOrigin,
targetOrigin: parentWindowOrigin,
payload: data,

@@ -45,3 +45,3 @@ });

target: parent,
targetOrigin: parentOrigin,
targetOrigin: parentWindowOrigin,
payload: "syn",

@@ -56,3 +56,3 @@ });

target: parent,
targetOrigin: parentOrigin,
targetOrigin: parentWindowOrigin,
payload: "ack",

@@ -59,0 +59,0 @@ });

import { PrimitiveAtom } from "jotai";
import { WrpAtomSet } from "./index";
import { PrimitiveSocketAtom, WrpAtomSet } from "./index";
import { Socket } from "../socket";
import { WrpChannel } from "../channel";
import { UseWrpIframeSocketResult } from "../react/useWrpIframeSocket";
export declare function useIframeWrpSocketAtomUpdateEffect(socketAtom: PrimitiveSocketAtom): UseWrpIframeSocketResult;
export declare function useIframeWrpAtomSetUpdateEffect(primitiveWrpAtomSetAtom: PrimitiveAtom<WrpAtomSet>, createWrpChannel?: (socket: Socket) => WrpChannel): UseWrpIframeSocketResult;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useIframeWrpAtomSetUpdateEffect = void 0;
exports.useIframeWrpAtomSetUpdateEffect = exports.useIframeWrpSocketAtomUpdateEffect = void 0;
const react_1 = require("react");

@@ -9,2 +9,14 @@ const jotai_1 = require("jotai");

const useWrpIframeSocket_1 = require("../react/useWrpIframeSocket");
function useIframeWrpSocketAtomUpdateEffect(socketAtom) {
const setSocket = (0, jotai_1.useSetAtom)(socketAtom);
const useWrpIframeSocketResult = (0, useWrpIframeSocket_1.default)();
const { socket } = useWrpIframeSocketResult;
(0, react_1.useEffect)(() => {
if (!socket)
return;
setSocket(socket);
}, [socket]);
return useWrpIframeSocketResult;
}
exports.useIframeWrpSocketAtomUpdateEffect = useIframeWrpSocketAtomUpdateEffect;
function useIframeWrpAtomSetUpdateEffect(primitiveWrpAtomSetAtom, createWrpChannel = channel_1.createWrpChannel) {

@@ -11,0 +23,0 @@ const setIframeAtomSet = (0, jotai_1.useSetAtom)(primitiveWrpAtomSetAtom);

@@ -1,2 +0,2 @@

import { Atom } from "jotai";
import { Atom, PrimitiveAtom } from "jotai";
import type { RpcClientImpl } from "@pbkit/runtime/rpc";

@@ -6,6 +6,8 @@ import { Socket } from "../socket";

import { WrpGuest } from "../guest";
export declare type SocketAtom = Atom<Promise<Socket | undefined>>;
export declare type SocketAtom = PrimitiveSocketAtom | AsyncSocketAtom;
export declare type ChannelAtom = Atom<WrpChannel | undefined>;
export declare type GuestAtom = Atom<Promise<WrpGuest> | undefined>;
export declare type ClientImplAtom = Atom<RpcClientImpl | undefined>;
export declare type PrimitiveSocketAtom = PrimitiveAtom<Socket | undefined>;
export declare type AsyncSocketAtom = Atom<Promise<Socket | undefined>>;
export interface WrpAtomSet {

@@ -12,0 +14,0 @@ channelAtom: ChannelAtom;

@@ -8,3 +8,3 @@ "use strict";

const client_1 = require("../rpc/client");
const guest_1 = require("../guest");
const tee_1 = require("../tee");
function createWrpAtomSet(socketAtom) {

@@ -25,28 +25,3 @@ const channelAtom = (0, jotai_1.atom)((get) => {

return;
const listeners = [];
const guest = (0, guest_1.createWrpGuest)({
channel: {
...sourceChannel,
async *listen() {
for await (const message of sourceChannel.listen()) {
yield message;
for (const listener of listeners)
listener(message);
listeners.length = 0;
}
},
},
});
const channel = {
...sourceChannel,
async *listen() {
while (true) {
const message = await new Promise((resolve) => listeners.push(resolve));
if (!message)
break;
yield message;
}
},
};
return { channel, guest };
return (0, tee_1.default)(sourceChannel);
});

@@ -53,0 +28,0 @@ const channelAtom = (0, utils_1.selectAtom)(channelAndGuestAtom, (cag) => cag === null || cag === void 0 ? void 0 : cag.channel);

import type { RpcClientImpl } from "@pbkit/runtime/rpc";
import { WrpChannel } from "../channel";
import { WrpGuest } from "../guest";
import { ChannelAtom, ClientImplAtom, GuestAtom, SocketAtom } from "./index";
export declare const socketAtom: SocketAtom;
import { ChannelAtom, ClientImplAtom, GuestAtom, PrimitiveSocketAtom } from "./index";
/**
* Use it on root of your react application
*/
export declare function useInitParentSocketEffect(): void;
export declare const socketAtom: PrimitiveSocketAtom;
export declare const channelAtom: ChannelAtom;

@@ -7,0 +11,0 @@ export declare function useChannel(): WrpChannel | undefined;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useClientImpl = exports.clientImplAtom = exports.useGuest = exports.guestAtom = exports.useChannel = exports.channelAtom = exports.socketAtom = void 0;
exports.useClientImpl = exports.clientImplAtom = exports.useGuest = exports.guestAtom = exports.useChannel = exports.channelAtom = exports.socketAtom = exports.useInitParentSocketEffect = void 0;
const jotai_1 = require("jotai");
const ios_1 = require("../glue/ios");
const android_1 = require("../glue/android");
const parent_window_1 = require("../glue/parent-window");
const useOnceEffect_1 = require("../react/useOnceEffect");
const parent_1 = require("../glue/parent");
const index_1 = require("./index");
exports.socketAtom = (0, jotai_1.atom)(async () => {
return await Promise.any([
(0, android_1.createAndroidSocket)(),
(0, ios_1.createIosSocket)(),
(0, parent_window_1.createParentWindowSocket)({
parentWindowOrigin: "*",
}),
(0, parent_window_1.createParentWindowSocket)({
parent: globalThis.opener,
parentWindowOrigin: "*",
}),
]).catch(() => undefined);
});
/**
* Use it on root of your react application
*/
function useInitParentSocketEffect() {
const setSocket = (0, jotai_1.useSetAtom)(exports.socketAtom);
(0, useOnceEffect_1.default)(() => (0, parent_1.subscribeParentSocket)(setSocket));
}
exports.useInitParentSocketEffect = useInitParentSocketEffect;
exports.socketAtom = (0, jotai_1.atom)(undefined);
const wrpAtomSet = (0, index_1.createWrpAtomSet)(exports.socketAtom);

@@ -23,0 +18,0 @@ exports.channelAtom = wrpAtomSet.channelAtom;

{
"name": "@pbkit/wrp",
"version": "0.1.0",
"version": "0.1.1",
"author": "JongChan Choi <jong@chan.moe>",

@@ -5,0 +5,0 @@ "license": "(MIT OR Apache-2.0)",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc