Created
June 28, 2017 16:15
-
-
Save rtmalone/594fe676b0f3c8ba4c1a9298755c3143 to your computer and use it in GitHub Desktop.
invite/share
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const _location = window.location | |
| const uAgent = window.navigator.userAgent.toLowercase() | |
| const query = <grab the query params according to your code base> | |
| if (uAgent.match(/iphone|ipod|ipad/i)) { | |
| handleIOS(location, query) | |
| } else if (uAgent.match(/android/i)) { | |
| handleAndroid(location, query) { | |
| } else { | |
| <User is on a desktop; I just logged a message to the console> | |
| } | |
| handleIOS(location, query) { | |
| // using a npm package as 'cookie' | |
| const _cookie = cookie.load(<some identifier>); | |
| if ( _cookie ) { | |
| if (_cookie.cid) { | |
| location.assign = `rabbletv:invite?conversationId=${_cookie.cid}`; | |
| } else { | |
| location.assign = `rabbletv:invite?userId=${_cookie.uid}`; | |
| } | |
| } else if (!_cookie && query.isChecking) { | |
| return; | |
| } else { | |
| cookie.save('rabbleInvite', query, {maxAge: (24 * 60 * 60)}); | |
| location.assign('https://itunes.apple.com/us/app/rabbletv/id960082861'); | |
| } | |
| } | |
| handleAndroid(location, query) { | |
| let psQuery; | |
| if (query.cid && query.uid) { | |
| psQuery = 'conversationId=' + query.cid + '&userId=' + query.uid; | |
| } else if (query.conversationId) { | |
| psQuery = 'conversationId=' + query.cid; | |
| } | |
| if (psQuery) { | |
| location.assign('https://play.google.com/store/apps/details?id=tv.rabble.rabbletv&referrer=' + encodeURIComponent(psQuery)); | |
| } else { | |
| location.assign('https://play.google.com/store/apps/details?id=tv.rabble.rabbletv'); | |
| } | |
| } | |
| // SHARE | |
| ////////////////////////////////////// | |
| // In React I was setting a Mobile flag on the component state once before mounting | |
| const uAgent = global.navigator.userAgent; | |
| this.setState(() => { | |
| let _isMobile = null; | |
| if (uAgent.match(/iphone|ipod|ipad|andriod/i)) { | |
| _isMobile = true; | |
| } else { | |
| _isMobile = false; | |
| } | |
| return {isMobile: _isMobile}; | |
| }); | |
| // once mounted... | |
| const location = window.location; | |
| const query = <grab the query params> | |
| cookie.save('rabbleShare', query, {maxAge: (24 * 60 * 60)}); | |
| if (this.state.isMobile && this.state.uAgent.match(/iphone|ipod|ipad/i)) { | |
| this.handleIOS(location); | |
| } else if (this.state.isMobile && this.state.uAgent.match(/andriod/i)) { | |
| this.handleAndroid(location, query); | |
| } else { | |
| console.info('You must be on a non-mobile device'); | |
| } | |
| handleIOS(location) { | |
| const { _cookie } = cookie.load('rabbleShare'); | |
| if (_cookie.broadcast_id || _cookie.user_id) { | |
| location.assign = `https://rabble.tv/conversation/${_cookie.cid}`; | |
| } else { | |
| location.assign('https://itunes.apple.com/us/app/rabbletv/id960082861'); | |
| } | |
| } | |
| handleAndroid(location, query) { | |
| let psQuery; | |
| if (query.broadcastId) { | |
| psQuery = 'broadcastId=' + query.broadcastId; | |
| } else if (query.userId) { | |
| psQuery = 'userId=' + query.userId; | |
| } | |
| if (psQuery) { | |
| location.assign('https://play.google.com/store/apps/details?id=tv.rabble.rabbletv&referrer=' + encodeURIComponent(psQuery)); | |
| } else { | |
| location.assign('https://play.google.com/store/apps/details?id=tv.rabble.rabbletv'); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment