diff options
author | Daniel Calviño Sánchez <danxuliu@gmail.com> | 2022-04-06 20:55:56 +0300 |
---|---|---|
committer | Daniel Calviño Sánchez <danxuliu@gmail.com> | 2022-04-08 04:05:13 +0300 |
commit | eca059cbf480e64bc2b7c25de5f324a59c3edba2 (patch) | |
tree | 35089c6079ffc8949bb98dc0f265fc4c656a2a93 /docs | |
parent | 48068f53757af0243f6ba21efd383efd3c5b21e3 (diff) |
Get API version from capabilities
Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
Diffstat (limited to 'docs')
-rw-r--r-- | docs/Talkbuchet.js | 42 |
1 files changed, 39 insertions, 3 deletions
diff --git a/docs/Talkbuchet.js b/docs/Talkbuchet.js index a58c5e73c..29a3ad735 100644 --- a/docs/Talkbuchet.js +++ b/docs/Talkbuchet.js @@ -129,9 +129,6 @@ const user = '' const appToken = '' -const signalingApiVersion = 2 // FIXME get from capabilities endpoint -const conversationApiVersion = 3 // FIXME get from capabilities endpoint - // The conversation token is only strictly needed for guests or if HPB // clustering is enabled. const token = '' @@ -156,6 +153,45 @@ const connectionWarningTimeout = 5000 // target Nextcloud instance, as cross-doman requests are not allowed, so the // host is directly got from the current location. const host = 'https://' + window.location.host + +const capabitiliesUrl = host + '/ocs/v1.php/cloud/capabilities' + +async function getCapabilities() { + const fetchOptions = { + headers: { + 'OCS-ApiRequest': true, + 'Accept': 'json', + }, + } + + const capabilitiesResponse = await fetch(capabitiliesUrl, fetchOptions) + const capabilities = await capabilitiesResponse.json() + + return capabilities.ocs.data +} + +const capabilities = await getCapabilities() + +function extractFeatureVersion(feature) { + const talkFeatures = capabilities?.capabilities?.spreed?.features + if (!talkFeatures) { + console.error('Talk features not found', capabilities) + throw new Error() + } + + for (const talkFeature of talkFeatures) { + if (talkFeature.startsWith(feature + '-v')) { + return talkFeature.substring(feature.length + 2) + } + } + + console.error('Failed to get feature version for ' + feature, talkFeatures) + throw new Error() +} + +const signalingApiVersion = extractFeatureVersion('signaling') +const conversationApiVersion = extractFeatureVersion('conversation') + const talkOcsApiUrl = host + '/ocs/v2.php/apps/spreed/api/' const signalingSettingsUrl = talkOcsApiUrl + 'v' + signalingApiVersion + '/signaling/settings' const signalingBackendUrl = talkOcsApiUrl + 'v' + signalingApiVersion + '/signaling/backend' |