<commit_before>import { DataEventType } from './event-type';
import { DataEvent } from './event';
import { ConnectionEvent } from './../connection/event';
import { EventDispatcher } from './../dispatcher/dispatcher';
import { DataChannelCollection } from './collection';

const LABEL = 'chunks';

export class DataChannelFactory {
  public static get(peer: RTCPeerConnection, dataConstraints: RTCDataChannelInit): RTCDataChannel {
    return peer.createDataChannel(LABEL, dataConstraints);
  }

  public static subscribeToEvents(channel: RTCDataChannel, channels: DataChannelCollection, event: ConnectionEvent) {
    channel.onmessage = (channelEvent: MessageEvent) => {
      const message: DataEvent = {
        id: event.caller.id,
        event: channelEvent,
      };
      EventDispatcher.dispatch(DataEventType.DATA, message);
    };

    channel.onopen = (channelEvent: Event) => {
      const message: DataEvent = {
        id: event.caller.id,
        event: channelEvent,
      };
      EventDispatcher.dispatch(DataEventType.OPEN, message);
    };

    channel.onclose = (channelEvent: Event) => {
      const message: DataEvent = {
        id: event.caller.id,
        event: channelEvent,
      };
      EventDispatcher.dispatch(DataEventType.CLOSE, message);
<commit_msg>Create data channel with random label<commit_after>import { DataEventType } from './event-type';
import { DataEvent } from './event';
import { ConnectionEvent } from './../connection/event';
import { EventDispatcher } from './../dispatcher/dispatcher';
import { DataChannelCollection } from './collection';

export class DataChannelFactory {
  public static get(peer: RTCPeerConnection, dataConstraints: RTCDataChannelInit): RTCDataChannel {
    const label = Math.floor((1 + Math.random()) * 1e16).toString(16).substring(1);

    return peer.createDataChannel(label, dataConstraints);
  }

  public static subscribeToEvents(channel: RTCDataChannel, channels: DataChannelCollection, event: ConnectionEvent) {
    channel.onmessage = (channelEvent: MessageEvent) => {
      const message: DataEvent = {
        id: event.caller.id,
        event: channelEvent,
      };
      EventDispatcher.dispatch(DataEventType.DATA, message);
    };

    channel.onopen = (channelEvent: Event) => {
      const message: DataEvent = {
        id: event.caller.id,
        event: channelEvent,
      };
      EventDispatcher.dispatch(DataEventType.OPEN, message);
    };

    channel.onclose = (channelEvent: Event) => {
      const message: DataEvent = {
        id: event.caller.id,
        event: channelEvent,
      };
      EventDispatcher.dispatch(DataEventType.CLOSE, message);

{'fraction_non_alphanumeric': 0.1197289156626506, 'fraction_numerical': 0.0026355421686746986, 'mean_word_length': 3.488175675675676, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '5418965', 'n_tokens_mistral': 741, 'n_tokens_neox': 712, 'n_words': 167}