Constructor
new queue(server, chanDB, channel)
Instantiates a new media queue for a given channel
Parameters:
| Name | Type | Description |
|---|---|---|
server |
channelManager | Parent server object |
chanDB |
Document | Related Channel Document from DB |
channel |
activeChannel | Parent Channel object for desired channel queue |
- Source:
Members
channel
Parent Chennel Object for desired channel queue
- Source:
liveMode
Current live-stream schedule mode
- Source:
liveRemainder
Media interrupted by current live-stream
- Source:
locked
Locks schedule upon admin request
- Source:
nextTimer
Next Media Timer
- Source:
nowPlaying
Currently Playing Media Item
- Source:
preSwitchDelta
Time before media switch to run pre-switch method call against next media
- Source:
preSwitchTimer
Next Media Pre-Switch Timer
- Source:
schedule
Map containing current schedule
- Source:
server
Parent Server Object
- Source:
streamLock
Locks scheduling functionality during livestreams
- Source:
syncDelta
Sync Delta in MS
- Source:
syncTimer
Syncronization Timer
- Source:
timestamp
Current Timestamp in Media
- Source:
Methods
(async) broadcastQueue(chanDB)
Broadcasts channel queue
Parameters:
| Name | Type | Description |
|---|---|---|
chanDB |
Mongoose.Document | Pass through Channel Document to save on DB Transactions |
- Source:
defineListeners(socket)
Defines server-side socket.io listeners for newly connected sockets
Parameters:
| Name | Type | Description |
|---|---|---|
socket |
Socket | Newly connected socket to define listeners against |
- Source:
(async) deleteMedia(socket, data)
Processes client requests to delete queued media
Parameters:
| Name | Type | Description |
|---|---|---|
socket |
Socket | Requesting socket |
data |
Object | Event payload |
- Source:
(async) deleteRange(socket, data)
Processes request to delete a range of media items from the queue
Parameters:
| Name | Type | Description |
|---|---|---|
socket |
Socket | Requesting socket |
data |
Object | Event payload |
- Source:
(async) end(quiet, noArchive, volatile, chanDB)
End currently playing media
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
quiet |
Boolean | false | Enable to prevent ending the media client-side |
noArchive |
Boolean | false | Enable to prevent ended media from being written to channel archive. Deletes media if Volatile is false |
volatile |
Boolean | false | Enable to prevent DB Transactions |
chanDB |
Mongoose.Document | Pass through Channel Document to save on DB Transactions |
- Source:
(async) endLivestream(wasPlaying, chanDB)
Ends running Livestream
Parameters:
| Name | Type | Description |
|---|---|---|
wasPlaying |
queuedMedia | Media object that was playing while we started the Livestream |
chanDB |
Mongoose.Document | Pass through Channel Document to save on DB Transactions |
- Source:
getItemAtEpoch(epoch) → {queuedMedia}
Gets a media item by epoch
Parameters:
| Name | Type | Description |
|---|---|---|
epoch |
Number | Date to check by JS Epoch (Millis) |
- Source:
Returns:
found media item
- Type
- queuedMedia
getItemByUUID(uuid) → {queuedMedia}
Get Scheduled Item by UUID
Parameters:
| Name | Type | Description |
|---|---|---|
uuid |
String | UUID of item to reschedule |
- Source:
Returns:
found item
- Type
- queuedMedia
getItemsBetweenEpochs(start, end, noUnfinished) → {queuedMedia}
Returns scheduled media between two given datetimes
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
start |
Number | Start date by JS Epoch (Millis) | |
end |
Number | End date by JS Epoch (Millis) | |
noUnfinished |
Boolean | false | Enable to include currently playing media |
- Source:
Returns:
Found Media Objects
- Type
- queuedMedia
getLastItem(epoch)
Gets last item from a given epoch
Parameters:
| Name | Type | Description |
|---|---|---|
epoch |
Number | Date to check by JS Epoch (Millis), defaults to now |
- Source:
Returns:
Last played item
getNextItem(epoch) → {queuedMedia}
Gets next item from a given epoch
Parameters:
| Name | Type | Description |
|---|---|---|
epoch |
Number | Date to check by JS Epoch (Millis), defaults to now |
- Source:
Returns:
Next item on the schedule
- Type
- queuedMedia
getStart(start)
Validates start times, and replaces bad ones with 5ms in the future
Parameters:
| Name | Type | Description |
|---|---|---|
start |
Number | Start time to validate by JS Epoch (millis) |
- Source:
Returns:
Start time as JS Epoch (millis)
(async) goLive(socket, data)
Handle client request to start an HLS live stream
Parameters:
| Name | Type | Description |
|---|---|---|
socket |
Socket | Requesting socket |
data |
Object | Event payload |
- Source:
(async) handleRawRefresh(mediaObj) → {queuedMedia}
Refreshes expired raw links before media plays
Parameters:
| Name | Type | Description |
|---|---|---|
mediaObj |
queuedMedia | Media object that's about to play |
- Source:
Returns:
passes through Media object with updated link upon success
- Type
- queuedMedia
(async) livestreamOverwriteSchedule(wasPlaying, chanDB)
Overwrites livestream over scheduled media content after it has ended
Parameters:
| Name | Type | Description |
|---|---|---|
wasPlaying |
queuedMedia | Media object that was playing while we started the Livestream |
chanDB |
Mongoose.Document | Pass through Channel Document to save on DB Transactions |
- Source:
(async) livestreamPushbackSchedule(wasPlaying, chanDB)
Pushes back any missed content scheduled during Livestream after Livestream has ended.
Parameters:
| Name | Type | Description |
|---|---|---|
wasPlaying |
queuedMedia | Media object that was playing while we started the Livestream |
chanDB |
Mongoose.Document | Pass through Channel Document to save on DB Transactions |
- Source:
(async) moveMedia(socket, data)
Processes request to move queued media item
Parameters:
| Name | Type | Description |
|---|---|---|
socket |
Socket | Requesting socket |
data |
Object | Event payload |
- Source:
(async) preSwitch(mediaObj)
Called 10 seconds before media begins to play
Parameters:
| Name | Type | Description |
|---|---|---|
mediaObj |
queuedMedia | Media object that's about to play |
- Source:
(async) prepQueue(chanDB)
Prepares channel queue for network transmission
Parameters:
| Name | Type | Description |
|---|---|---|
chanDB |
Mongoose.Document | Pass through Channel Document to save on DB Transactions |
- Source:
Returns:
de-hydrated scehdule information
(async) queueURL(socket, data)
Accepts new URL's to queue from the client
Parameters:
| Name | Type | Description |
|---|---|---|
socket |
Socket | Socket we're receiving the URL from |
data |
Object | Event payload |
- Source:
refreshNextTimer(volatile)
Calculates next item to play, and sets timer to play it at it's scheduled start
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
volatile |
Boolean | false | Disables DB Transactions if true |
- Source:
(async) rehydrateQueue(chanDB)
Rehydrates media schedule from DB
Parameters:
| Name | Type | Description |
|---|---|---|
chanDB |
Mongoose.Document | Pass through Channel Document to save on DB Transactions |
- Source:
(async) removeMedia(uuid, socket, chanDB, noScheduling) → {Media}
Removes a media item
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
uuid |
String | UUID of item to reschedule | |
socket |
Socket | Requesting Socket | |
chanDB |
Mongoose.Document | Channnel Document Passthrough to save on DB Access | |
noScheduling |
Boolean | false | Disables schedule timer refresh if true |
- Source:
Returns:
Deleted Media Item
- Type
- Media
(async) removeRange(start, end, socket, noUnfinished)
Removes range of media items from the queue
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
start |
Number | Start date by JS Epoch (millis) | |
end |
Number | End date by JS Epoch (millis) | |
socket |
Socket | Requesting Socket | |
noUnfinished |
Boolean | false | Set to true to include items that may be currently playing |
- Source:
(async) rescheduleMedia(uuid, start, socket, chanDB)
Reschedules a media item
Parameters:
| Name | Type | Description |
|---|---|---|
uuid |
String | UUID of item to reschedule |
start |
Number | New start time by JS Epoch (Millis) |
socket |
Socket | Requesting Socket |
chanDB |
Mongoose.Document | Channnel Document Passthrough to save on DB Access |
- Source:
(async) scheduleMedia(media, socket, chanDB, force, volatile, startVolatile, saveLate, noSave)
Schedules a Media Item
This is a fun method and I think it deserves it's own little explination...
Since we're working with a time based schedule, using start epochs as keys for our iterable seemed the best option
I don't want to store everything in a sparse array because that *feels* icky, and would probably be a pain in the ass.
Maps seem like a good choice, if it wheren't for the issue of keeping them ordered...
That's where this comes in. You see if we temporarily store it in a sparse array and convert into a map,
we can quickly and easily create a properly sorted schedule map that, out side of adding items, behaves normally.
Also a note on preformance:
While .forEach ONLY runs through populated items in sparse arrays, many JS implementations run through them in the background,
simply skipping them before executing the provided function. Looping through object.keys(arr), however, avoids this entirely,
since it ONLY loops through defiened items within the array. No skipped empties for your runtime to worry about.
Even more preformance benefits can be had by using a real for loop on the arrays keys, skipping the overhead of forEach entirely.
This might seem gross but it completely avoids the computational workload of a sorting algo, especially when you consider
that, no matter what, re-ordering the schedule map would've required us to iterate through and rebuild the map anyways...
Also it looks like due to implementation limitations, epochs stored as MS are too large for array elements, so we store them there as seconds.
This also means that our current implementation will break exactly on unix epoch 4294967295 (Feb 7, 2106 6:28:15 AM UTC)
Hopefully javascript arrays will allow for larger lengths by then. If not blame the W3C :P
If for some reason they haven't and we're not dead, we could probably implement an object that wraps a 2d array and set/gets it using modulo/devision/multiplication
Further Reading:
https://stackoverflow.com/questions/59480871/foreach-vs-object-keys-foreach-performance-on-sparse-arrays
https://community.appsmith.com/content/blog/dark-side-foreach-why-you-should-think-twice-using-it
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
media |
Media | Media item to schedule | |
socket |
Socket | Requesting Socket | |
chanDB |
Mongoose.Document | Channnel Document Passthrough to save on DB Access | |
force |
Boolean | false | Ignore certain conditions that would prevent scehduling and play the bitch anyways, used for internal function calls |
volatile |
Boolean | false | Prevent DB Writes, used for internal function calls |
startVolatile |
Boolean | false | Runs refreshNextTimer calls without DB writes, used for internal function calls |
saveLate |
Boolean | false | Saves items even if they're about to, or have already started. Used for internal function calls |
noSave |
Boolean | false | Allows function to edit Channel Document, but not save. Used for internal function calls in which the channel document is passed through, but will be saved immediatly after the scheduleMedia() call. |
- Source:
sendMedia(socket)
Send media update to a specific socket or broadcast it to the entire channel
Parameters:
| Name | Type | Description |
|---|---|---|
socket |
Socket | Requesting Socket |
- Source:
(async) start(mediaObj, timestamp, volatile)
Kicks off a media item
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
mediaObj |
queuedMedia | Media object that's about to play | |
timestamp |
Number | Media start timestamp in seconds | |
volatile |
Boolean | false | Disables DB Transactions |
- Source:
stop(socket)
Stops currently playing media item
Parameters:
| Name | Type | Description |
|---|---|---|
socket |
Socket | Requesting Socket |
- Source:
Returns:
returns false if there is nothing to stop
(async) stopMedia(socket)
Processes requests to stop currently playing media from client
Parameters:
| Name | Type | Description |
|---|---|---|
socket |
Socket | Socket we received the request from |
- Source:
(async) stopScheduleTimers(noArchive)
Clears and scheduling timers
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
noArchive |
Boolean | true | Disables Archiving |
- Source:
sync()
Sends a syncronization ping out to client Sockets and increments the tracked timestamp by the Synchronization Delta
Called auto-magically by the Synchronization Timer
- Source:
(async) toggleLock(socket)
Handle client request to (un)lock queue
Parameters:
| Name | Type | Description |
|---|---|---|
socket |
Socket | Requesting socket |
- Source: