47 lines
1.5 KiB
TypeScript
47 lines
1.5 KiB
TypeScript
// Metro module 10635 (f10636).
|
|
import { TransportTypes } from "../Constants";
|
|
import { RPCCloseCodes } from "../../../Constants";
|
|
import BaseSocket from "./BaseSocket";
|
|
import RPCError from "../RPCError";
|
|
import RPCOpcodes from "../RPCOpcodes";
|
|
class WindowProxySocket extends BaseSocket {
|
|
constructor({ origin, postMessageToRPCClient, frameId, version, encoding, logger, postClose, onSendingToRPCClient }) {
|
|
const POST_MESSAGE = TransportTypes.POST_MESSAGE;
|
|
super(POST_MESSAGE, version, encoding);
|
|
if (["etf", "json"].indexOf(encoding) === -1) {
|
|
throw new RPCError({
|
|
closeCode: RPCCloseCodes.INVALID_ENCODING
|
|
}, `Invalid Encoding: ${encoding}`);
|
|
}
|
|
if (encoding === "etf") {
|
|
throw new RPCError({
|
|
closeCode: RPCCloseCodes.INVALID_ENCODING
|
|
}, "Erlpack cannot be used on this client");
|
|
}
|
|
this.origin = origin;
|
|
this.postMessageToRPCClient = postMessageToRPCClient;
|
|
this.frameId = frameId;
|
|
this.logger = logger;
|
|
this.postClose = postClose;
|
|
this.onSendingToRPCClient = onSendingToRPCClient;
|
|
this.closed = false;
|
|
}
|
|
send(a0) {
|
|
const onSendingToRPCClient = this.onSendingToRPCClient;
|
|
if (onSendingToRPCClient != null) {
|
|
onSendingToRPCClient.call(this, a0, this.id);
|
|
}
|
|
this.postMessageToRPCClient([RPCOpcodes.FRAME, a0], this.origin);
|
|
}
|
|
close(a0, a1) {
|
|
if (!this.closed) {
|
|
this.postClose(this.origin, {
|
|
code: a0,
|
|
message: a1
|
|
}, this.postMessageToRPCClient);
|
|
}
|
|
this.closed = true;
|
|
}
|
|
}
|
|
export default WindowProxySocket;
|