<commit_before>//
//  HotBoxNativeService.swift
//  hotbox
//
//  Created by <NAME> on 2017-08-04.
//  Copyright © 2017 <NAME>. All rights reserved.
//

import OpenTok
import RxSwift

class HotBoxNativeService: NSObject {

  class func defaultSetting() -> OTPublisherSettings {
    let settings = OTPublisherSettings()
    settings.name = UIDevice.current.name
    return settings
  }

  static let shared = HotBoxNativeService()
  
  var sessions: [String : OTSession?] = [:]
  var activeSessionId: String?
  var publisher : OTPublisher? = OTPublisher(delegate: nil,
                                             settings: HotBoxNativeService.defaultSetting())
  var subscribers: [String : OTSubscriber?] = [:]
  var connections: [String : OTConnection?] = [:]
  
  let sessionDidConnect = Variable<String?>(nil)
  let sessionDidDisconnect = Variable<String?>(nil)
  let sessionConnectionCreated = Variable<[String : Any?]>([:])
  let sessionConnectionDestroyed = Variable<String?>(nil)
  let sessionStreamCreated = Variable<[String : Any?]>([:])
  let sessionStreamDidFailWithError = Variable<String?>(nil)
  let sessionStreamDestroyed = Variable<String?>(nil)
  let sessionReceivedSignal = Variable<[String : String?]>([:])<commit_msg>Add UserDefaultsKey to manage publisher stream quality<commit_after>//
//  HotBoxNativeService.swift
//  hotbox
//
//  Created by <NAME> on 2017-08-04.
//  Copyright © 2017 <NAME>. All rights reserved.
//

import OpenTok
import RxSwift

class HotBoxNativeService: NSObject {

  static let cameraResolutionKey = "camera-resolution.HotBoxNativeService"
  
  class func defaultSetting() -> OTPublisherSettings {
    let settings = OTPublisherSettings()
    settings.name = UIDevice.current.name
    
    if let cameraResolutionString = UserDefaults.standard.string(forKey: HotBoxNativeService.cameraResolutionKey) {
      switch cameraResolutionString {
      case "high":
        settings.cameraResolution = .high
      case "low":
        settings.cameraResolution = .low
      default:
        settings.cameraResolution = .medium
      }
    }
    
    return settings
  }

  static let shared = HotBoxNativeService()
  
  var sessions: [String : OTSession?] = [:]
  var activeSessionId: String?
  var publisher : OTPublisher? = OTPublisher(delegate: nil,
                                             settings: HotBoxNativeService.defaultSetting())
  var subscribers: [String : OTSubscriber?] = [:]
  var connections: [String : OTConnection?] = [:]
  
  let sessionDidConnect = Variable<String?>(nil)
  let sessionDidDisconnect = Variable<String?>(nil)
  let sessionConnectionCreated = Variable<[String : Any?]>([:])
  let sessionConnectionDestroyed = Variable<String?>(nil)
  let sessionStreamCreated = Variable<[String : Any?]>([:])
  let sessionStreamDidFailWithError = Variable<String?>(nil)
  let sessionStreamDestroyed = Variable<String?>(nil)
  let sessionReceivedSignal = Variable<[String : String?]>([:])
{'fraction_non_alphanumeric': 0.11389830508474576, 'fraction_numerical': 0.008135593220338983, 'mean_word_length': 3.7443729903536975, 'pattern_counts': {'":': 2, '<': 23, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '353265', 'n_tokens_mistral': 893, 'n_tokens_neox': 829, 'n_words': 199}