AbstractChannelService

AbstractChannelService ⇐ Abstract

Kind: global abstract class
Extends: Abstract
Mixes: MFavoritesAndBlockedList, MServiceCache
Service:

AbstractChannelService()

This class represents the service that handles the channels.

newChannel(properties) ⇒ AbstractChannel

Create a new channel model. It is preferred to use this method instead of using new $Channel(), as this method will always create the model with the right implementation.

Kind: instance method of AbstractChannelService
Returns: AbstractChannel - The channel model

ParamTypeDescription
propertiesObject

The model of properties

setCurrentChannelListId(listId, [type], [options]) ⇒ Promise.<Object, Error>

Change the current list.

Kind: instance method of AbstractChannelService
Returns: Promise.<Object, Error> - Returns a promise resolved with {listId:listId, type:listType} or rejected if the list does not exist
Emits: channelListChange

ParamTypeDescription
listIdstring

A predefined list identifier or a favorite list identifier

[type]number

The channel type. See: $Channel.XXX_TYPE

[options]Object

Additional options

[options.skipNotify]boolean

If true do not fire the onChannelListChange event

getCurrentChannelListId() ⇒ Promise.<Object, Error>

Get the current list identifier.

Kind: instance method of AbstractChannelService
Returns: Promise.<Object, Error> - Returns a promise resolved with {id:listId, type:listType}

getChannelList([options]) ⇒ Promise.<ChannelList, Error>

Get the channels of the current channel list, sorted by LCN. You can use the listId option to get a the channel of a specific list.

Kind: instance method of AbstractChannelService
Returns: Promise.<ChannelList, Error> - A promise resolved with an array of channels or rejected in case of problem

ParamTypeDefaultDescription
[options]Object

Additional options

[options.type]number

The type of channel to look for, such as $Channel.TV_TYPE or $Channel.Radio_TYPE. If omitted, any type will match.

[options.force]booleanfalse

If true, don't use the value stored in the cache

[options.listId]stringnull

If set, it gets a channel on a specific list

[options.sort]function$ChannelService.byNumberComparator

If a function is specified, will sort the list by channel numbers

[options.duration]number

Duration in milliseconds before invalidation of cache (if null, $$maxAge value is used by default)

find(filterFunction, [options]) ⇒ Promise.<Array.<AbstractChannel>, Error>

Find channel(s) using a function as filter.

Kind: instance method of AbstractChannelService
Returns: Promise.<Array.<AbstractChannel>, Error> - A promise (channel(s), error)

ParamTypeDefaultDescription
filterFunctionfunction | null

A function that takes a channel in arg and return true or false (true mean keep channel)

[options]Object

Additional options

[options.force]booleanfalse

If true, don't use the value stored in the cache

[options.listId]stringnull

If set, it gets a channel on a specific list

getTVChannelList([options]) ⇒ Promise.<Array.<AbstractChannel>>

Get the list of TV channels, sorted by LCN (i.e. logical channel number).

Kind: instance method of AbstractChannelService

ParamTypeDefaultDescription
[options]Object

Additional options

[options.force]booleanfalse

If true, don't use the value stored in the cache

[options.listId]stringnull

If set, it gets a channel on a specific list

getRadioChannelList([options]) ⇒ Promise.<Array.<AbstractChannel>>

Get the list of radio channels, sorted by LCN (i.e. logical channel number).

Kind: instance method of AbstractChannelService

ParamTypeDefaultDescription
[options]Object

Additional options

[options.force]booleanfalse

If true, don't use the value stored in the cache

[options.listId]stringnull

If set, it gets a channel on a specific list

getApplicationChannelList([options]) ⇒ Promise.<Array.<AbstractChannel>>

Get the list of application channels, sorted by LCN (i.e. logical channel number).

Kind: instance method of AbstractChannelService

ParamTypeDefaultDescription
[options]Object

Additional options

[options.force]booleanfalse

If true, don't use the value stored in the cache

[options.listId]stringnull

If set, it gets a channel on a specific list

getOtherChannelList([options]) ⇒ Promise.<Array.<AbstractChannel>>

Get the list of other channels (neither TV nor radio), sorted by LCN (i.e. logical channel number).

Kind: instance method of AbstractChannelService

ParamTypeDefaultDescription
[options]Object

Additional options

[options.force]booleanfalse

If true, don't use the value stored in the cache

[options.listId]stringnull

If set, it gets a channel on a specific list

getFavoriteList(favoriteListId, [options]) ⇒ Promise.<Array.<AbstractChannel>, Error>

Get the favorite list by its identifier

Kind: instance method of AbstractChannelService
Returns: Promise.<Array.<AbstractChannel>, Error> - A promise resolved with an array of channels or rejected in case of problem

ParamTypeDefaultDescription
favoriteListIdstring

The identifier of the favorite

[options]Object

Additional options

[options.type]number

The type of channel to look for, such as $Channel.TV_TYPE or $Channel.Radio_TYPE. If omitted, any type will match.

[options.force]booleanfalse

If true, don't use the value stored in the cache

[options.sort]function$ChannelService.byNumberComparator

If a function is specified, will sort the list by channel numbers

getBlockedList([options]) ⇒ Promise.<Array.<AbstractChannel>, Error>

Get all the blocked channels of a given type (TV or RADIO)

Kind: instance method of AbstractChannelService
Returns: Promise.<Array.<AbstractChannel>, Error> - A promise resolved with an array of channels or rejected in case of problem

ParamTypeDefaultDescription
[options]Object

Additional options

[options.type]number

The type of channel to look for, such as $Channel.TV_TYPE or $Channel.Radio_TYPE. If omitted, any type will match.

[options.force]booleanfalse

If true, don't use the value stored in the cache

[options.sort]function$ChannelService.byNumberComparator

If a function is specified, will sort the list by channel numbers

getChannel(id, [options]) ⇒ Promise.<AbstractChannel>

Get a channel by its identifier. The channel must belong to the list.

Kind: instance method of AbstractChannelService
Returns: Promise.<AbstractChannel> - A promise resolved with the channel data (or undefined if not found).

ParamTypeDefaultDescription
idstring

The channel identifier

[options]Object

Additional options

[options.type]number

The type of channel to look for, such as $Channel.TV_TYPE or $Channel.Radio_TYPE. If omitted, any type will match.

[options.force]booleanfalse

If true, it refreshes the channel list (i.e. renew the cache)

[options.listId]stringnull

If set, it gets a channel on a specific list

getPreferredChannel() ⇒ Promise.<AbstractChannel, Error>

Get a preferred channel

Kind: instance method of AbstractChannelService
Returns: Promise.<AbstractChannel, Error> - A promise resolved a channel or rejected in case of problem

getNextChannel(channel, [options]) ⇒ Promise.<AbstractChannel, Error>

Get the channel after a given one.

Kind: instance method of AbstractChannelService
Returns: Promise.<AbstractChannel, Error> - A promise (next channel object, error).

ParamTypeDefaultDescription
channelnumber | AbstractChannel

The reference channel number or object. If a number is given, it does not have to exist in the channel list.

[options]Object
[options.type]number

The type of channel to look for, such as $Channel.TV_TYPE or $Channel.Radio_TYPE. If omitted, any type will match.

[options.cyclic]booleantrue

Whether or not to loop at the end of the channel list.

[options.force]booleanfalse

If true, it refreshes the channel list (i.e. renew the cache)

[options.listId]stringnull

If set, it gets a channel on a specific list

getPreviousChannel(channel, [options]) ⇒ Promise.<AbstractChannel, Error>

Get the channel before a given one.

Kind: instance method of AbstractChannelService
Returns: Promise.<AbstractChannel, Error> - A promise (next channel object, error).

ParamTypeDefaultDescription
channelnumber | AbstractChannel

The reference channel number or object. If a number is given, it does not have to exist in the channel list.

[options]object
[options.type]number

The type of channel to look for, such as $Channel.TV_TYPE or $Channel.Radio_TYPE. If omitted, any type will match.

[options.cyclic]booleantrue

Whether or not to loop at the beginning of the channel list.

[options.force]booleanfalse

If true, it refreshes the channel list (i.e. renew the cache)

[options.listId]stringnull

If set, it gets a channel on a specific list

getNearestChannel(channel, [options]) ⇒ AbstractChannel

Returns the closest channel by number.

Kind: instance method of AbstractChannelService
Returns: AbstractChannel - channel, or undefined if the channel list was empty.

ParamTypeDefaultDescription
channelnumber | AbstractChannel

the reference channel, or its number.

[options]object
[options.type]number

The type of channel to look for, such as $Channel.TV_TYPE or $Channel.Radio_TYPE. If omitted, any type will match.

[options.cyclic]booleantrue

Whether or not to loop at the beginning and the end of the channel list.

[options.listId]stringnull

If set, get channel on a specific list

[options.strategy]"round" | "floor" | "ceil""round"

If given, define the strategy to adopt to search through the channel list

[options.channelList]Array.<AbstractChannel>

If set, gives the channel list through which the search should be made

getChannelByNumber(number, [options]) ⇒ Promise.<AbstractChannel, Error>

Get channel by its number

Kind: instance method of AbstractChannelService
Returns: Promise.<AbstractChannel, Error> - a promise

ParamTypeDefaultDescription
numbernumber

Number of the channel (integer)

[options]object
[options.type]number

The type of channel to look for, such as $Channel.TV_TYPE or $Channel.Radio_TYPE. If omitted, any type will match.

[options.force]booleanfalse

If true, refresh the channel list (ie renew the cache)

[options.listId]stringnull

If set, get channel on a specific list

_newChannel(properties) ⇒ *

Kind: instance abstract method of AbstractChannelService

ParamType
propertiesObject

_getAllList([options]) ⇒ Promise.<Array.<AbstractChannel>, Error>

Vendor implementation to get the list that contains all channels

⚠ WARNING: DON’T FORGET TO MARK THE CHANNELS BLOCKED WITH THE isUserBlocked PROPERTY !!!

Kind: instance abstract method of AbstractChannelService
Returns: Promise.<Array.<AbstractChannel>, Error> - A promise resolved with an array of channels or rejected in case of problem

ParamTypeDescription
[options]Object

Additional options

_reload([options]) ⇒ Promise.<boolean, error>

Default implementation to reload the list. (By default, it invalidates the cache)

Kind: instance method of AbstractChannelService
Returns: Promise.<boolean, error> - A promise resolved to true if the list have been reloaded

ParamTypeDefaultDescription
[options]Object

Additional options

[options.listId]stringnull

If set, it reloads a specific channel list otherwise it invalidates the current channel list

_getPreferredChannel() ⇒ Promise.<AbstractChannel, Error>

Vendor implementation to get the preferred channel

Kind: instance abstract method of AbstractChannelService
Returns: Promise.<AbstractChannel, Error> - A promise resolved a channel or rejected in case of problem

_getChannel(id, channelList) ⇒ Channel | Promise.<Channel, Error>

Given the channelList, this method gets the channel by its identifier.

Kind: instance method of AbstractChannelService
Returns: Channel | Promise.<Channel, Error> - the found channel, null otherwise
Access: protected

ParamTypeDescription
idstring

the channel id

channelListChannelList

the channel list

invalidateCache([options]) ⇒ Promise

Invalidate the cache forcing the next call to getChannelList to refresh the list from the vendor

Kind: instance method of AbstractChannelService

ParamTypeDefaultDescription
[options]Object

Additional options

[options.listId]stringnull

If set invalidate a specific channel list, else invalidate the current channel list

reload([options]) ⇒ Promise.<boolean, error>

Reload the list (i.e. check if there is an update and re-new the cache)

Kind: instance method of AbstractChannelService
Returns: Promise.<boolean, error> - A promise resolved to true if the list have been reloaded

ParamTypeDefaultDescription
[options]Object

Additional options

[options.listId]stringnull

If set invalidate a specific channel list, else invalidate the current channel list

_onChannelListChange(newChannelListDef, oldChannelListDef) ⇒ Promise

Kind: instance method of AbstractChannelService
Access: protected

ParamType
newChannelListDefArray.<AbstractChannel>
oldChannelListDefArray.<AbstractChannel>

“channelListChange” (newChannelListDef, oldChannelListDef)

Fired when the current list has been changed

Kind: event emitted by AbstractChannelService

ParamTypeDescription
newChannelListDefObject

The new list {listId:listId, type:listType}

oldChannelListDefObject

The old list {listId:listId, type:listType}

ALL_CHANNEL_LIST_ID : string

List of all channels identifiers

Kind: static constant of AbstractChannelService

BLOCKED_CHANNEL_LIST_ID : string

List of blocked channels identifiers

Kind: static constant of AbstractChannelService

byNumberComparator(a, b) ⇒ number

A Comparator that can be used to compare two channels by their channels number

Kind: static method of AbstractChannelService

ParamType
aChannel
bChannel

byTypeFilter(type) ⇒ function

Return a closure to be used in find for filtering channels by type

Kind: static method of AbstractChannelService
Returns: function - The callback to be used in find

ParamTypeDescription
typenumber

The channel type. See: $Channel.XXX_TYPE

Example

$ChannelService.getInstance().find($ChannelService.byTypeFilter($Channel.TV_TYPE)); // the list of current TV channels