Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Commit

Permalink
Adds twitch support
Browse files Browse the repository at this point in the history
Resolves #13139

Auditors:

Test Plan:
  • Loading branch information
NejcZdovc committed Feb 23, 2018
1 parent 989a53e commit b0738dc
Show file tree
Hide file tree
Showing 13 changed files with 647 additions and 60 deletions.
23 changes: 19 additions & 4 deletions app/browser/api/ledger.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ const getPublisherData = (result, scorekeeper) => {
verified: result.options.verified || false,
exclude: result.options.exclude || false,
publisherKey: result.publisherKey,
providerName: result.providerName,
siteName: result.publisherKey,
views: result.visits,
duration: duration,
Expand Down Expand Up @@ -1387,7 +1388,7 @@ const roundtrip = (params, options, callback) => {
: typeof params.server !== 'undefined' ? params.server
: typeof options.server === 'string' ? urlParse(options.server) : options.server
const binaryP = options.binaryP
const rawP = binaryP || options.rawP
const rawP = binaryP || options.rawP || options.scrapeP

if (!params.method) params.method = 'GET'
parts = underscore.extend(underscore.pick(parts, ['protocol', 'hostname', 'port']),
Expand Down Expand Up @@ -2399,10 +2400,15 @@ const onMediaRequest = (state, xhr, type, tabId) => {

const parsed = ledgerUtil.getMediaData(xhr, type)
const mediaId = ledgerUtil.getMediaId(parsed, type)

if (mediaId == null) {
return state
}

const mediaKey = ledgerUtil.getMediaKey(mediaId, type)
let duration = ledgerUtil.getMediaDuration(parsed, type)
let duration = ledgerUtil.getMediaDuration(state, parsed, mediaKey, type)

if (mediaId == null || duration == null || mediaKey == null) {
if (duration == null || mediaKey == null) {
return state
}

Expand All @@ -2422,9 +2428,14 @@ const onMediaRequest = (state, xhr, type, tabId) => {
currentMediaKey = mediaKey
}

const stateData = ledgerUtil.generateMediaCacheData(parsed, type)
const cache = ledgerVideoCache.getDataByVideoId(state, mediaKey)

if (!cache.isEmpty()) {
if (!stateData.isEmpty()) {
state = ledgerVideoCache.mergeCacheByVideoId(state, mediaKey, stateData)
}

const publisherKey = cache.get('publisher')
const publisher = ledgerState.getPublisher(state, publisherKey)
if (!publisher.isEmpty() && publisher.has('providerName')) {
Expand All @@ -2436,6 +2447,10 @@ const onMediaRequest = (state, xhr, type, tabId) => {
}
}

if (!stateData.isEmpty()) {
state = ledgerVideoCache.setCacheByVideoId(state, mediaKey, stateData)
}

const options = underscore.extend({roundtrip: module.exports.roundtrip}, clientOptions)
const mediaProps = {
mediaId,
Expand Down Expand Up @@ -2513,7 +2528,7 @@ const onMediaPublisher = (state, mediaKey, response, duration, revisited) => {
.set('publisher', publisherKey)

// Add to cache
state = ledgerVideoCache.setCacheByVideoId(state, mediaKey, cacheObject)
state = ledgerVideoCache.mergeCacheByVideoId(state, mediaKey, cacheObject)

state = module.exports.saveVisit(state, publisherKey, {
duration,
Expand Down
19 changes: 18 additions & 1 deletion app/common/cache/ledgerVideoCache.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,24 @@ const setCacheByVideoId = (state, key, data) => {
return state.setIn(['cache', 'ledgerVideos', key], data)
}

const mergeCacheByVideoId = (state, key, data) => {
state = validateState(state)

if (key == null || data == null) {
return state
}

data = makeImmutable(data)

if (data.isEmpty()) {
return state
}

return state.mergeIn(['cache', 'ledgerVideos', key], data)
}

module.exports = {
getDataByVideoId,
setCacheByVideoId
setCacheByVideoId,
mergeCacheByVideoId
}
3 changes: 2 additions & 1 deletion app/common/constants/ledgerMediaProviders.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
* You can obtain one at http://mozilla.org/MPL/2.0/. */

const providers = {
YOUTUBE: 'youtube'
YOUTUBE: 'youtube',
TWITCH: 'twitch'
}

module.exports = providers
12 changes: 12 additions & 0 deletions app/common/constants/twitchEvents.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

const events = {
MINUTE_WATCHED: 'minute-watched',
START: 'video-play',
PLAY_PAUSE: 'player_click_playpause',
SEEK: 'vod_seek'
}

module.exports = events
Loading

0 comments on commit b0738dc

Please sign in to comment.