<commit_before>//
//  Socket.swift
//  Pods
//
//  Created by <NAME> on 23/06/2016.
//
//

import Foundation
import Starscream

public final class Socket {
    // MARK: - Convenience aliases
    public typealias Payload = [String: AnyObject]

    // MARK: - Properties

    private var socket: WebSocket
    public var enableLogging = true

    public var onConnect: (() -> ())?
    public var onDisconnect: (NSError? -> ())?

    private(set) public var channels: [String: Channel] = [:]

    private static let HeartbeatInterval = Int64(30 * NSEC_PER_SEC)
    private static let HeartbeatPrefix = "hb-"
    private var heartbeatQueue: dispatch_queue_t

    private var awaitingResponses = [String: Push]()

    public var isConnected: Bool {
        return socket.isConnected
    }

    // MARK: - Initialisation

    public init(url: NSURL, params: [String: String]? = nil, selfSignedSSL: Bool = false) {
        heartbeatQueue = dispatch_queue_create("com.ecksd.birdsong.hbqueue", nil)
        socket = WebSocket(url: buildURL(url, params: params))
        socket.delegate = self
        socket.selfSignedSSL = selfSignedSSL
    }

    // MARK: - Connection
<commit_msg>Added convenience init methods (#1).<commit_after>//
//  Socket.swift
//  Pods
//
//  Created by <NAME> on 23/06/2016.
//
//

import Foundation
import Starscream

public final class Socket {
    // MARK: - Convenience aliases
    public typealias Payload = [String: AnyObject]

    // MARK: - Properties

    private var socket: WebSocket
    public var enableLogging = true

    public var onConnect: (() -> ())?
    public var onDisconnect: (NSError? -> ())?

    private(set) public var channels: [String: Channel] = [:]

    private static let HeartbeatInterval = Int64(30 * NSEC_PER_SEC)
    private static let HeartbeatPrefix = "hb-"
    private var heartbeatQueue: dispatch_queue_t

    private var awaitingResponses = [String: Push]()

    public var isConnected: Bool {
        return socket.isConnected
    }

    // MARK: - Initialisation

    public init(url: NSURL, params: [String: String]? = nil, selfSignedSSL: Bool = false) {
        heartbeatQueue = dispatch_queue_create("com.ecksd.birdsong.hbqueue", nil)
        socket = WebSocket(url: buildURL(url, params: params))
        socket.delegate = self
        socket.selfSignedSSL = selfSignedSSL
    }

    public convenience init(url: String, params: [String: String]? = nil,
                            selfSignedSSL: Bool = false) {
        if let parsedURL = NSURL(string: url) {
            self.init(url: parsedURL, params: params, selfSignedSSL: selfSignedSSL)
        }
        else {
            print("[Birdsong] Invalid URL in init. Defaulting to localhost URL.")
            self.init()
        }
    }

    public convenience init(prot: String = "http", host: String = "localhost", port: Int = 4000,
                            path: String = "socket", transport: String = "websocket",
                            params: [String: String]? = nil, selfSignedSSL: Bool = false) {
        let url = "\(prot)://\(host):\(port)/\(path)/\(transport)"
        self.init(url: url, params: params, selfSignedSSL: selfSignedSSL)
    }

    // MARK: - Connection

{'fraction_non_alphanumeric': 0.11661989398191457, 'fraction_numerical': 0.00904271905207359, 'mean_word_length': 2.576365663322185, 'pattern_counts': {'":': 0, '<': 5, '<?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': '1634519', 'n_tokens_mistral': 1022, 'n_tokens_neox': 932, 'n_words': 268}