The content ID is an identifier used by our backend to match Mesh sources that are watching the same content. It is an optional parameter, and by default, we generate contentId from the content URL by removing any query parameters and protocol from it.
contentIdGenerator - function (optional)
The default contentIdGenerator
option is a function that generates a content ID from content URL.
In some cases, you might need to implement your own content ID generation logic.
-
You should be very careful that this function returns a string that identifies a content in a truly unique manner. If there's a collision, our backend will match Mesh sources that aren't watching the same content together, which can lead to unpredictable results.
-
We require the content identified by the same id to be packaged in the exact same way. If you are packaging your content in an origin server and using your edge servers merely as cache servers, you're fine. If your edge servers are doing the packaging, then you shouldn't identify contents coming from different edge servers as being the same content. It is advised, then, that you don't set this optional parameter and that you use the default (full URL without the query string).
-
Be careful about elements non-related to the content in your id. For example, if you derive your content id from its URL, and you have a user-specific token in your query string, you're going to have to strip that token from the id. Same thing if you have query parameters identifying the device, you'll want to remove them if your content is packaged the same for all devices (but keep it if the content is different for mobile and desktop for example).
Generic example
Create your own function.
function contentIdFn(contentUrl) {
// your own function logic
}
Then, pass the result in the wrapper constructor or the player conf object.
var dnaConfig = {
"contentIdGenerator" : contentIdFn
};
If not defined, Streamroot will fall back to the default implementation.
Specific examples
1 - Your content can be identified from the content URL path.
Typical use cases: multi-CDNs, or your own edge servers.
function contentIdFn(contentUrl) {
var l = document.createElement("a");
l.href = contentUrl;
return l.pathname;
}
var dnaConfig = {
"contentIdGenerator" : contentIdFn
};
In our example, we only take into account the URL path (we remove the URL host and query parameters)
2 - Your content can be identified from a parameter from an external source
Typical use cases: content ID from your backend, or from outside of the player scope.
var contentID="external content id";
function contentIdFn(contentUrl) {
return contentID;
}
var dnaConfig = {
"contentIdGenerator" : contentIdFn
};
In our example, we first store the content ID in a variable, then we create a function that will return this variable.