<commit_before>kd        = require 'kd'
helper    = require './helper'
constants = require './constants'


module.exports = class VideoCollaborationViewModel extends kd.Object

  constructor: (options = {}, data) ->

    super options, data

    {@view, @model} = options

    @model.on 'ActiveParticipantChanged', (nick) => kd.utils.defer => @switchTo nick
    @model.on 'VideoCollaborationActive',   @bound 'fixParticipantVideoElements'
    @model.on 'SelectedParticipantChanged', @bound 'handleParticipantSelected'

    @model.on 'CameraAccessQuestionAsked',    @bound 'handleCameraQuestionAsked'
    @model.on 'CameraAccessQuestionAnswered', @bound 'handleCameraQuestionAnswered'

    viewControlBinder = (control) => (state) => @view[control].setActiveState state

    @model.on 'VideoPublishStateChanged', viewControlBinder 'controlVideo'
    @model.on 'AudioPublishStateChanged', viewControlBinder 'controlAudio'
    @model.on 'SpeakerStateChanged',      viewControlBinder 'controlSpeaker'


  ###*
   * First hide all participants, even the offline ones(!), then show
   * participant with given nickname.
   *
   * @param {string} nick
  ###
  switchTo: (nick) ->

    participants = @model.getParticipants()
    hideAll @view, participants

    participant = @model.getParticipant nick

    if not participant
      showOfflineParticipant @view, nick
    else if isDefaultParticipant participant
      showNonpublishingUser @view, nick<commit_msg>video: whenever a video publish state changes fix video element<commit_after>kd        = require 'kd'
helper    = require './helper'
constants = require './constants'


module.exports = class VideoCollaborationViewModel extends kd.Object

  constructor: (options = {}, data) ->

    super options, data

    {@view, @model} = options

    @model.on 'ActiveParticipantChanged', (nick) => kd.utils.defer => @switchTo nick
    @model.on 'VideoCollaborationActive',   @bound 'fixParticipantVideoElements'
    @model.on 'SelectedParticipantChanged', @bound 'handleParticipantSelected'

    @model.on 'CameraAccessQuestionAsked',    @bound 'handleCameraQuestionAsked'
    @model.on 'CameraAccessQuestionAnswered', @bound 'handleCameraQuestionAnswered'

    viewControlBinder = (control) => (state) => @view[control].setActiveState state

    @model.on 'VideoPublishStateChanged', viewControlBinder 'controlVideo'
    @model.on 'AudioPublishStateChanged', viewControlBinder 'controlAudio'
    @model.on 'SpeakerStateChanged',      viewControlBinder 'controlSpeaker'

    # every time we are re/publishing, we have to fix the video element css.
    @model.on 'VideoPublishStateChanged', => fixParticipantVideo @model.publisher


  ###*
   * First hide all participants, even the offline ones(!), then show
   * participant with given nickname.
   *
   * @param {string} nick
  ###
  switchTo: (nick) ->

    participants = @model.getParticipants()
    hideAll @view, participants

    participant = @model.getParticipant nick

    if not participant
      showOfflineParticipant @view, nick
    else if isDefaultParticipant participant
      showNonpublishingUser @view, nick
{'fraction_non_alphanumeric': 0.10307298335467349, 'fraction_numerical': 0.0, 'mean_word_length': 4.278716216216216, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 16, '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': '5389588', 'n_tokens_mistral': 907, 'n_tokens_neox': 856, 'n_words': 229}