success: function() {
                            YouTubeV3API.getSong({
                                songId: dataSource.get('id'),
                                success: function(song) {
                                    this.get(request.playlistId).get('items').addSongs(song);

                                    //  TODO: It would be nice to run this in addSongs not here to keep things more DRY.
                                    //  But I kind of feel like I need the playlist title when adding > 1 song (5 songs added to playlist XYZ) which forces it back to the playlist.
                                    Streamus.channels.backgroundNotification.commands.trigger('show:notification', {
                                        title: chrome.i18n.getMessage('songAdded'),
                                        message: song.get('title')
                                    });

                                    //  TODO: This responds success after fetching songs but not after the songs were actually added successfully.
                                    sendResponse({ result: 'success' });
                                }.bind(this),
                                error: function() {
                                    Streamus.channels.backgroundNotification.commands.trigger('show:notification', {
                                        title: chrome.i18n.getMessage('errorEncountered')
                                    });

                                    sendResponse({ result: 'error' });
                                }
                            });
                        }.bind(this),
Example #2
0
    _setResultsBySong: function(songId) {
      var pendingRequest = YouTubeV3API.getSong({
        songId: songId,
        success: this._trySetResults.bind(this),
        error: this._onSearchError.bind(this)
      });

      this.set('pendingRequest', pendingRequest);
    },
                success: function() {
                    YouTubeV3API.getSong({
                        songId: this.get('id'),
                        success: options.success,
                        error: function() {
                            Streamus.channels.backgroundNotification.commands.trigger('show:notification', {
                                title: chrome.i18n.getMessage('failedToFindSong')
                            });

                            if (options.error) {
                                options.error();
                            }
                        }
                    });
                }.bind(this)
        _onChromeRuntimeMessage: function(request, sender, sendResponse) {
            var sendAsynchronousResponse = false;

            switch (request.method) {
                case 'getPlaylists':
                    sendResponse({ playlists: this });
                    break;
                case 'addYouTubeSongByIdToPlaylist':
                    YouTubeV3API.getSong({
                        songId: request.songId,
                        success: function(song) {
                            this.get(request.playlistId).get('items').addSongs(song);

                            //  TODO: It would be nice to run this in addSongs not here to keep things more DRY.
                            //  But I kind of feel like I need the playlist title when adding > 1 song (5 songs added to playlist XYZ) which forces it back to the playlist.
                            Streamus.channels.backgroundNotification.commands.trigger('show:notification', {
                                title: chrome.i18n.getMessage('songAdded'),
                                message: song.get('title')
                            });

                            //  TODO: This responds success after fetching songs but not after the songs were actually added successfully.
                            sendResponse({ result: 'success' });
                        }.bind(this),
                        error: function() {
                            Streamus.channels.backgroundNotification.commands.trigger('show:notification', {
                                title: chrome.i18n.getMessage('errorEncountered')
                            });

                            sendResponse({ result: 'error' });
                        }
                    });

                    sendAsynchronousResponse = true;
                    break;
            }

            //  sendResponse becomes invalid when the event listener returns, unless you return true from the event listener to indicate you wish to send a response asynchronously (this will keep the message channel open to the other end until sendResponse is called).
            return sendAsynchronousResponse;
        },