"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.RemoteClient = void 0;
const STRING_1 = require("./constant/STRING");
const RemotePort_1 = require("./RemotePort");
class RemoteClient {
    constructor(port) {
        this._init_data = (data) => {
            return { type: STRING_1.INIT, data };
        };
        this._exec_data = (data) => {
            return { type: STRING_1.EXEC, data };
        };
        this._port = port;
        const _port = {
            send: (data) => {
                const _data = this._exec_data(data);
                this._port.send(_data);
            },
            onmessage(data) { },
            onerror() { },
            terminate() { },
        };
        this._port.onmessage = (data) => {
            _port.onmessage(data);
        };
        this._remote_port = new RemotePort_1.RemotePort(_port);
    }
    init(bundle) {
        const _data = this._init_data(bundle);
        this._port.send(_data);
    }
    terminate() {
        this._port.terminate();
    }
    port() {
        return this._remote_port;
    }
    invalidate() {
        this._remote_port.close();
    }
}
exports.RemoteClient = RemoteClient;
//# sourceMappingURL=RemoteClient.js.map