Show Menu
主题×

获取会话 ID

引用播放器中的此代码片段显示了一种编码 会话请求 ,以及从响应的 Location 标头中提取会话 ID(和媒体收集 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. ...