109 lines
2.9 KiB
CoffeeScript
109 lines
2.9 KiB
CoffeeScript
context = window
|
|
|
|
@SessionHelper = class SessionHelper
|
|
|
|
constructor: (app, session, participantsEverSeen, isRecording, downloadingJamTrack) ->
|
|
@app = app
|
|
@session = session
|
|
@participantsEverSeen = participantsEverSeen
|
|
@isRecording = isRecording
|
|
@downloadingJamTrack = downloadingJamTrack
|
|
|
|
inSession: () ->
|
|
@session?
|
|
|
|
participants: () ->
|
|
if @session
|
|
return @session.participants
|
|
else
|
|
[]
|
|
|
|
otherParticipants: () ->
|
|
others = []
|
|
for participant in @participants()
|
|
myTrack = @app.clientId == participant.client_id
|
|
|
|
others.push(participant) unless myTrack
|
|
others
|
|
|
|
# if any participant has the metronome open, then we say this session has the metronome open
|
|
isMetronomeOpen: () ->
|
|
@session? && @session.metronome_active
|
|
|
|
isPlayingRecording: () ->
|
|
# this is the server's state; there is no guarantee that the local tracks
|
|
# requested from the backend will have corresponding track information
|
|
return !!(@session && @session.claimed_recording);
|
|
|
|
recordedTracks: () ->
|
|
if @session && @session.claimed_recording
|
|
@session.claimed_recording.recording.recorded_tracks
|
|
else
|
|
null
|
|
|
|
recordedBackingTracks: () ->
|
|
if @session && @session.claimed_recording
|
|
@session.claimed_recording.recording.recorded_backing_tracks
|
|
else
|
|
null
|
|
|
|
backingTracks: () ->
|
|
backingTracks = []
|
|
# this may be wrong if we loosen the idea that only one person can have a backing track open.
|
|
# but for now, the 1st person we find with a backing track open is all there is to find...
|
|
|
|
for participant in @participants()
|
|
if participant.backing_tracks.length > 0
|
|
backingTracks = participant.backing_tracks
|
|
break
|
|
|
|
backingTracks
|
|
|
|
backingTrack: () ->
|
|
result = null
|
|
if @session
|
|
# TODO: objectize this for VRFS-2665, VRFS-2666, VRFS-2667, VRFS-2668
|
|
result =
|
|
path: @session.backing_track_path
|
|
result
|
|
|
|
jamTracks: () ->
|
|
if @session && @session.jam_track
|
|
@session.jam_track.tracks.filter((track)->
|
|
track.track_type == 'Track'
|
|
)
|
|
else
|
|
null
|
|
|
|
jamTrackMixdown: () ->
|
|
{ id: @session?.jam_track?.mixdown.id }
|
|
|
|
jamTrackName: () ->
|
|
@session?.jam_track?.name
|
|
|
|
recordedJamTracks:() ->
|
|
if @session && @session.claimed_recording
|
|
@session.claimed_recording.recording.recorded_jam_track_tracks
|
|
else
|
|
null
|
|
|
|
recordedJamTrackName: () ->
|
|
jam_track = @session?.claimed_recording?.recording?.jam_track
|
|
|
|
if jam_track? then jam_track.name else null
|
|
|
|
recordingName: () ->
|
|
@session?.claimed_recording?.name
|
|
|
|
getParticipant: (clientId) ->
|
|
found = null
|
|
for participant in @participants()
|
|
if participant.client_id == clientId
|
|
found = participant
|
|
break
|
|
|
|
logger.warn('unable to find participant with clientId: ' + clientId) unless found
|
|
found
|
|
|
|
id: () ->
|
|
@session.id |