@pbkit/wrp
Advanced tools
Comparing version 0.1.3 to 0.1.4
@@ -39,3 +39,3 @@ "use strict"; | ||
function messageHandler(e) { | ||
if (e.source !== parent) | ||
if (e.source !== child) | ||
return; | ||
@@ -42,0 +42,0 @@ if (!(0, web_1.isGlueEvent)(e)) |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createParentWindowSocket = void 0; | ||
const observer_1 = require("@pbkit/runtime/async/observer"); | ||
const index_1 = require("./index"); | ||
@@ -12,3 +13,4 @@ const web_1 = require("./misc/web"); | ||
throw new Error("Invalid parent window."); | ||
let handshakeIsDone = false; | ||
const wait = (0, observer_1.defer)(); | ||
let acked = false; | ||
globalThis.addEventListener("message", messageHandler); | ||
@@ -19,2 +21,3 @@ globalThis.addEventListener("message", handshakeHandler); | ||
syn(); | ||
await wait; | ||
return { | ||
@@ -41,2 +44,3 @@ read: glue.read, | ||
onClosed === null || onClosed === void 0 ? void 0 : onClosed(); | ||
wait.reject(new Error("Connection closed.")); | ||
} | ||
@@ -53,3 +57,3 @@ function syn() { | ||
function ack() { | ||
handshakeIsDone = true; | ||
acked = true; | ||
const success = (0, web_1.postGlueHandshakeMessage)({ | ||
@@ -60,3 +64,5 @@ target: parent, | ||
}); | ||
if (!success) | ||
if (success) | ||
wait.resolve(); | ||
else | ||
close(); | ||
@@ -79,3 +85,3 @@ } | ||
if (payload === "syn-ack") { | ||
if (handshakeIsDone) | ||
if (acked) | ||
close(); | ||
@@ -82,0 +88,0 @@ else |
{ | ||
"name": "@pbkit/wrp", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"author": "JongChan Choi <jong@chan.moe>", | ||
@@ -5,0 +5,0 @@ "license": "(MIT OR Apache-2.0)", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
132174
72
2815