meshblu-connector-skype
Version:
68 lines (52 loc) • 3.07 kB
text/coffeescript
_ = require 'lodash'
debug = require('debug')('meshblu-connector-skype:lync-event-emitter')
{EventEmitter2} = require 'eventemitter2'
class LyncEventEmitter extends EventEmitter2
constructor: ->
= {}
handle: ({conversationId, eventSource, eventType, participantId, data}) =>
debug {conversationId, eventSource, eventType}
{conversationId, eventType, data} if eventSource == 'ConversationManager'
{conversationId, eventType, data} if eventSource == 'Conversation'
{conversationId, eventType, data} if eventSource == 'VideoChannel'
{conversationId, eventType, data} if eventSource == 'AvModality'
{conversationId, participantId, eventType, data} if eventSource == 'Participant'
debug JSON.stringify(, null, 2)
unless _.isEqual ,
'config',
= _.cloneDeep
handleParticipantEvent: ({conversationId, participantId, eventType, data}) =>
if eventType == 'MutedChanged'
safeId = _.replace participantId, /\./g, '-'
_.set , "#{conversationId}.participants.#{safeId}.isMuted", data
handleConversationEvent: ({conversationId, eventType, data}) =>
if eventType == 'StateChanged'
if data.NewState == 'Terminated'
delete [conversationId]
else
_.set , "#{conversationId}.state", data.NewState
if eventType == 'PropertyChanged'
_.set , "#{conversationId}.properties.#{_.camelCase data.Property}", data.Value
if eventType == 'ParticipantAdded'
safeId = _.replace data.id, /\./g, '-'
_.set , "#{conversationId}.participants.#{safeId}", data
_.set , "#{conversationId}.self", safeId if data.isSelf
if eventType == 'ParticipantRemoved'
safeId = _.replace data.id, /\./g
_.unset , "#{conversationId}.participants.#{safeId}"
handleConversationManagerEvent: ({conversationId, eventType, data}) =>
if eventType == 'ConversationAdded'
_.set , "#{conversationId}.properties", data || {}
if eventType == 'ConversationRemoved'
delete [conversationId]
handleVideoChannelEvent: ({conversationId, eventType, data}) =>
if eventType == 'ActionAvailabilityChanged'
_.set , "#{conversationId}.video.actions.#{data.Action}", data.IsAvailable
if eventType == 'StateChanged'
_.set , "#{conversationId}.video.state", data.NewState
handleAVModalityEvent: ({conversationId, eventType, data}) =>
if eventType == 'ActionAvailabilityChanged'
_.set , "#{conversationId}.modality.actions.#{data.Action}", data.IsAvailable
if eventType == 'ModalityStateChanged'
_.set , "#{conversationId}.modality.state", data.NewState
module.exports = LyncEventEmitter