<commit_before>import {
  EventEmitter,
  Inject,
  NgZone,
  Injectable,
  PLATFORM_ID,
} from '@angular/core';
import { Session } from './session';
import { io } from 'socket.io-client';
import { ConfigsService } from '../common/services/configs.service';
import { BehaviorSubject } from 'rxjs';
import { isPlatformServer } from '@angular/common';

@Injectable()
export class SocketsService {
  SOCKET_IO_SERVER: string;
  LIVE_ROOM_NAME = 'live';

  socket: any;
  registered: boolean = false;
  subscriptions: any = {};
  rooms: string[] = [];
  debug: boolean = false;
  public error$: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);

  constructor(
    public session: Session,
    private nz: NgZone,
    private configs: ConfigsService,
    @Inject(PLATFORM_ID) private platformId: Object
  ) {
    this.SOCKET_IO_SERVER = this.configs.get('socket_server');
  }

  setUp(): SocketsService {
    if (isPlatformServer(this.platformId)) return this;
    this.SOCKET_IO_SERVER = this.configs.get('socket_server');
    this.nz.runOutsideAngular(() => {
      if (this.socket) {
        this.socket.destroy();
      }

      this.socket = io(this.SOCKET_IO_SERVER, {
        reconnection: true,
        timeout: 40000,
        autoConnect: false,
        withCredentials: true,
      });

      this.rooms = [];
      this.registered = false;
      this.setUpDefaultListeners();

      if (this.session.isLoggedIn()) {
        this.socket.connect();

        // join all rooms that have already been subscribed to
        for (const name in this.subscriptions) {
          this.nz.runOutsideAngular(() => {
            this.socket.on(name, (...args) => {
              this.nz.run(() => {
                this.subscriptions[name].next(args);
              });
            });
          });
        }
      }

      this.session.isLoggedIn((is: any) => {
        if (is) {
          this.reconnect();
        } else {
          this.disconnect();
          this.rooms = [];
          this.registered = false;
        }
      });<commit_msg>(chore): force websockets and not polling<commit_after>import {
  EventEmitter,
  Inject,
  NgZone,
  Injectable,
  PLATFORM_ID,
} from '@angular/core';
import { Session } from './session';
import { io } from 'socket.io-client';
import { ConfigsService } from '../common/services/configs.service';
import { BehaviorSubject } from 'rxjs';
import { isPlatformServer } from '@angular/common';

@Injectable()
export class SocketsService {
  SOCKET_IO_SERVER: string;
  LIVE_ROOM_NAME = 'live';

  socket: any;
  registered: boolean = false;
  subscriptions: any = {};
  rooms: string[] = [];
  debug: boolean = false;
  public error$: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);

  constructor(
    public session: Session,
    private nz: NgZone,
    private configs: ConfigsService,
    @Inject(PLATFORM_ID) private platformId: Object
  ) {
    this.SOCKET_IO_SERVER = this.configs.get('socket_server');
  }

  setUp(): SocketsService {
    if (isPlatformServer(this.platformId)) return this;
    this.SOCKET_IO_SERVER = this.configs.get('socket_server');
    this.nz.runOutsideAngular(() => {
      if (this.socket) {
        this.socket.destroy();
      }

      this.socket = io(this.SOCKET_IO_SERVER, {
        reconnection: true,
        timeout: 40000,
        autoConnect: false,
        withCredentials: true,
        transports: ['websocket'],
      });

      this.rooms = [];
      this.registered = false;
      this.setUpDefaultListeners();

      if (this.session.isLoggedIn()) {
        this.socket.connect();

        // join all rooms that have already been subscribed to
        for (const name in this.subscriptions) {
          this.nz.runOutsideAngular(() => {
            this.socket.on(name, (...args) => {
              this.nz.run(() => {
                this.subscriptions[name].next(args);
              });
            });
          });
        }
      }

      this.session.isLoggedIn((is: any) => {
        if (is) {
          this.reconnect();
        } else {
          this.disconnect();
          this.rooms = [];
          this.registered = false;
        }
      });
{'fraction_non_alphanumeric': 0.13574335647593966, 'fraction_numerical': 0.0023940627244433805, 'mean_word_length': 2.407830342577488, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 17, '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': '1333042', 'n_tokens_mistral': 1290, 'n_tokens_neox': 1253, 'n_words': 261}