@clockworkdog/cogs-client 2.1.1 → 2.3.0

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.
@@ -35,6 +35,10 @@ export default class CogsConnection<Manifest extends CogsPluginManifest> {
35
35
  private audioOutputs;
36
36
  private _selectedAudioOutput;
37
37
  get selectedAudioOutput(): string;
38
+ /**
39
+ * URL parameters use for the websocket connection and asset URLs
40
+ */
41
+ private urlParams;
38
42
  constructor(manifest: Manifest, { hostname, port }?: {
39
43
  hostname?: string;
40
44
  port?: number;
@@ -28,7 +28,8 @@ class CogsConnection {
28
28
  * Return asset URLs using the information about the client and server support for HTTP/2
29
29
  */
30
30
  getAssetUrl(path) {
31
- return (0, urls_1.assetUrl)(path, this.supportsHttp2Assets);
31
+ var _a, _b;
32
+ return `${(0, urls_1.assetUrl)(path, this.supportsHttp2Assets)}?${(_b = (_a = this.urlParams) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _b !== void 0 ? _b : ''}`;
32
33
  }
33
34
  get selectedAudioOutput() {
34
35
  return this._selectedAudioOutput;
@@ -55,7 +56,16 @@ class CogsConnection {
55
56
  this._selectedAudioOutput = '';
56
57
  this.currentState = { ...initialClientState };
57
58
  const { useReconnectingWebsocket, path, pathParams, supportsHttp2Assets } = websocketParametersFromUrl(document.location.href);
58
- const socketUrl = `ws://${hostname}:${port}${path}${pathParams ? '?' + pathParams : ''}`;
59
+ // Store the URL parameters for use in asset URLs
60
+ // and add screen dimensions which COGS can use to determine the best asset quality to serve
61
+ //
62
+ // Note that content always runs fullscreen and
63
+ // we assume the screen resolution will not change while the content is running.
64
+ this.urlParams = new URLSearchParams(pathParams);
65
+ this.urlParams.set('screenWidth', window.screen.width.toString());
66
+ this.urlParams.set('screenHeight', window.screen.height.toString());
67
+ this.urlParams.set('screenPixelRatio', window.devicePixelRatio.toString());
68
+ const socketUrl = `ws://${hostname}:${port}${path}?${this.urlParams}`;
59
69
  this.websocket = useReconnectingWebsocket ? new reconnecting_websocket_1.default(socketUrl) : new WebSocket(socketUrl);
60
70
  this.clientSupportsHttp2Assets = !!supportsHttp2Assets;
61
71
  this.websocket.onopen = () => {
@@ -101,6 +111,17 @@ class CogsConnection {
101
111
  case 'cogs_environment':
102
112
  this.serverSupportsHttp2Assets = message.http2AssetsServer;
103
113
  break;
114
+ case 'media_config_update':
115
+ for (const optionName of ['preferOptimizedAudio', 'preferOptimizedVideo', 'preferOptimizedImages']) {
116
+ const optionEnabled = message[optionName];
117
+ if (optionEnabled) {
118
+ this.urlParams.set(optionName, 'true');
119
+ }
120
+ else {
121
+ this.urlParams.delete(optionName);
122
+ }
123
+ }
124
+ break;
104
125
  }
105
126
  this.dispatchEvent(new CogsMessageEvent(message));
106
127
  }