<commit_before>// @flow
import type {
  ApiError,
  ApiLobby,
  ApiPlayer,
  ApiPlayerMove,
  ApiPlayerTurnInfo,
  ApiPreparedCard,
  ApiTable,
} from './model';
import type { JsonStompClient, SubscribeFn } from './websocket';
import { createJsonStompClient } from './websocket';

const wsURL = '/seven-wonders-websocket';

export class SevenWondersSession {
  client: JsonStompClient;

  constructor(client: JsonStompClient) {
    this.client = client;
  }

  watchErrors(): SubscribeFn<ApiError> {
    return this.client.subscriber('/user/queue/errors');
  }

  chooseName(displayName: string): void {
    this.client.send('/app/chooseName', { playerName: displayName });
  }

  watchNameChoice(): SubscribeFn<ApiPlayer> {
    return this.client.subscriber('/user/queue/nameChoice');
  }

  watchGames(): SubscribeFn<ApiLobby[]> {
    return this.client.subscriber('/topic/games');
  }

  watchLobbyJoined(): SubscribeFn<Object> {
    return this.client.subscriber('/user/queue/lobby/joined');
  }

  watchLobbyUpdated(currentGameId: number): SubscribeFn<Object> {
    return this.client.subscriber(`/topic/lobby/${currentGameId}/updated`);
  }

  watchGameStarted(currentGameId: number): SubscribeFn<Object> {
    return this.client.subscriber(`/topic/lobby/${currentGameId}/started`);
  }

  createGame(gameName: string): void {
    this.client.send('/app/lobby/create', { gameName });
  }

  joinGame(gameId: number): void {
    this.client.send('/app/lobby/join', { gameId });
  }

  startGame(): void {
    this.client.send('/app/lobby/startGame');
  }

  watchPlayerReady(currentGameId: number): SubscribeFn<string> {
    return this.client.subscriber(`/topic/game/${currentGameId}/playerReady`);
  }

  watchTableUpdates(currentGameId: number): SubscribeFn<ApiTable> {
    return this.client.subscriber(`/topic/game/${currentGameId}/tableUpdates`);
  }

  watchPreparedMove(currentGameId: number): SubscribeFn<ApiPreparedCard> {
    return this.client.subscriber(`/topic/game/${currentGameId}/prepared`);
  }

  watchTurnInfo(): SubscribeFn<ApiPlayerTurnInfo> {
    return this.client.subscriber('/user/queue/game/turnInfo');
  }

  sayReady(): void {
    this.client.send('/app/game/sayReady');
  }

  prepareMove(move: ApiPlayerMove): void {
    this.client.send('/app/game/sayReady', { move });
  }
}

export async function connectToGame(): Promise<SevenWondersSession> {
  const jsonStompClient: JsonStompClient = createJsonStompClient(wsURL);
  await jsonStompClient.connect();
  return new SevenWondersSession(jsonStompClient);<commit_msg>Fix and order seven wonders JS client<commit_after>// @flow
import type {
  ApiError,
  ApiLobby,
  ApiPlayer,
  ApiPlayerMove,
  ApiPlayerTurnInfo,
  ApiPreparedCard,
  ApiSettings,
  ApiTable,
} from './model';
import type { JsonStompClient, SubscribeFn } from './websocket';
import { createJsonStompClient } from './websocket';

const WS_URL = '/seven-wonders-websocket';

export class SevenWondersSession {
  client: JsonStompClient;

  constructor(client: JsonStompClient) {
    this.client = client;
  }

  watchErrors(): SubscribeFn<ApiError> {
    return this.client.subscriber('/user/queue/errors');
  }

  watchNameChoice(): SubscribeFn<ApiPlayer> {
    return this.client.subscriber('/user/queue/nameChoice');
  }

  chooseName(displayName: string): void {
    this.client.send('/app/chooseName', { playerName: displayName });
  }

  watchGames(): SubscribeFn<ApiLobby[]> {
    return this.client.subscriber('/topic/games');
  }

  watchLobbyJoined(): SubscribeFn<Object> {
    return this.client.subscriber('/user/queue/lobby/joined');
  }

  createGame(gameName: string): void {
    this.client.send('/app/lobby/create', { gameName });
  }

  joinGame(gameId: number): void {
    this.client.send('/app/lobby/join', { gameId });
  }

  watchLobbyUpdated(currentGameId: number): SubscribeFn<Object> {
    return this.client.subscriber(`/topic/lobby/${currentGameId}/updated`);
  }

  watchGameStarted(currentGameId: number): SubscribeFn<Object> {
    return this.client.subscriber(`/topic/lobby/${currentGameId}/started`);
  }

  leave(): void {
    this.client.send('/app/lobby/leave');
  }

  reorderPlayers(orderedPlayers: Array<string>): void {
    this.client.send('/app/lobby/reorderPlayers', { orderedPlayers });
  }

  updateSettings(settings: ApiSettings): void {
    this.client.send('/app/lobby/updateSettings', { settings });
  }

  startGame(): void {
    this.client.send('/app/lobby/startGame');
  }

  watchPlayerReady(currentGameId: number): SubscribeFn<string> {
    return this.client.subscriber(`/topic/game/${currentGameId}/playerReady`);
  }

  watchTableUpdates(currentGameId: number): SubscribeFn<ApiTable> {
    return this.client.subscriber(`/topic/game/${currentGameId}/tableUpdates`);
  }

  watchPreparedMove(currentGameId: number): SubscribeFn<ApiPreparedCard> {
    return this.client.subscriber(`/topic/game/${currentGameId}/prepared`);
  }

  watchTurnInfo(): SubscribeFn<ApiPlayerTurnInfo> {
    return this.client.subscriber('/user/queue/game/turn');
  }

  sayReady(): void {
    this.client.send('/app/game/sayReady');
  }

  prepareMove(move: ApiPlayerMove): void {
    this.client.send('/app/game/prepareMove', { move });
  }
}

export async function connectToGame(): Promise<SevenWondersSession> {
  const jsonStompClient: JsonStompClient = createJsonStompClient(WS_URL);
  await jsonStompClient.connect();
  return new SevenWondersSession(jsonStompClient);
{'fraction_non_alphanumeric': 0.14790408200622368, 'fraction_numerical': 0.0, 'mean_word_length': 4.604102564102564, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 26, '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': '6183134', 'n_tokens_mistral': 1783, 'n_tokens_neox': 1747, 'n_words': 261}