Skip to content

Commit

Permalink
Deeplink: add micropage path support for v2 (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
pyby authored Feb 27, 2024
1 parent 5830706 commit 49cdcbe
Show file tree
Hide file tree
Showing 4 changed files with 155 additions and 52 deletions.
52 changes: 52 additions & 0 deletions docs/DEEP_LINK.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
Playfff - Deeplink
=============

## About

Playfff is the middleware to help Play SRG mobile applications understanding Play web urls.

## Compatibility

* [Since July 2019](https://github.com/SRGSSR/playsrg-playfff/releases/tag/13), Play iOS applications download `parsePlayUrl.js` v1 file.
* [Since September 2019](https://github.com/SRGSSR/playsrg-playfff/releases/tag/17), Play Android and Play iOS applications download `parsePlayUrl.js` v2 file.

## Convert a web url to application url

The conversion is done with a javascript function, included in the `parsePlayUrl.js` file. The file is downloaded with [the GET API](README.md#deep-link).

### V1

Function is: `parseForPlayApp(scheme, hostname, pathname, queryParams, anchor)`:

* Parameters: the web url to parse, splitted in variables.
* It returns an application url, conform to [an old Play iOS application URL](https://github.com/SRGSSR/playsrg-apple/blob/ios/2.9.5-313/docs/URL_SCHEMES.md) specification.

### V2

Function is: `parseForPlayApp(scheme, hostname, pathname, queryParams, anchor, supportedAppHostnames)`:

* Parameters: the web url to parse, splitted in variables.
* `supportedAppHostnames`: an optional array to share the supported application url hostnames. Required to support the new `micropage` hostname conversion.
* It returns an application url, conform to [Play iOS application URL](https://github.com/SRGSSR/playsrg-apple/blob/develop/docs/CUSTOM_URLS_AND_UNIVERSAL_LINKS.md) and [Play Android custom URL](https://github.com/SRGSSR/playsrg-android/blob/main/doc/schemeUrl.md) specifications.
* If the JS script returns the `unsupported` hostname, the application can share it to the server using [the POST API](README.md#deep-link).

## Get updated

The server pulls IL every 5 minutes to have updated contents (topics).

* Topic list requests: IL `/integrationlayer/2.0/[BU]/topicList/tv`.
* Topic title are converted to *SeoName* value [used by the Play web application](https://github.com/SRGSSR/playsrg-playfff/issues/46) for topic urls.

## How to test

Curently, unit tests are a on private repository, accessible via a public url:

* [Tests v1](https://play-mmf.herokuapp.com/deeplink/tests/v1/index.html)
* [Tests V2](https://play-mmf.herokuapp.com/deeplink/tests/v2/index.html)

To test Play web url conversions, a tool is available:

* [Middleware Prod deeplink tool](https://play-mmf.herokuapp.com/deeplink/index.html)
* [Middleware Dev deeplink tool](https://play-mmf.herokuapp.com/deeplink/index.html#dev)
* [Old V1 deeplink tool](https://play-mmf.herokuapp.com/deeplink/index.html#localv1)
* [Next V2 version deeplink tool](http://play-mmf.herokuapp.com/deeplink/index.html#localv2)
2 changes: 2 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ A wide list of parameters are available.
* `jsVersion` (integer): the `parsePlayUrl.js` value of `parsePlayUrlVersion` variable.
* `url` (string): the unparsing url.

For more informations, see the [deep link documentation](DEEP_LINK.md).

#### Recommendation for a media

* `/api/v2/playlist/recommendation/continuousPlayback/{urn}` : get recommended medias for a continuous playback purpose.
Expand Down
39 changes: 23 additions & 16 deletions src/main/resources/deeplink/v1/parsePlayUrl.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// parsePlayUrl

var parsePlayUrlVersion = 39;
var parsePlayUrlVersion = 40;
var parsePlayUrlBuild = "mmf";

if (!console) {
Expand All @@ -10,7 +10,13 @@ if (!console) {
}

function parseForPlayApp(scheme, hostname, pathname, queryParams, anchor) {
originalPathname = pathname;
originalUrl = {
"scheme": scheme,
"hostname": hostname,
"pathname": pathname,
"queryParams": queryParams,
"anchor": anchor
};

// fix path issue
pathname = pathname.replace("//", "/");
Expand Down Expand Up @@ -124,7 +130,7 @@ function parseForPlayApp(scheme, hostname, pathname, queryParams, anchor) {
break;
}
if (redirectBu) {
return openURL(server, redirectBu, scheme, hostname, originalPathname, queryParams, anchor);
return openURL(server, redirectBu, originalUrl);
}
}

Expand Down Expand Up @@ -243,7 +249,7 @@ function parseForPlayApp(scheme, hostname, pathname, queryParams, anchor) {
*
* Ex: https://www.rts.ch/play/tv/redirect/detail/9938530
* Ex: https://www.srf.ch/play/tv/redirect/Detail/99f040e9-b1e6-4d7a-bc08-d5639d600aa1
* Ex: https://www.srf.ch/play/tv/redirect/detail/99f040e9-b1e6-4d7a-bc08-d5639d600aa1/
* Ex: https://www.srf.ch/play/tv/redirect/detail/99f040e9-b1e6-4d7a-bc08-d5639d600aa1/
*/
switch (true) {
case pathname.includes("/tv/redirect/detail/"):
Expand Down Expand Up @@ -732,7 +738,7 @@ function parseForPlayApp(scheme, hostname, pathname, queryParams, anchor) {
}

/**
* Catch play help urls
* Catch help page urls
*
* Ex: https://www.srf.ch/play/tv/hilfe
* Ex: https://www.srf.ch/play/tv/hilfe/geoblock
Expand All @@ -748,22 +754,22 @@ function parseForPlayApp(scheme, hostname, pathname, queryParams, anchor) {
* Ex: playsrf://www.srf.ch/play/tv/hilfe
*/
if (pathname.endsWith("/hilfe") || pathname.includes("/hilfe/") || pathname.endsWith("/aide") || pathname.includes("/aide/") || pathname.endsWith("/guida") || pathname.includes("/guida/") || pathname.endsWith("/agid") || pathname.includes("/agid/") || pathname.endsWith("/help") || pathname.includes("/help/")) {
return openURL(server, bu, scheme, hostname, originalPathname, queryParams, anchor);
return openURL(server, bu, originalUrl);
}

/**
* Catch play micro pages urls
* Catch micro page urls
*
* Ex: https://www.srf.ch/play/tv/micropages/test-?pageId=3c2674b9-37a7-4e76-9398-bb710bd135ee
*
* Ex: playsrf://www.srf.ch/play/tv/micropages/test-?pageId=3c2674b9-37a7-4e76-9398-bb710bd135ee
*/
if (pathname.includes("/micropages/")) {
return openURL(server, bu, scheme, hostname, originalPathname, queryParams, anchor);
return openURL(server, bu, originalUrl);
}

/**
* Catch play parameters urls
* Catch parameters page urls
*
* Ex: https://www.srf.ch/play/tv/einstellungen
* Ex: https://www.rts.ch/play/tv/parametres
Expand Down Expand Up @@ -861,7 +867,8 @@ function openPage(server, bu, page, channelId, options) {
return redirect;
}

function openURL(server, bu, scheme, hostname, pathname, queryParams, anchor) {
function openURL(server, bu, originalUrl) {
var scheme = originalUrl.scheme;
if (!scheme) {
scheme = "http";
}
Expand All @@ -870,21 +877,21 @@ function openURL(server, bu, scheme, hostname, pathname, queryParams, anchor) {
}

var queryParamsString = "";
if (queryParams) {
for (var key in queryParams) {
queryParamsString = queryParamsString + "&" + key + "=" + encodeURIComponent(queryParams[key]);
if (originalUrl.queryParams) {
for (var key in originalUrl.queryParams) {
queryParamsString = queryParamsString + "&" + key + "=" + encodeURIComponent(originalUrl.queryParams[key]);
}
}
if (queryParamsString.length > 0) {
queryParamsString = queryParamsString.replace('&', '?');
}

var anchorString = "";
if (anchor) {
anchorString = "#" + anchor;
if (originalUrl.anchor) {
anchorString = "#" + originalUrl.anchor;
}

var url = scheme + "://" + hostname + pathname + queryParamsString + anchorString;
var url = scheme + "://" + originalUrl.hostname + originalUrl.pathname + queryParamsString + anchorString;

var redirect = schemeForBu(bu) + "://open?url=" + encodeURIComponent(url);
if (server) {
Expand Down
Loading

0 comments on commit 49cdcbe

Please sign in to comment.