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

Adds twitch support #13142

Merged
merged 1 commit into from
Feb 23, 2018
Merged

Adds twitch support #13142

merged 1 commit into from
Feb 23, 2018

Conversation

NejcZdovc
Copy link
Contributor

@NejcZdovc NejcZdovc commented Feb 14, 2018

Resolves #13139

Submitter Checklist:

  • Submitted a ticket for my issue if one did not already exist.
  • Used Github auto-closing keywords in the commit message.
  • Added/updated tests for this change (for new code or code which already has tests).
  • Ran git rebase -i to squash commits (if needed).
  • Tagged reviewers and labelled the pull request as needed.
  • Request a security/privacy review as needed. (Ask a Brave employee to help if you cannot access this document.)

Test Plan:

Reviewer Checklist:

  • Request a security/privacy review as needed if one was not already requested.

Tests

  • Adequate test coverage exists to prevent regressions
  • Tests should be independent and work correctly when run individually or as a suite ref
  • New files have MPL2 license header

@codecov-io
Copy link

codecov-io commented Feb 14, 2018

Codecov Report

Merging #13142 into master will increase coverage by 0.14%.
The diff coverage is 86.77%.

@@            Coverage Diff             @@
##           master   #13142      +/-   ##
==========================================
+ Coverage   55.93%   56.07%   +0.14%     
==========================================
  Files         281      282       +1     
  Lines       27856    28017     +161     
  Branches     4571     4602      +31     
==========================================
+ Hits        15580    15711     +131     
- Misses      12276    12306      +30
Flag Coverage Δ
#unittest 56.07% <86.77%> (+0.14%) ⬆️
Impacted Files Coverage Δ
app/filtering.js 18% <0%> (+0.08%) ⬆️
app/common/constants/twitchEvents.js 100% <100%> (ø)
app/common/constants/ledgerMediaProviders.js 100% <100%> (ø) ⬆️
app/browser/api/ledger.js 58.68% <66.66%> (-0.11%) ⬇️
...erer/components/preferences/payment/ledgerTable.js 86.05% <84.61%> (-0.45%) ⬇️
app/common/cache/ledgerVideoCache.js 95.45% <86.66%> (-4.55%) ⬇️
app/common/lib/ledgerUtil.js 94.1% <91.97%> (-2.18%) ⬇️
js/stores/appStoreRenderer.js 91.66% <0%> (-8.34%) ⬇️
app/renderer/components/reduxComponent.js 57.75% <0%> (-3.45%) ⬇️
js/stores/windowStore.js 27.65% <0%> (-0.3%) ⬇️
... and 4 more

@NejcZdovc NejcZdovc added this to the 0.21.x (Beta Channel) milestone Feb 15, 2018
@NejcZdovc
Copy link
Contributor Author

blocked on brave-intl/bat-publisher#12

// Twitch
if (
(
(firstPartyUrl && firstPartyUrl.startsWith('https://www.twitch.tv')) ||
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

food for thought- with more integrations being added, it might make sense to move the URLs into ledgerMediaProviders.js. That module could then export:

  • type (ex: YOUTUBE, TWITCH)
  • providerUrls (indexed by type)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this url's are used only here, so I wouldn't add it into the providers

{
if (
(
data.event === 'minute-watched' ||
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these events would be great to put into a module (so it could work like an enum); ex: twitchEvents.MINUTE_WATCHED

Copy link
Member

@bsclifton bsclifton Feb 22, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

another way you could do this:
if (['minute-watched', 'video-play', 'player_click_playpause', 'vod_seek'].includes(data.event))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added new syntax

const previousData = ledgerVideoCache.getDataByVideoId(state, mediaKey)

if (previousData.isEmpty() && data.event === 'video-play') {
return milliseconds.second * 10
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this (and the magic number 10 below) might be better expressed as a constant; like twitchMinimumSeconds (or something like this). For readability and also so it's easy to change both (if needed)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

return milliseconds.second * 10
}

if (!data.properties) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be moved up to the initial check? ex:
if (data == null || mediaKey == null || !data.properties) {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can, done

}

// we get seconds back, so we need to convert it into ms
time = time * 1000
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for readability, you can use milliseconds.second instead of 1000 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

})
}

const getMediaFavicon = (providerName) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would this be better named as getDefaultMediaFavicon, since it would only be used when one is not present (ex: when watching live stream on Twitch)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Member

@bsclifton bsclifton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment left 😄 Overall- awesome job! Works extremely well

Initial findings:

NOT TWITCH SPECIFIC (existing bug)
When criteria is met, publisher button (to right of URL bar) doesn't become clickable to include. You mentioned this would be fixed though w/ next version

@diracdeltas
Copy link
Member

so do you still need the Twitch scraper in https://github.com/brave-intl/bat-publisher/blob/master/getMedia.js#L182 ? if not let's revert it.

@NejcZdovc
Copy link
Contributor Author

@diracdeltas we are not using scraper for Twitch. We skip it here https://github.com/brave-intl/bat-publisher/blob/master/getMedia.js#L151

// Twitch
if (
(
(firstPartyUrl && firstPartyUrl.startsWith('https://www.twitch.tv')) ||
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this origin check can be spoofed, e.g. by a request to 'https://www.twitch.tv.evil.com'. you probably want to add a trailing slash or do a proper URL parse.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

if (
(
(firstPartyUrl && firstPartyUrl.startsWith('https://www.twitch.tv')) ||
(referrer && referrer.startsWith('https://player.twitch.tv'))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

(firstPartyUrl && firstPartyUrl.startsWith('https://www.twitch.tv')) ||
(referrer && referrer.startsWith('https://player.twitch.tv'))
) &&
url.startsWith('https://api.mixpanel.com')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

app/filtering.js Outdated
// this can happen if the tab is closed and the webContents is no longer available
if (!firstPartyUrl) {
muonCb({ cancel: true })
return
}

if (module.exports.isResourceEnabled('ledger') && module.exports.isResourceEnabled('ledgerMedia')) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

curious why this was moved

Copy link
Member

@diracdeltas diracdeltas Feb 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also this should check !isPrivate. i know it checks for a private tab state later in the ledger reducer, but can't hurt to do it here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added private check

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this block was moved, because we need to get data from mixpanel which is blocked on our side and we need to get data first and then block it

Copy link
Member

@diracdeltas diracdeltas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bsclifton
bsclifton previously approved these changes Feb 23, 2018
Copy link
Member

@bsclifton bsclifton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested again after updates per code review. Works great! Made sure to try Twitch in a private tab and confirmed nothing is recorded. Nice job 😄

Resolves brave#13139

Auditors:

Test Plan:
@@ -93,6 +93,7 @@ AppStore
ledgerVideos: {
[mediaKey]: {
publisher: string // publisher key
beatData: object // data that we get from a heartbeat
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where is this set?

@diracdeltas diracdeltas dismissed their stale review February 23, 2018 06:34

comments addressed

@bsclifton bsclifton merged commit e1738ad into brave:master Feb 23, 2018
@bsclifton
Copy link
Member

bsclifton commented Feb 23, 2018

master e1738ad

@NejcZdovc can you help me cherry-pick into 0.22.x and 0.21.x?

NejcZdovc pushed a commit that referenced this pull request Feb 23, 2018
NejcZdovc pushed a commit that referenced this pull request Feb 23, 2018
@NejcZdovc
Copy link
Contributor Author

0.22 33c7601
0.21 0f77c26

@NejcZdovc NejcZdovc modified the milestones: 0.21.x (Beta Channel), 0.21.x (Twitch) Feb 24, 2018
NejcZdovc pushed a commit that referenced this pull request Feb 24, 2018
@NejcZdovc
Copy link
Contributor Author

0.21 twitch d39cb3c

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants