@ateam-ai-mobile/core 0.1.26 → 0.1.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -40,6 +40,14 @@ function getCoreApiUrl() {
40
40
  function getCoreWsUrl() {
41
41
  return getCoreApiUrl().replace(/^http/, "ws");
42
42
  }
43
+ var CORE_WS_PROTOCOL = "adas.v1";
44
+ var CORE_WS_BEARER_PREFIX = "adas.bearer.";
45
+ function openCoreWs(tenant, token) {
46
+ const url = `${getCoreWsUrl()}/ws?tenant=${encodeURIComponent(tenant)}`;
47
+ const protocols = [CORE_WS_PROTOCOL];
48
+ if (token) protocols.push(CORE_WS_BEARER_PREFIX + token);
49
+ return new WebSocket(url, protocols);
50
+ }
43
51
  function getVoiceApiUrl() {
44
52
  const url = getConfig().voiceUrl;
45
53
  if (!url) throw new Error("[adas] voiceUrl not configured");
@@ -976,9 +984,8 @@ function handleEvent(msg) {
976
984
  function openSocket() {
977
985
  if (_ws) return;
978
986
  if (!_token || !_tenant) return;
979
- const url = `${getCoreWsUrl()}/ws?token=${encodeURIComponent(_token)}&tenant=${encodeURIComponent(_tenant)}`;
980
987
  console.log(`[acsWs] opening`);
981
- const ws = new WebSocket(url);
988
+ const ws = openCoreWs(_tenant, _token);
982
989
  _ws = ws;
983
990
  const isCurrent = () => ws === _ws;
984
991
  ws.onopen = () => {
@@ -1838,8 +1845,7 @@ function setClientDeclarationProvider(fn) {
1838
1845
  var _currentJobId = null;
1839
1846
  function ensureWs(tenant, token) {
1840
1847
  if (_ws2 && _wsReady) return _ws2;
1841
- const wsUrl = `${getCoreWsUrl()}/ws?token=${encodeURIComponent(token || "")}&tenant=${encodeURIComponent(tenant)}`;
1842
- const ws = new WebSocket(wsUrl);
1848
+ const ws = openCoreWs(tenant, token);
1843
1849
  _ws2 = ws;
1844
1850
  _wsReady = false;
1845
1851
  ws.onopen = () => {