<commit_before>/**
 * This file is part of the peer-data package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

import Socket = SocketIOClient.Socket;
import * as io from "socket.io-client";
import {Bridge} from "./bridge";
import {CONFIG} from "./app";
import {Signaling} from "./signaling/signaling";
import {SignalingEvent} from "./signaling/event";
import {SignalingEventType} from "./signaling/event-type";

export class SocketChannel implements Signaling {
    private socket: Socket;

    constructor() {
        this.socket = io.connect();
        this.socket.on('message', this.onMessage);
        this.socket.on('ipaddr', this.onIp);
        this.socket.on('log', this.onLog);
    }

    send(event: SignalingEvent) {
        this.socket.emit('message', event);
    }

    private onIp(ipaddr: string) {
        CONFIG.logger.log.apply(CONFIG.logger, ['Server IP address is: ' + ipaddr]);
    }

    private onLog(data: any[]) {
        CONFIG.logger.log.apply(CONFIG.logger, [data]);
    }

    private onMessage(event: SignalingEvent) {
        switch (event.type) {
            case SignalingEventType.OFFER:
                Bridge.onOffer(event);
                break;
            case SignalingEventType.ANSWER:<commit_msg>Add socket options<commit_after>/**
 * This file is part of the peer-data package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

import Socket = SocketIOClient.Socket;
import * as io from "socket.io-client";
import {Bridge} from "./bridge";
import {CONFIG} from "./app";
import {Signaling} from "./signaling/signaling";
import {SignalingEvent} from "./signaling/event";
import {SignalingEventType} from "./signaling/event-type";

export class SocketChannel implements Signaling {
    private socket: Socket;

    constructor(opts?: SocketIOClient.ConnectOpts) {
        this.socket = io.connect(opts);
        this.socket.on('message', this.onMessage);
        this.socket.on('ipaddr', this.onIp);
        this.socket.on('log', this.onLog);
    }

    send(event: SignalingEvent) {
        this.socket.emit('message', event);
    }

    private onIp(ipaddr: string) {
        CONFIG.logger.log.apply(CONFIG.logger, ['Server IP address is: ' + ipaddr]);
    }

    private onLog(data: any[]) {
        CONFIG.logger.log.apply(CONFIG.logger, [data]);
    }

    private onMessage(event: SignalingEvent) {
        switch (event.type) {
            case SignalingEventType.OFFER:
                Bridge.onOffer(event);
                break;
            case SignalingEventType.ANSWER:
{'fraction_non_alphanumeric': 0.13190406976744187, 'fraction_numerical': 0.0, 'mean_word_length': 2.9272467902995722, 'pattern_counts': {'":': 0, '<': 9, '<?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': '4860742', 'n_tokens_mistral': 817, 'n_tokens_neox': 791, 'n_words': 212}