Skip to content

Commit

Permalink
PLAYRTS-5611 Deeplink: Add root pages, pac preview pages (#100)
Browse files Browse the repository at this point in the history
  • Loading branch information
pyby authored Aug 19, 2024
1 parent b1fc4a8 commit 8315d45
Show file tree
Hide file tree
Showing 3 changed files with 176 additions and 43 deletions.
5 changes: 3 additions & 2 deletions docs/DEEP_LINK.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ Function is: `parseForPlayApp(scheme, hostname, pathname, queryParams, anchor)`:
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.
* `supportedAppHostnames`: an optional array to share the supported application url hostnames. Required to support the new `micropage` or `page` hostnames 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.
* An optional `preview=true` query parameter can be added to the returned application url. It's related to PAC (Play Application Configuration) and it's used to have a preview of the content page.
* 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
Expand All @@ -49,4 +50,4 @@ 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)
* [Next V2 version deeplink tool](http://play-mmf.herokuapp.com/deeplink/index.html#localv2)
71 changes: 59 additions & 12 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 = 42;
var parsePlayUrlVersion = 43;
var parsePlayUrlBuild = "mmf";

if (!console) {
Expand Down Expand Up @@ -156,6 +156,7 @@ function parseForPlayApp(scheme, hostname, pathname, queryParams, anchor) {

if (hostname.includes("play-web") || hostname.includes("play-staging")) {
pathname = pathname.substring(4);
pathname = pathname.replace("/production/play", "/play");
pathname = pathname.replace("/stage/play", "/play");
pathname = pathname.replace("/test/play", "/play");
}
Expand Down Expand Up @@ -519,9 +520,16 @@ function parseForPlayApp(scheme, hostname, pathname, queryParams, anchor) {
* Catch home TV urls
*
* Ex: https://www.srf.ch/play/tv
* Ex: https://www.srf.ch/play/tv?pageId=b2f5173a-da2c-4451-9101-fedc76e6c3bc
*/
if (pathname.endsWith("/tv")) {
return openPage(server, bu, "tv:home", null, null);
var pageId = queryParams["pageId"];
if (pageId) {
return openURL(server, bu, originalUrl);
}
else {
return openPage(server, bu, "tv:home", null, null);
}
}

/**
Expand Down Expand Up @@ -784,19 +792,48 @@ function parseForPlayApp(scheme, hostname, pathname, queryParams, anchor) {
return openPage(server, bu, "tv:home", null, null);
}

/**
* Catch PAC preview urls
*
* https://play-web.herokuapp.com/rts/production/play/tv/pac?pageId=b2f5173a-da2c-4451-9101-fedc76e6c3bc&type=LANDING_PAGE
* https://play-web.herokuapp.com/rts/production/play/tv/pac?pageId=758a8e8d-5f27-49a5-bcdc-384cf7f68d2e&topicUrn=urn%3Arts%3Atopic%3Atv%3A2743&type=TOPIC_PAGE
* https://play-web.herokuapp.com/rts/production/play/tv/pac?pageId=09cf1258-054d-4318-866f-c826e3d0c209&showUrn=urn%3Arts%3Ashow%3Atv%3A9356413&type=SHOW_PAGE
* https://play-web.herokuapp.com/rts/production/play/tv/pac?pageId=09cf1258-054d-4318-866f-c826e3d0c209&showUrn=urn%3Arts%3Ashow%3Atv%3A9356413&type=DEFAULT_SHOW_PAGE
* https://play-web.herokuapp.com/rts/production/play/tv/pac?pageId=307bb901-9f17-487e-bd1e-d51ccf5c8eb2&type=MICRO_PAGE
*/
if (pathname.endsWith("/tv/pac")) {
var pageId = queryParams["pageId"];
var type = queryParams["type"];
if (pageId && type) {
switch (type) {
case "LANDING_PAGE":
return openURL(server, bu, originalUrl);
case "TOPIC_PAGE":
var topicUrn = queryParams["topicUrn"];
if (topicUrn) {
return openTopicUrn(server, bu, topicUrn);
}
break;
case "SHOW_PAGE":
case "DEFAULT_SHOW_PAGE":
var showUrn = queryParams["showUrn"];
if (showUrn) {
return openShowUrn(server, bu, showUrn);
}
break;
case "MICRO_PAGE":
return openURL(server, bu, originalUrl);
}
}
}

// Redirect fallback.
console.log("Can't parse Play URL. Unsupported URL.");
return schemeForBu(bu) + "://unsupported?server=" + server;
};
function openMedia(server, bu, mediaType, mediaId, startTime) {
var redirect = schemeForBu(bu) + "://open?media=urn:" + bu + ":" + mediaType + ":" + mediaId;
if (startTime) {
redirect = redirect + "&start-time=" + startTime;
}
if (server) {
redirect = redirect + "&server=" + encodeURIComponent(server);
}
return redirect;
var mediaUrn = "urn:" + bu + ":" + mediaType + ":" + mediaId;
return openMediaUrn(server, bu, mediaUrn, startTime);
}

function openMediaUrn(server, bu, mediaUrn, startTime) {
Expand All @@ -811,15 +848,25 @@ function openMediaUrn(server, bu, mediaUrn, startTime) {
}

function openShow(server, bu, showTransmission, showId) {
var redirect = schemeForBu(bu) + "://open?show=urn:" + bu + ":show:" + showTransmission + ":" + showId;
var showUrn = "urn:" + bu + ":show:" + showTransmission + ":" + showId;
return openShowUrn(server, bu, showUrn);
}

function openShowUrn(server, bu, showUrn) {
var redirect = schemeForBu(bu) + "://open?show=" + showUrn;
if (server) {
redirect = redirect + "&server=" + encodeURIComponent(server);
}
return redirect;
}

function openTopic(server, bu, topicTransmission, topicId) {
var redirect = schemeForBu(bu) + "://open?topic=urn:" + bu + ":topic:" + topicTransmission + ":" + topicId;
var topicUrn = "urn:" + bu + ":topic:" + topicTransmission + ":" + topicId;
return openTopicUrn(server, bu, topicUrn);
}

function openTopicUrn(server, bu, topicUrn) {
var redirect = schemeForBu(bu) + "://open?topic=" + topicUrn;
if (server) {
redirect = redirect + "&server=" + encodeURIComponent(server);
}
Expand Down
Loading

0 comments on commit 8315d45

Please sign in to comment.