function signal(data) {
      var _this2 = this;

      if (this.destroyed) throw new Error('cannot signal after peer is destroyed');
      if (typeof data === 'string') {
        try {
          data = JSON.parse(data);
        } catch (err) {
          data = {};
        }
      }
      // self._debug('signal()')

      if (data.candidate) {
        if (this._pc.remoteDescription) this._addIceCandidate(data.candidate);else this._pendingCandidates.push(data.candidate);
      }
      if (data.sdp) {
        this._pc.setRemoteDescription(new this._wrtc.RTCSessionDescription(data), function () {
          if (_this2.destroyed) return;

          _this2._pendingCandidates.forEach(function (candidate) {
            return _this2._addIceCandidate(candidate);
          });
          _this2._pendingCandidates = [];

          if (_this2._pc.remoteDescription.type === 'offer') _this2._createAnswer();
        }, function (err) {
          _this2._destroy(err);
        });
      }
      if (!data.sdp && !data.candidate) {
        this._destroy(new Error('signal() called with invalid signal data'));
      }
    }
/**
     * The signal method attempts to setup the P2P connection using the proposed
     * candidates.
     * @param {RTCSessionDescription} data The signalling data
     */
The signal method attempts to setup the P2P connection using the proposed
candidates.
@param {RTCSessionDescription} data The signalling data
The signal method attempts to setup the P2P connection using the proposed candidates . @param { RTCSessionDescription } data The signalling data
function signal(data) {
      var _this2 = this;
      if (this.destroyed) throw new Error('cannot signal after peer is destroyed');
      if (typeof data === 'string') {
        try {
          data = JSON.parse(data);
        } catch (err) {
          data = {};
        }
      }
      if (data.candidate) {
        if (this._pc.remoteDescription) this._addIceCandidate(data.candidate);else this._pendingCandidates.push(data.candidate);
      }
      if (data.sdp) {
        this._pc.setRemoteDescription(new this._wrtc.RTCSessionDescription(data), function () {
          if (_this2.destroyed) return;
          _this2._pendingCandidates.forEach(function (candidate) {
            return _this2._addIceCandidate(candidate);
          });
          _this2._pendingCandidates = [];
          if (_this2._pc.remoteDescription.type === 'offer') _this2._createAnswer();
        }, function (err) {
          _this2._destroy(err);
        });
      }
      if (!data.sdp && !data.candidate) {
        this._destroy(new Error('signal() called with invalid signal data'));
      }
    }
function signal ( data ) { var _this2 = this ; if ( this . destroyed ) throw new Error ( 'cannot signal after peer is destroyed' ) ; if ( typeof data === 'string' ) { try { data = JSON . parse ( data ) ; } catch ( err ) { data = { } ; } } if ( data . candidate ) { if ( this . _pc . remoteDescription ) this . _addIceCandidate ( data . candidate ) ; else this . _pendingCandidates . push ( data . candidate ) ; } if ( data . sdp ) { this . _pc . setRemoteDescription ( new this . _wrtc . RTCSessionDescription ( data ) , function ( ) { if ( _this2 . destroyed ) return ; _this2 . _pendingCandidates . forEach ( function ( candidate ) { return _this2 . _addIceCandidate ( candidate ) ; } ) ; _this2 . _pendingCandidates = [ ] ; if ( _this2 . _pc . remoteDescription . type === 'offer' ) _this2 . _createAnswer ( ) ; } , function ( err ) { _this2 . _destroy ( err ) ; } ) ; } if ( ! data . sdp && ! data . candidate ) { this . _destroy ( new Error ( 'signal() called with invalid signal data' ) ) ; } }
The signal method attempts to setup the P2P connection using the proposed
 candidates.
The signal method attempts to setup the P2P connection using the proposed candidates .
// self._debug('signal()')