322:7dfdf32e8577
Anton Shestakov <av6@dwimlabs.net>, Sat, 14 Jul 2018 20:23:13 +0800
index: authorizing contact also adds it to the roster Maybe there are cases when this doesn't make sense, but so far this looks like the right thing to do.

next change 328:c6851321a39e
previous change 320:5d464090cea7

coffee/calls.coffee

Permissions: -rw-r--r--

Other formats: Feeds:
class Tram.Call extends Backbone.Model
idAttribute: 'jid'
initialize: ->
@on('change:local/stream', @updateLocalStreamURL)
@on('change:remote/stream', @updateRemoteStreamURL)
updateStreamURL: (sattr, uattr) ->
if @has(uattr)
URL.revokeObjectURL(@get(uattr))
stream = @get(sattr)
if stream
@set(uattr, URL.createObjectURL(stream))
else
@unset(uattr)
updateLocalStreamURL: ->
@updateStreamURL('local/stream', 'local/stream/url')
updateRemoteStreamURL: ->
@updateStreamURL('remote/stream', 'remote/stream/url')
class Tram.Calls extends Backbone.Collection
model: Tram.Call
class Tram.CallView extends Backbone.View
templateEl: $($('#video-block-template').html())
events:
'click [data-mute-cam]': -> @model.set('local/video/muted', true)
'click [data-unmute-cam]': -> @model.set('local/video/muted', false)
'click [data-mute-mic]': -> @model.set('local/audio/muted', true)
'click [data-unmute-mic]': -> @model.set('local/audio/muted', false)
'click [data-mute-audio]': -> @model.set('remote/audio/muted', true)
'click [data-unmute-audio]': -> @model.set('remote/audio/muted', false)
'click [data-hang-up]': -> @model.get('contact').trigger('action/hangup')
initialize: ->
@setElement(@templateEl.clone())
@$local = @$('video.local')
@$remote = @$('video.remote')
@$avatarColumn = @$('.avatar-column')
@bind()
bind: ->
@listenTo(@model, 'change:local/stream/url', @updateLocal)
@listenTo(@model, 'change:remote/stream/url', @updateRemote)
@listenTo(@model, 'change:local/video/muted', @muteCam)
@listenTo(@model, 'change:local/audio/muted', @muteMic)
@listenTo(@model, 'change:remote/audio/muted', @muteAudio)
@listenTo(@model, 'remove', @remove)
updateLocal: ->
if @model.has('local/stream/url')
@updateVideo(@$local, @model.get('local/stream/url'))
else
@removeVideo(@$local)
updateRemote: ->
if @model.has('remote/stream/url')
@updateVideo(@$remote, @model.get('remote/stream/url'))
else
@removeVideo(@$remote)
updateVideo: ($video, url) ->
$video.each ->
@src = url
@play()
removeVideo: ($video) ->
$video.each ->
@pause()
@removeAttribute('src')
toggleTracks: (tracks, state) ->
if tracks?
for track in tracks
track.enabled = state
muteCam: ->
muted = @model.get('local/video/muted')
@toggleTracks(@model.get('local/stream')?.getVideoTracks?(), not muted)
muteMic: ->
muted = @model.get('local/audio/muted')
@toggleTracks(@model.get('local/stream')?.getAudioTracks?(), not muted)
muteAudio: ->
muted = @model.get('remote/audio/muted')
@toggleTracks(@model.get('remote/stream')?.getAudioTracks?(), not muted)
render: ->
@rivet = rivets.bind(@el, call: @model, view: @)
@av = new Tram.AvatarView(model: @model.get('contact'))
@$avatarColumn.append(@av.render().el)
@
remove: ->
@av.remove()
@rivet.unbind()
super
class Tram.CallsApp extends Backbone.View
initialize: ->
@listenTo(@collection, 'add', @onAdd)
onAdd: (model) ->
model.view = new Tram.CallView(model: model)
@$el.append(model.view.render().el)