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://';
    }
    async callOption(req) {
        return req;
    }
    async register(sipConf) {
        return;
    }
    async unregister() {
        return;
    }
    async call(req) {
        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({
            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