<commit_before>/**
 * Copyright (c) 2015-present, Facebook, Inc.
 * All rights reserved.
 *
 * This source code is licensed under the BSD-style license found in the
 * LICENSE file in the root directory of this source tree. An additional grant
 * of patent rights can be found in the PATENTS file in the same directory.
 *
 * @flow
 */

import Module from './Module';

import type {ReactNativeContext} from '../ReactNativeContext';

/**
 * WebSocketModule is an implementation of the websocket interface used by React native.
 * These methods are not intended to be called directly. Rather, they are
 * called remotely by the WebSocketModule module on the React side.
 * @class WebSocketModule
 * @extends Module
 */
export default class WebSocketModule extends Module {
  _rnctx: ReactNativeContext;
  _sockets: {[id: string]: WebSocket};

  /**
   * Constructs a WebSocketModule with a specific React Native Context
   */
  constructor(rnctx: ReactNativeContext) {
    super('WebSocketModule');
    this._sockets = {};
    this._rnctx = rnctx;
  }

  /**
   * Establish a connection and associate with socketID. socketID is used for future
   * communication with React
   * @param url - string Url to connect to
   * @param protocols - protocols for creating the WebSocket instance
   * @param options - currently unused
   * @param socketId - ID used to represent this connection in React
   */
  connect(url: string, protocols: string | Array<string>, options: any, socketId: number) {
    const socket = new WebSocket(url, protocols);
    socket.binaryType = 'arraybuffer';
    this._sockets[String(socketId)] = socket;

    // set the onclose, onerror and onmessage functions so that the
    // React event can be dispatched
    socket.onclose = event => {<commit_msg>WebSocketModule (re-submit): fix secure websocket creation when protocols is null<commit_after>/**
 * Copyright (c) 2015-present, Facebook, Inc.
 * All rights reserved.
 *
 * This source code is licensed under the BSD-style license found in the
 * LICENSE file in the root directory of this source tree. An additional grant
 * of patent rights can be found in the PATENTS file in the same directory.
 *
 * @flow
 */

import Module from './Module';

import type {ReactNativeContext} from '../ReactNativeContext';

/**
 * WebSocketModule is an implementation of the websocket interface used by React native.
 * These methods are not intended to be called directly. Rather, they are
 * called remotely by the WebSocketModule module on the React side.
 * @class WebSocketModule
 * @extends Module
 */
export default class WebSocketModule extends Module {
  _rnctx: ReactNativeContext;
  _sockets: {[id: string]: WebSocket};

  /**
   * Constructs a WebSocketModule with a specific React Native Context
   */
  constructor(rnctx: ReactNativeContext) {
    super('WebSocketModule');
    this._sockets = {};
    this._rnctx = rnctx;
  }

  /**
   * Establish a connection and associate with socketID. socketID is used for future
   * communication with React
   * @param url - string Url to connect to
   * @param protocols - protocols for creating the WebSocket instance
   * @param options - currently unused
   * @param socketId - ID used to represent this connection in React
   */
  connect(url: string, protocols: string | Array<string>, options: any, socketId: number) {
    const socket = protocols ? new WebSocket(url, protocols) : new WebSocket(url);
    socket.binaryType = 'arraybuffer';
    this._sockets[String(socketId)] = socket;

    // set the onclose, onerror and onmessage functions so that the
    // React event can be dispatched
    socket.onclose = event => {
{'fraction_non_alphanumeric': 0.08490824431662558, 'fraction_numerical': 0.0021911804984935633, 'mean_word_length': 3.682051282051282, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5433758', 'n_tokens_mistral': 980, 'n_tokens_neox': 949, 'n_words': 416}