참조 플레이어의 이 코드 조각은 응답의 위치 헤더에서 세션 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.
...