<commit_before>/* @flow */
import ConnectionBase from './base';

class ConnectionPublisher extends ConnectionBase {
  connect(stream: ?MediaStream.prototype) {
    this.role = 'upstream';
    if (this.options && this.options.multistream) {
      return this._multiStream(stream);
    }
    else {
      return this._singleStream(stream);
    }
  }

  _singleStream(stream: ?MediaStream.prototype) {
    return this.disconnect()
      .then(this._signaling.bind(this))
      .then(message => {
        return this._connectPeerConnection(message);
      })
      .then(message => {
        if (typeof this._pc.addStream === 'undefined') {
          stream.getTracks().forEach(track => {
            this._pc.addTrack(track, stream);
          });
        }
        else {
          this._pc.addStream(stream);
        }
        this.stream = stream;
        return this._setRemoteDescription(message);
      })
      .then(this._createAnswer.bind(this))
      .then(this._sendAnswer.bind(this))
      .then(this._onIceCandidate.bind(this))
      .then(() => {
        return this.stream;
      });
  }

  _multiStream(stream: ?MediaStream.prototype) {
    return this.disconnect()
      .then(this._signaling.bind(this))
      .then(message => {
        return this._connectPeerConnection(message);
      })
      .then(message => {
        if (typeof this._pc.addStream === 'undefined') {
          stream.getTracks().forEach(track => {
            this._pc.addTrack(track, stream);
          });
        }
        else {
          this._pc.addStream(stream);
        }
        if (typeof this._pc.ontrack === 'undefined') {
          this._pc.onaddstream = event => {
            if (this.clientId !== event.stream.id) {
              this._callbacks.addstream(event);
            }
          };
        } else {
          this._pc.ontrack = event => {
            const stream = event.streams[0];
            if (stream.id === 'default') return;
            if (event.track.kind === 'video') {
              event.stream = stream;
              this._callbacks.addstream(event);
            }
          };
        }
        this._pc.onremovestream = event => {
          this._callbacks.removestream(event);
        };
        this.stream = stream;
        return this._setRemoteDescription(message);
      })
      .then(this._createAnswer.bind(this))
      .then(this._sendAnswer.bind(this))
      .then(this._onIceCandidate.bind(this))
      .then(() => {
        return this.stream;
      });
  }
}
<commit_msg>client id と stream id を比較して localStream かどうか判定する<commit_after>/* @flow */
import ConnectionBase from './base';

class ConnectionPublisher extends ConnectionBase {
  connect(stream: ?MediaStream.prototype) {
    this.role = 'upstream';
    if (this.options && this.options.multistream) {
      return this._multiStream(stream);
    }
    else {
      return this._singleStream(stream);
    }
  }

  _singleStream(stream: ?MediaStream.prototype) {
    return this.disconnect()
      .then(this._signaling.bind(this))
      .then(message => {
        return this._connectPeerConnection(message);
      })
      .then(message => {
        if (typeof this._pc.addStream === 'undefined') {
          stream.getTracks().forEach(track => {
            this._pc.addTrack(track, stream);
          });
        }
        else {
          this._pc.addStream(stream);
        }
        this.stream = stream;
        return this._setRemoteDescription(message);
      })
      .then(this._createAnswer.bind(this))
      .then(this._sendAnswer.bind(this))
      .then(this._onIceCandidate.bind(this))
      .then(() => {
        return this.stream;
      });
  }

  _multiStream(stream: ?MediaStream.prototype) {
    return this.disconnect()
      .then(this._signaling.bind(this))
      .then(message => {
        return this._connectPeerConnection(message);
      })
      .then(message => {
        if (typeof this._pc.addStream === 'undefined') {
          stream.getTracks().forEach(track => {
            this._pc.addTrack(track, stream);
          });
        }
        else {
          this._pc.addStream(stream);
        }
        if (typeof this._pc.ontrack === 'undefined') {
          this._pc.onaddstream = event => {
            if (this.clientId !== event.stream.id) {
              this._callbacks.addstream(event);
            }
          };
        } else {
          this.streams = [];
          this._pc.ontrack = event => {
            const stream = event.streams[0];
            if (stream.id === 'default') return;
            if (stream.id === this.clientId) return;
            if (event.track.kind === 'video') {
              event.stream = stream;
              this.streams.push(stream);
              this._callbacks.addstream(event);
            }
          };
        }
        this._pc.onremovestream = event => {
          this._callbacks.removestream(event);
        };
        this.stream = stream;
        return this._setRemoteDescription(message);
      })
      .then(this._createAnswer.bind(this))
      .then(this._sendAnswer.bind(this))
      .then(this._onIceCandidate.bind(this))
      .then(() => {
        return this.stream;
      });
  }
}

{'fraction_non_alphanumeric': 0.14065510597302505, 'fraction_numerical': 0.0003853564547206166, 'mean_word_length': 1.9, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4483507', 'n_tokens_mistral': 1525, 'n_tokens_neox': 1502, 'n_words': 227}