"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const react_native_1 = require("react-native");
const { WebRTCModule } = react_native_1.NativeModules;
class RTCRtpTransceiver {
    constructor(args) {
        this._mid = null;
        this._peerConnectionId = args.peerConnectionId;
        this._mid = args.mid ? args.mid : null;
        this._direction = args.direction;
        this._currentDirection = args.currentDirection;
        this._stopped = Boolean(args.isStopped);
        this._sender = args.sender;
        this._receiver = args.receiver;
    }
    get mid() {
        return this._mid;
    }
    get stopped() {
        return this._stopped;
    }
    get direction() {
        return this._direction;
    }
    set direction(val) {
        if (!['sendonly', 'recvonly', 'sendrecv', 'inactive'].includes(val)) {
            throw new TypeError('Invalid direction provided');
        }
        if (this._stopped) {
            throw Error('Transceiver Stopped');
        }
        if (this._direction === val) {
            return;
        }
        const oldDirection = this._direction;
        WebRTCModule.transceiverSetDirection(this._peerConnectionId, this.sender.id, val)
            .catch(() => {
            this._direction = oldDirection;
        });
        this._direction = val;
    }
    get currentDirection() {
        return this._currentDirection;
    }
    get sender() {
        return this._sender;
    }
    get receiver() {
        return this._receiver;
    }
    stop() {
        if (this._stopped) {
            return;
        }
        WebRTCModule.transceiverStop(this._peerConnectionId, this.sender.id)
            .then(() => this._setStopped());
    }
    _setStopped() {
        this._stopped = true;
        this._direction = 'stopped';
        this._currentDirection = 'stopped';
        this._mid = null;
    }
}
exports.default = RTCRtpTransceiver;
//# sourceMappingURL=RTCRtpTransceiver.js.map