import { __awaiter } from "tslib";
import { EventEmitter } from 'ee-ts/lib/ee';
import Session from './session';
export class ExternalClient extends EventEmitter {
    constructor(config) {
        super();
        this.config = config;
        this.type = 'external';
        this.schema = 'wtel://';
    }
    callOption(req) {
        return __awaiter(this, void 0, void 0, function* () {
            return req;
        });
    }
    register(sipConf) {
        return __awaiter(this, void 0, void 0, function* () {
            return;
        });
    }
    unregister() {
        return __awaiter(this, void 0, void 0, function* () {
            return;
        });
    }
    call(req) {
        return __awaiter(this, void 0, void 0, function* () {
            if (!req.destination) {
                return;
            }
            this.exec(req.destination);
        });
    }
    answer(id) {
        this.exec(id, 'answer');
    }
    isRegistered() {
        return false;
    }
    sipSessionByCallId(id) {
        return new Session(this, id);
    }
    sipSessionBySipId(id) {
        return null;
    }
    open(token) {
        this.exec(encodeURIComponent(JSON.stringify(Object.assign({ token }, this.config))), 'open');
    }
    exec(args, action) {
        // TODO escape
        let url = `${this.schema}${args}`;
        if (action) {
            url += ` ${action}`;
        }
        const link = document.createElement('a');
        link.download = 'File name';
        link.href = url;
        link.click();
        return;
    }
}
//# sourceMappingURL=index.js.map