取得工作階段 ID obtaining-a-session-id

這段來自參考播放器的程式碼片段示範如何編寫工作階段要求 的程式碼,以及示範如何從回應中的 Location 標題擷取工作階段 ID (和 Media Collection API 版本)。

var
sessionData = {
        ...
        "media.contentType": "VOD",
        "media.channel": "sample-channel",
        ...
    }
};
...

const SESSION_ID_EXTRACTOR = /^\/api\/(.*)\/sessions\/(.*)/;
    ...
    apiClient.request({
        "baseUrl": config.apiBaseUrl,   // The endpoint
        "path": config.apiSessionsPath, // api/v1/sessions/
        "method": "POST",               // (Always POST)
        "data": sessionData             // Mandatory params
     }).then((response) => {
        // Extract Session ID (and API version)
        const [, apiVersion, sessionId] =  response.headers.Location.match(SESSION_ID_EXTRACTOR);
        this.sessionId = sessionId;     // Session ID obtained
        this._sessionStarted = true;    // Session started.
    ...
recommendation-more-help
c8eee520-cef5-4f8c-a38a-d4952cfae4eb