steelseries-sonar-sdk 0.2.0 → 0.2.2

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.
Files changed (188) hide show
  1. package/dist/index.js +874 -0
  2. package/package.json +7 -3
  3. package/.gitattributes +0 -8
  4. package/.github/workflows/tests.yml +0 -18
  5. package/.vscode/extensions.json +0 -8
  6. package/.vscode/settings.json +0 -33
  7. package/_.todo +0 -4
  8. package/biome.json +0 -62
  9. package/http/sonar.http +0 -104
  10. package/src/consts/fetch-options-put.ts +0 -3
  11. package/src/enums.ts +0 -88
  12. package/src/exceptions.ts +0 -45
  13. package/src/functions/audio/get-audio-data-classic.ts +0 -31
  14. package/src/functions/audio/get-audio-data-stream.ts +0 -37
  15. package/src/functions/audio/get-audio-mode.ts +0 -11
  16. package/src/functions/audio/set-audio-mode.ts +0 -12
  17. package/src/functions/audio/set-channel-mute-classic.ts +0 -35
  18. package/src/functions/audio/set-channel-mute-streamer.ts +0 -41
  19. package/src/functions/audio/set-channel-volume-classic.ts +0 -37
  20. package/src/functions/audio/set-channel-volume-streamer.ts +0 -43
  21. package/src/functions/chatmix/get-chat-mix-state.ts +0 -20
  22. package/src/functions/chatmix/set-chat-mix-balance.ts +0 -22
  23. package/src/functions/converters/convert-channel-to-api.ts +0 -19
  24. package/src/functions/converters/convert-chat-mix-balance-to-api.ts +0 -6
  25. package/src/functions/converters/convert-chat-mix-balance-to-user.ts +0 -7
  26. package/src/functions/converters/convert-profile-channel-to-api.ts +0 -19
  27. package/src/functions/converters/convert-profile-channel-to-user.ts +0 -19
  28. package/src/functions/converters/convert-volume-to-api.ts +0 -5
  29. package/src/functions/converters/convert-volume-to-user.ts +0 -6
  30. package/src/functions/devices/get-audio-devices.ts +0 -40
  31. package/src/functions/devices/set-audio-device.ts +0 -19
  32. package/src/functions/endpoint/get-app-endpoint.ts +0 -73
  33. package/src/functions/endpoint/get-sonar-endpoint-cached.ts +0 -28
  34. package/src/functions/endpoint/get-sonar-endpoint.ts +0 -88
  35. package/src/functions/profile/get-channel-profiles.ts +0 -26
  36. package/src/functions/profile/get-selected-profiles.ts +0 -17
  37. package/src/functions/profile/set-selected-profile.ts +0 -17
  38. package/src/index.ts +0 -41
  39. package/src/sonar/models/audio-settings/chatmix-data.ts +0 -6
  40. package/src/sonar/models/audio-settings/enums/audio-mode.ts +0 -4
  41. package/src/sonar/models/audio-settings/enums/chat-mix-state.ts +0 -6
  42. package/src/sonar/models/audio-settings/enums/device-data-flow.ts +0 -5
  43. package/src/sonar/models/audio-settings/enums/device-default-roles.ts +0 -6
  44. package/src/sonar/models/audio-settings/enums/device-role.ts +0 -9
  45. package/src/sonar/models/audio-settings/enums/device-state.ts +0 -8
  46. package/src/sonar/models/audio-settings/enums/sonar-channel.ts +0 -8
  47. package/src/sonar/models/audio-settings/enums/streaming-path.ts +0 -4
  48. package/src/sonar/models/audio-settings/volume-info-classic.ts +0 -4
  49. package/src/sonar/models/audio-settings/volume-info-streamer.ts +0 -10
  50. package/src/sonar/models/audio-settings/volume-settings-classic.ts +0 -13
  51. package/src/sonar/models/audio-settings/volume-settings-streamer.ts +0 -13
  52. package/src/sonar/models/config/config.ts +0 -9
  53. package/src/sonar/models/config/enums/VirtualAudioDevice.ts +0 -7
  54. package/src/sonar/models/devices/audio-device.ts +0 -17
  55. package/src/sonar/models/devices/changed-device.ts +0 -7
  56. package/src/sonar/requests/audio-devices/change-audio-device.ts +0 -37
  57. package/src/sonar/requests/audio-devices/request-audio-devices.ts +0 -42
  58. package/src/sonar/requests/chatmix/change-chat-mix-balance.ts +0 -25
  59. package/src/sonar/requests/chatmix/request-chat-mix-state.ts +0 -24
  60. package/src/sonar/requests/mode/change-audio-mode.ts +0 -24
  61. package/src/sonar/requests/mode/request-audio-mode.ts +0 -24
  62. package/src/sonar/requests/profiles/change-selected-config.ts +0 -25
  63. package/src/sonar/requests/profiles/request-configs.ts +0 -24
  64. package/src/sonar/requests/profiles/request-selected-configs.ts +0 -22
  65. package/src/sonar/requests/volume-settings/change-volume-level-classic.ts +0 -27
  66. package/src/sonar/requests/volume-settings/change-volume-level-streamer.ts +0 -29
  67. package/src/sonar/requests/volume-settings/change-volume-mute-classic.ts +0 -27
  68. package/src/sonar/requests/volume-settings/change-volume-mute-streamer.ts +0 -29
  69. package/src/sonar/requests/volume-settings/request-volume-settings-classic.ts +0 -22
  70. package/src/sonar/requests/volume-settings/request-volume-settings-streamer.ts +0 -22
  71. package/src/types/audio-device.ts +0 -7
  72. package/src/types/changed-device.ts +0 -7
  73. package/src/types/channel-volume-classic.ts +0 -4
  74. package/src/types/channel-volume-streamer-path.ts +0 -4
  75. package/src/types/channel-volume-streamer.ts +0 -6
  76. package/src/types/channel-volumes-classic.ts +0 -8
  77. package/src/types/channel-volumes-streamer.ts +0 -8
  78. package/src/types/chat-mix-data.ts +0 -7
  79. package/src/types/profile-option.ts +0 -9
  80. package/tests/e2e/audio/get-audio-data-classic.real.test.ts +0 -11
  81. package/tests/e2e/audio/get-audio-data-stream.real.test.ts +0 -11
  82. package/tests/e2e/audio/get-audio-mode.real.test.ts +0 -12
  83. package/tests/e2e/audio/set-audio-mode.real.test.ts +0 -20
  84. package/tests/e2e/audio/set-channel-mute-classic.real.test.ts +0 -18
  85. package/tests/e2e/audio/set-channel-mute-streamer.real.test.ts +0 -18
  86. package/tests/e2e/audio/set-channel-volume-classic.real.test.ts +0 -17
  87. package/tests/e2e/audio/set-channel-volume-streamer.real.test.ts +0 -22
  88. package/tests/e2e/chatmix/get-chat-mix-state.real.test.ts +0 -25
  89. package/tests/e2e/chatmix/set-chat-mix-balance.real.test.ts +0 -25
  90. package/tests/e2e/devices/get-audio-devices.real.test.ts +0 -29
  91. package/tests/e2e/devices/set-audio-device.real.test.ts +0 -32
  92. package/tests/e2e/enpoint/get-app-endpoint.real.test.ts +0 -19
  93. package/tests/e2e/enpoint/get-sonar-endpoint-cached.real.test.ts +0 -32
  94. package/tests/e2e/enpoint/get-sonar-endpoint.real.test.ts +0 -21
  95. package/tests/e2e/profiles/get-channel-profiles.real.test.ts +0 -21
  96. package/tests/e2e/profiles/get-selected-profiles.real.test.ts +0 -11
  97. package/tests/e2e/profiles/set-selected-profile.real.test.ts +0 -17
  98. package/tests/helpers/get-endpoint-e2e.ts +0 -8
  99. package/tests/unit/audio/get-audio-data-classic.test.ts +0 -57
  100. package/tests/unit/audio/get-audio-data-stream.test.ts +0 -65
  101. package/tests/unit/audio/get-audio-mode.test.ts +0 -58
  102. package/tests/unit/audio/set-audio-mode.test.ts +0 -66
  103. package/tests/unit/audio/set-channel-mute-classic.test.ts +0 -58
  104. package/tests/unit/audio/set-channel-mute-streamer.test.ts +0 -64
  105. package/tests/unit/audio/set-channel-volume-classic.test.ts +0 -58
  106. package/tests/unit/audio/set-channel-volume-streamer.test.ts +0 -64
  107. package/tests/unit/chatmix/get-chat-mix-state.test.ts +0 -70
  108. package/tests/unit/chatmix/set-chat-mix-balance.test.ts +0 -58
  109. package/tests/unit/devices/get-audio-devices.test.ts +0 -59
  110. package/tests/unit/devices/set-audio-devices.test.ts +0 -62
  111. package/tests/unit/endpoint/get-app-endpoint.test.ts +0 -72
  112. package/tests/unit/endpoint/get-sonar-endpoint-cached.test.ts +0 -93
  113. package/tests/unit/endpoint/get-sonar-endpoint.test.ts +0 -140
  114. package/tests/unit/profiles/get-channel-profiles.test.ts +0 -91
  115. package/tests/unit/profiles/get-selected-profiles.test.ts +0 -64
  116. package/tests/unit/profiles/set-selected-profile.test.ts +0 -55
  117. package/tsconfig.build.json +0 -12
  118. package/tsconfig.json +0 -36
  119. /package/{src → dist}/consts/fetch-options-put.d.ts +0 -0
  120. /package/{src → dist}/enums.d.ts +0 -0
  121. /package/{src → dist}/exceptions.d.ts +0 -0
  122. /package/{src → dist}/functions/audio/get-audio-data-classic.d.ts +0 -0
  123. /package/{src → dist}/functions/audio/get-audio-data-stream.d.ts +0 -0
  124. /package/{src → dist}/functions/audio/get-audio-mode.d.ts +0 -0
  125. /package/{src → dist}/functions/audio/set-audio-mode.d.ts +0 -0
  126. /package/{src → dist}/functions/audio/set-channel-mute-classic.d.ts +0 -0
  127. /package/{src → dist}/functions/audio/set-channel-mute-streamer.d.ts +0 -0
  128. /package/{src → dist}/functions/audio/set-channel-volume-classic.d.ts +0 -0
  129. /package/{src → dist}/functions/audio/set-channel-volume-streamer.d.ts +0 -0
  130. /package/{src → dist}/functions/chatmix/get-chat-mix-state.d.ts +0 -0
  131. /package/{src → dist}/functions/chatmix/set-chat-mix-balance.d.ts +0 -0
  132. /package/{src → dist}/functions/converters/convert-channel-to-api.d.ts +0 -0
  133. /package/{src → dist}/functions/converters/convert-chat-mix-balance-to-api.d.ts +0 -0
  134. /package/{src → dist}/functions/converters/convert-chat-mix-balance-to-user.d.ts +0 -0
  135. /package/{src → dist}/functions/converters/convert-profile-channel-to-api.d.ts +0 -0
  136. /package/{src → dist}/functions/converters/convert-profile-channel-to-user.d.ts +0 -0
  137. /package/{src → dist}/functions/converters/convert-volume-to-api.d.ts +0 -0
  138. /package/{src → dist}/functions/converters/convert-volume-to-user.d.ts +0 -0
  139. /package/{src → dist}/functions/devices/get-audio-devices.d.ts +0 -0
  140. /package/{src → dist}/functions/devices/set-audio-device.d.ts +0 -0
  141. /package/{src → dist}/functions/endpoint/get-app-endpoint.d.ts +0 -0
  142. /package/{src → dist}/functions/endpoint/get-sonar-endpoint-cached.d.ts +0 -0
  143. /package/{src → dist}/functions/endpoint/get-sonar-endpoint.d.ts +0 -0
  144. /package/{src → dist}/functions/profile/get-channel-profiles.d.ts +0 -0
  145. /package/{src → dist}/functions/profile/get-selected-profiles.d.ts +0 -0
  146. /package/{src → dist}/functions/profile/set-selected-profile.d.ts +0 -0
  147. /package/{src → dist}/index.d.ts +0 -0
  148. /package/{src → dist}/sonar/models/audio-settings/chatmix-data.d.ts +0 -0
  149. /package/{src → dist}/sonar/models/audio-settings/enums/audio-mode.d.ts +0 -0
  150. /package/{src → dist}/sonar/models/audio-settings/enums/chat-mix-state.d.ts +0 -0
  151. /package/{src → dist}/sonar/models/audio-settings/enums/device-data-flow.d.ts +0 -0
  152. /package/{src → dist}/sonar/models/audio-settings/enums/device-default-roles.d.ts +0 -0
  153. /package/{src → dist}/sonar/models/audio-settings/enums/device-role.d.ts +0 -0
  154. /package/{src → dist}/sonar/models/audio-settings/enums/device-state.d.ts +0 -0
  155. /package/{src → dist}/sonar/models/audio-settings/enums/sonar-channel.d.ts +0 -0
  156. /package/{src → dist}/sonar/models/audio-settings/enums/streaming-path.d.ts +0 -0
  157. /package/{src → dist}/sonar/models/audio-settings/volume-info-classic.d.ts +0 -0
  158. /package/{src → dist}/sonar/models/audio-settings/volume-info-streamer.d.ts +0 -0
  159. /package/{src → dist}/sonar/models/audio-settings/volume-settings-classic.d.ts +0 -0
  160. /package/{src → dist}/sonar/models/audio-settings/volume-settings-streamer.d.ts +0 -0
  161. /package/{src → dist}/sonar/models/config/config.d.ts +0 -0
  162. /package/{src → dist}/sonar/models/config/enums/VirtualAudioDevice.d.ts +0 -0
  163. /package/{src → dist}/sonar/models/devices/audio-device.d.ts +0 -0
  164. /package/{src → dist}/sonar/models/devices/changed-device.d.ts +0 -0
  165. /package/{src → dist}/sonar/requests/audio-devices/change-audio-device.d.ts +0 -0
  166. /package/{src → dist}/sonar/requests/audio-devices/request-audio-devices.d.ts +0 -0
  167. /package/{src → dist}/sonar/requests/chatmix/change-chat-mix-balance.d.ts +0 -0
  168. /package/{src → dist}/sonar/requests/chatmix/request-chat-mix-state.d.ts +0 -0
  169. /package/{src → dist}/sonar/requests/mode/change-audio-mode.d.ts +0 -0
  170. /package/{src → dist}/sonar/requests/mode/request-audio-mode.d.ts +0 -0
  171. /package/{src → dist}/sonar/requests/profiles/change-selected-config.d.ts +0 -0
  172. /package/{src → dist}/sonar/requests/profiles/request-configs.d.ts +0 -0
  173. /package/{src → dist}/sonar/requests/profiles/request-selected-configs.d.ts +0 -0
  174. /package/{src → dist}/sonar/requests/volume-settings/change-volume-level-classic.d.ts +0 -0
  175. /package/{src → dist}/sonar/requests/volume-settings/change-volume-level-streamer.d.ts +0 -0
  176. /package/{src → dist}/sonar/requests/volume-settings/change-volume-mute-classic.d.ts +0 -0
  177. /package/{src → dist}/sonar/requests/volume-settings/change-volume-mute-streamer.d.ts +0 -0
  178. /package/{src → dist}/sonar/requests/volume-settings/request-volume-settings-classic.d.ts +0 -0
  179. /package/{src → dist}/sonar/requests/volume-settings/request-volume-settings-streamer.d.ts +0 -0
  180. /package/{src → dist}/types/audio-device.d.ts +0 -0
  181. /package/{src → dist}/types/changed-device.d.ts +0 -0
  182. /package/{src → dist}/types/channel-volume-classic.d.ts +0 -0
  183. /package/{src → dist}/types/channel-volume-streamer-path.d.ts +0 -0
  184. /package/{src → dist}/types/channel-volume-streamer.d.ts +0 -0
  185. /package/{src → dist}/types/channel-volumes-classic.d.ts +0 -0
  186. /package/{src → dist}/types/channel-volumes-streamer.d.ts +0 -0
  187. /package/{src → dist}/types/chat-mix-data.d.ts +0 -0
  188. /package/{src → dist}/types/profile-option.d.ts +0 -0
package/dist/index.js ADDED
@@ -0,0 +1,874 @@
1
+ // src/enums.ts
2
+ var AudioChannel;
3
+ ((AudioChannel2) => {
4
+ AudioChannel2["Master"] = "master";
5
+ AudioChannel2["Game"] = "game";
6
+ AudioChannel2["Chat"] = "chat";
7
+ AudioChannel2["Media"] = "media";
8
+ AudioChannel2["Aux"] = "aux";
9
+ AudioChannel2["Mic"] = "mic";
10
+ })(AudioChannel ||= {});
11
+ var ProfileChannel;
12
+ ((ProfileChannel2) => {
13
+ ProfileChannel2["Game"] = "game";
14
+ ProfileChannel2["Chat"] = "chat";
15
+ ProfileChannel2["Media"] = "media";
16
+ ProfileChannel2["Aux"] = "aux";
17
+ ProfileChannel2["Mic"] = "mic";
18
+ })(ProfileChannel ||= {});
19
+ var DeviceChannel;
20
+ ((DeviceChannel2) => {
21
+ DeviceChannel2["Output"] = "render";
22
+ DeviceChannel2["Game"] = "game";
23
+ DeviceChannel2["Chat"] = "chat";
24
+ DeviceChannel2["Media"] = "media";
25
+ DeviceChannel2["Aux"] = "aux";
26
+ DeviceChannel2["Mic"] = "mic";
27
+ })(DeviceChannel ||= {});
28
+ var StreamerPath;
29
+ ((StreamerPath2) => {
30
+ StreamerPath2["Streaming"] = "streaming";
31
+ StreamerPath2["Monitoring"] = "monitoring";
32
+ })(StreamerPath ||= {});
33
+ var AudioMode;
34
+ ((AudioMode2) => {
35
+ AudioMode2["Classic"] = "classic";
36
+ AudioMode2["Streamer"] = "stream";
37
+ })(AudioMode ||= {});
38
+ var ChatMixState;
39
+ ((ChatMixState2) => {
40
+ ChatMixState2["Enabled"] = "enabled";
41
+ ChatMixState2["FiniteWheel"] = "finiteWheel";
42
+ ChatMixState2["DifferentDeviceSelected"] = "differentDeviceSelected";
43
+ ChatMixState2["NoDeviceSelected"] = "noDeviceSelected";
44
+ })(ChatMixState ||= {});
45
+ var DeviceFlow;
46
+ ((DeviceFlow2) => {
47
+ DeviceFlow2["Output"] = "output";
48
+ DeviceFlow2["Input"] = "input";
49
+ })(DeviceFlow ||= {});
50
+ // src/exceptions.ts
51
+ var InitializeErrorReason;
52
+ ((InitializeErrorReason2) => {
53
+ InitializeErrorReason2["BadConfig"] = "Bad Config";
54
+ InitializeErrorReason2["OSUnsupported"] = "OS Unsupported";
55
+ InitializeErrorReason2["NotEnabled"] = "Not Enabled";
56
+ InitializeErrorReason2["NotRunning"] = "Not Running";
57
+ InitializeErrorReason2["NotReady"] = "Not Ready";
58
+ InitializeErrorReason2["NotResponding"] = "Not Responding";
59
+ InitializeErrorReason2["NotAvailable"] = "Not Available";
60
+ })(InitializeErrorReason ||= {});
61
+
62
+ class SonarException extends Error {
63
+ constructor(message, cause) {
64
+ super(message, { cause });
65
+ super.name = new.target.name;
66
+ }
67
+ }
68
+
69
+ class SonarRequestException extends SonarException {
70
+ constructor(error) {
71
+ super(error?.message ?? "There was an issue communicating with the Sonar service.", error?.innerException);
72
+ }
73
+ }
74
+
75
+ class SonarInitializationException extends SonarException {
76
+ reason;
77
+ constructor(error) {
78
+ const message = `${error?.message ?? `There was an issue finding the Sonar service: ${error.reason}.`}${error?.innerException ? " See inner exception." : ""}`;
79
+ super(message, error?.innerException);
80
+ this.reason = error.reason;
81
+ }
82
+ }
83
+ // src/functions/converters/convert-volume-to-user.ts
84
+ function convertVolumeToUser(value) {
85
+ let result = value * 100;
86
+ result = Math.min(Math.max(result, 0), 100);
87
+ result = Math.floor(result);
88
+ return result;
89
+ }
90
+
91
+ // src/sonar/requests/volume-settings/request-volume-settings-classic.ts
92
+ async function requestVolumeSettingsClassic(sonarEndpoint) {
93
+ let response;
94
+ try {
95
+ const url = new URL(`${sonarEndpoint}/volumeSettings/classic`);
96
+ response = await fetch(url);
97
+ } catch (error) {
98
+ throw new SonarRequestException({ innerException: error });
99
+ }
100
+ if (response.ok) {
101
+ const data = await response.json();
102
+ if (data?.masters?.classic == null) {
103
+ throw new SonarRequestException({ innerException: new Error("Missing required data in response.") });
104
+ }
105
+ return data;
106
+ } else {
107
+ const data = await response.json();
108
+ throw new SonarRequestException({ innerException: new Error(data?.error ?? data) });
109
+ }
110
+ }
111
+
112
+ // src/functions/audio/get-audio-data-classic.ts
113
+ async function getAudioDataClassic(sonarEndpoint) {
114
+ const data = await requestVolumeSettingsClassic(sonarEndpoint);
115
+ const volumeData = {
116
+ ["master" /* Master */]: createResponseVolumeData(data.masters.classic),
117
+ ["game" /* Game */]: data.devices.game && createResponseVolumeData(data.devices.game.classic),
118
+ ["chat" /* Chat */]: data.devices.chatRender && createResponseVolumeData(data.devices.chatRender.classic),
119
+ ["media" /* Media */]: data.devices.media && createResponseVolumeData(data.devices.media.classic),
120
+ ["aux" /* Aux */]: data.devices.aux && createResponseVolumeData(data.devices.aux.classic),
121
+ ["mic" /* Mic */]: data.devices.chatCapture && createResponseVolumeData(data.devices.chatCapture.classic)
122
+ };
123
+ return volumeData;
124
+ }
125
+ function createResponseVolumeData(volumeData) {
126
+ return {
127
+ volume: convertVolumeToUser(volumeData.volume),
128
+ isMuted: volumeData.muted
129
+ };
130
+ }
131
+ // src/sonar/requests/volume-settings/request-volume-settings-streamer.ts
132
+ async function requestVolumeSettingsStreamer(sonarEndpoint) {
133
+ let response;
134
+ try {
135
+ const url = new URL(`${sonarEndpoint}/volumeSettings/streamer`);
136
+ response = await fetch(url);
137
+ } catch (error) {
138
+ throw new SonarRequestException({ innerException: error });
139
+ }
140
+ if (response.ok) {
141
+ const data = await response.json();
142
+ if (data?.masters?.stream == null) {
143
+ throw new SonarRequestException({ innerException: new Error("Missing required data in response.") });
144
+ }
145
+ return data;
146
+ } else {
147
+ const data = await response.json();
148
+ throw new SonarRequestException({ innerException: new Error(data?.error ?? data) });
149
+ }
150
+ }
151
+
152
+ // src/functions/audio/get-audio-data-stream.ts
153
+ async function getAudioDataStream(sonarEndpoint) {
154
+ const data = await requestVolumeSettingsStreamer(sonarEndpoint);
155
+ const volumeData = {
156
+ ["master" /* Master */]: createResponseVolumeData2(data.masters.stream),
157
+ ["game" /* Game */]: data.devices.game && createResponseVolumeData2(data.devices.game.stream),
158
+ ["chat" /* Chat */]: data.devices.chatRender && createResponseVolumeData2(data.devices.chatRender.stream),
159
+ ["media" /* Media */]: data.devices.media && createResponseVolumeData2(data.devices.media.stream),
160
+ ["aux" /* Aux */]: data.devices.aux && createResponseVolumeData2(data.devices.aux.stream),
161
+ ["mic" /* Mic */]: data.devices.chatCapture && createResponseVolumeData2(data.devices.chatCapture.stream)
162
+ };
163
+ return volumeData;
164
+ }
165
+ function createResponseVolumeData2(volumeData) {
166
+ return {
167
+ ["streaming" /* Streaming */]: {
168
+ volume: convertVolumeToUser(volumeData.streaming.volume),
169
+ isMuted: volumeData.streaming.muted
170
+ },
171
+ ["monitoring" /* Monitoring */]: {
172
+ volume: convertVolumeToUser(volumeData.monitoring.volume),
173
+ isMuted: volumeData.monitoring.muted
174
+ }
175
+ };
176
+ }
177
+ // src/sonar/models/audio-settings/enums/audio-mode.ts
178
+ var AudioMode2;
179
+ ((AudioMode3) => {
180
+ AudioMode3["Classic"] = "classic";
181
+ AudioMode3["Streamer"] = "stream";
182
+ })(AudioMode2 ||= {});
183
+
184
+ // src/sonar/requests/mode/request-audio-mode.ts
185
+ async function requestAudioMode(sonarEndpoint) {
186
+ let response;
187
+ const url = new URL(`${sonarEndpoint}/mode`);
188
+ try {
189
+ response = await fetch(url);
190
+ } catch (error) {
191
+ throw new SonarRequestException({ innerException: error });
192
+ }
193
+ if (response.ok) {
194
+ const data = await response.json();
195
+ if (Object.values(AudioMode2).includes(data)) {
196
+ return data;
197
+ }
198
+ throw new SonarRequestException({ message: "Received unhandled audio mode from Sonar server" });
199
+ } else {
200
+ const data = await response.text();
201
+ throw new SonarRequestException({ innerException: new Error(data) });
202
+ }
203
+ }
204
+
205
+ // src/functions/audio/get-audio-mode.ts
206
+ async function getAudioMode(sonarEndpoint) {
207
+ return await requestAudioMode(sonarEndpoint);
208
+ }
209
+ // src/sonar/requests/mode/change-audio-mode.ts
210
+ async function changeAudioMode(sonarEndpoint, audioMode) {
211
+ let response;
212
+ const url = new URL(`${sonarEndpoint}/mode/${audioMode}`);
213
+ try {
214
+ response = await fetch(url, {
215
+ method: "PUT"
216
+ });
217
+ } catch (error) {
218
+ throw new SonarRequestException({ innerException: error });
219
+ }
220
+ if (response.ok) {
221
+ const data = await response.json();
222
+ if (data !== audioMode) {
223
+ throw new SonarRequestException({ message: "Returned audio mode does not match requested mode" });
224
+ }
225
+ return data;
226
+ } else {
227
+ const data = await response.text();
228
+ throw new SonarRequestException({ innerException: new Error(data) });
229
+ }
230
+ }
231
+
232
+ // src/functions/audio/set-audio-mode.ts
233
+ async function setAudioMode(sonarEndpoint, audioMode) {
234
+ return await changeAudioMode(sonarEndpoint, audioMode);
235
+ }
236
+ // src/functions/converters/convert-channel-to-api.ts
237
+ function convertChannelToApi(channel) {
238
+ switch (channel) {
239
+ case "master" /* Master */:
240
+ return "master" /* Master */;
241
+ case "game" /* Game */:
242
+ return "chatRender" /* ChatRender */;
243
+ case "media" /* Media */:
244
+ return "media" /* Media */;
245
+ case "aux" /* Aux */:
246
+ return "aux" /* Aux */;
247
+ case "mic" /* Mic */:
248
+ return "chatCapture" /* ChatCapture */;
249
+ default:
250
+ throw new Error(`Unsupported AudioChannel: ${channel}`);
251
+ }
252
+ }
253
+
254
+ // src/sonar/requests/volume-settings/change-volume-mute-classic.ts
255
+ async function changeVolumeMuteClassic(sonarEndpoint, isMuted, deviceRole) {
256
+ let response;
257
+ try {
258
+ const url = new URL(`${sonarEndpoint}/volumeSettings/classic/${deviceRole}/mute/${isMuted}`);
259
+ response = await fetch(url, { method: "PUT" });
260
+ } catch (error) {
261
+ throw new SonarRequestException({ innerException: error });
262
+ }
263
+ if (response.ok) {
264
+ const data = await response.json();
265
+ if (data?.masters?.classic == null) {
266
+ throw new SonarRequestException({ innerException: new Error("Missing required data in response.") });
267
+ }
268
+ return data;
269
+ } else {
270
+ const data = await response.json();
271
+ throw new SonarRequestException({ innerException: new Error(data?.error ?? data) });
272
+ }
273
+ }
274
+
275
+ // src/functions/audio/set-channel-mute-classic.ts
276
+ async function setChannelMuteClassic(sonarEndpoint, isMuted, channel) {
277
+ const sonarChannel = convertChannelToApi(channel);
278
+ const data = await changeVolumeMuteClassic(sonarEndpoint, isMuted, sonarChannel);
279
+ const device = sonarChannel === "master" /* Master */ ? data.masters.classic : data.devices[sonarChannel]?.classic;
280
+ if (!device) {
281
+ throw new SonarRequestException({ message: `Missing device data in response.` });
282
+ }
283
+ const result = {
284
+ volume: convertVolumeToUser(device.volume),
285
+ isMuted: device.muted
286
+ };
287
+ return result;
288
+ }
289
+ // src/sonar/requests/volume-settings/change-volume-mute-streamer.ts
290
+ async function changeVolumeMuteStreamer(sonarEndpoint, isMuted, deviceRole, path) {
291
+ let response;
292
+ try {
293
+ const url = new URL(`${sonarEndpoint}/volumeSettings/streamer/${path}/${deviceRole}/isMuted/${isMuted}`);
294
+ response = await fetch(url, { method: "PUT" });
295
+ } catch (error) {
296
+ throw new SonarRequestException({ innerException: error });
297
+ }
298
+ if (response.ok) {
299
+ const data = await response.json();
300
+ if (data?.masters?.stream == null) {
301
+ throw new SonarRequestException({ innerException: new Error("Missing required data in response.") });
302
+ }
303
+ return data;
304
+ } else {
305
+ const data = await response.json();
306
+ throw new SonarRequestException({ innerException: new Error(data?.error ?? data) });
307
+ }
308
+ }
309
+
310
+ // src/functions/audio/set-channel-mute-streamer.ts
311
+ async function setChannelMuteStreamer(sonarEndpoint, isMuted, channel, path) {
312
+ const sonarChannel = convertChannelToApi(channel);
313
+ const streamPath = path === "streaming" /* Streaming */ ? "streaming" /* Streaming */ : "monitoring" /* Monitoring */;
314
+ const data = await changeVolumeMuteStreamer(sonarEndpoint, isMuted, sonarChannel, streamPath);
315
+ const device = sonarChannel === "master" /* Master */ ? data.masters.stream : data.devices[sonarChannel]?.stream;
316
+ if (!device) {
317
+ throw new SonarRequestException({ message: `Missing device data in response.` });
318
+ }
319
+ const devicePath = path === "streaming" /* Streaming */ ? device.streaming : device.monitoring;
320
+ const result = {
321
+ volume: convertVolumeToUser(devicePath.volume),
322
+ isMuted: devicePath.muted
323
+ };
324
+ return result;
325
+ }
326
+ // src/functions/converters/convert-volume-to-api.ts
327
+ function convertVolumeToApi(value) {
328
+ let result = value / 100;
329
+ result = Math.min(Math.max(result, 0), 1);
330
+ return result;
331
+ }
332
+
333
+ // src/sonar/requests/volume-settings/change-volume-level-classic.ts
334
+ async function changeVolumeLevelClassic(sonarEndpoint, volume, deviceRole) {
335
+ let response;
336
+ try {
337
+ const url = new URL(`${sonarEndpoint}/volumeSettings/classic/${deviceRole}/volume/${volume}`);
338
+ response = await fetch(url, { method: "PUT" });
339
+ } catch (error) {
340
+ throw new SonarRequestException({ innerException: error });
341
+ }
342
+ if (response.ok) {
343
+ const data = await response.json();
344
+ if (data?.masters?.classic == null) {
345
+ throw new SonarRequestException({ innerException: new Error("Missing required data in response.") });
346
+ }
347
+ return data;
348
+ } else {
349
+ const data = await response.json();
350
+ throw new SonarRequestException({ innerException: new Error(data?.error ?? data) });
351
+ }
352
+ }
353
+
354
+ // src/functions/audio/set-channel-volume-classic.ts
355
+ async function setChannelVolumeClassic(sonarEndpoint, volumePercent, channel) {
356
+ const sonarChannel = convertChannelToApi(channel);
357
+ const formattedVolume = convertVolumeToApi(volumePercent);
358
+ const data = await changeVolumeLevelClassic(sonarEndpoint, formattedVolume, sonarChannel);
359
+ const device = sonarChannel === "master" /* Master */ ? data.masters.classic : data.devices[sonarChannel]?.classic;
360
+ if (!device) {
361
+ throw new SonarRequestException({ message: `Missing device data in response.` });
362
+ }
363
+ const result = {
364
+ volume: convertVolumeToUser(device.volume),
365
+ isMuted: device.muted
366
+ };
367
+ return result;
368
+ }
369
+ // src/sonar/requests/volume-settings/change-volume-level-streamer.ts
370
+ async function changeVolumeLevelStreamer(sonarEndpoint, volume, channel, path) {
371
+ let response;
372
+ try {
373
+ const url = new URL(`${sonarEndpoint}/volumeSettings/streamer/${path}/${channel}/volume/${volume}`);
374
+ response = await fetch(url, { method: "PUT" });
375
+ } catch (error) {
376
+ throw new SonarRequestException({ innerException: error });
377
+ }
378
+ if (response.ok) {
379
+ const data = await response.json();
380
+ if (data?.masters?.stream == null) {
381
+ throw new SonarRequestException({ innerException: new Error("Missing required data in response.") });
382
+ }
383
+ return data;
384
+ } else {
385
+ const data = await response.json();
386
+ throw new SonarRequestException({ innerException: new Error(data?.error ?? data) });
387
+ }
388
+ }
389
+
390
+ // src/functions/audio/set-channel-volume-streamer.ts
391
+ async function setChannelVolumeStreamer(sonarEndpoint, volumePercent, channel, path) {
392
+ const sonarChannel = convertChannelToApi(channel);
393
+ const formattedVolume = convertVolumeToApi(volumePercent);
394
+ const streamPath = path === "streaming" /* Streaming */ ? "streaming" /* Streaming */ : "monitoring" /* Monitoring */;
395
+ const data = await changeVolumeLevelStreamer(sonarEndpoint, formattedVolume, sonarChannel, streamPath);
396
+ const device = sonarChannel === "master" /* Master */ ? data.masters.stream : data.devices[sonarChannel]?.stream;
397
+ if (!device) {
398
+ throw new SonarRequestException({ message: `Missing device data in response.` });
399
+ }
400
+ const devicePath = path === "streaming" /* Streaming */ ? device.streaming : device.monitoring;
401
+ const result = {
402
+ volume: convertVolumeToUser(devicePath.volume),
403
+ isMuted: devicePath.muted
404
+ };
405
+ return result;
406
+ }
407
+ // src/functions/converters/convert-chat-mix-balance-to-user.ts
408
+ function convertChatMixBalanceToUser(balance) {
409
+ let result = (balance + 1) / 2 * 100;
410
+ result = Math.floor(result);
411
+ result = Math.min(Math.max(result, 0), 100);
412
+ return result;
413
+ }
414
+
415
+ // src/sonar/requests/chatmix/request-chat-mix-state.ts
416
+ async function requestChatMixState(sonarEndpoint) {
417
+ const url = new URL(`${sonarEndpoint}/chatMix`);
418
+ let response;
419
+ try {
420
+ response = await fetch(url);
421
+ } catch (error) {
422
+ throw new SonarRequestException({ innerException: error });
423
+ }
424
+ if (response.ok) {
425
+ const data = await response.json();
426
+ if (data?.balance == null || data?.state == null) {
427
+ throw new SonarRequestException({ message: "Missing required data in response" });
428
+ }
429
+ return data;
430
+ } else {
431
+ const data = await response.text();
432
+ throw new SonarRequestException({ innerException: new Error(data) });
433
+ }
434
+ }
435
+
436
+ // src/functions/chatmix/get-chat-mix-state.ts
437
+ async function getChatMixState(sonarEndpoint) {
438
+ const data = await requestChatMixState(sonarEndpoint);
439
+ const chatMixData = {
440
+ chatBalance: convertChatMixBalanceToUser(data.balance),
441
+ state: data.state,
442
+ isEnabled: data.state === "enabled" /* Enabled */
443
+ };
444
+ return chatMixData;
445
+ }
446
+ // src/functions/converters/convert-chat-mix-balance-to-api.ts
447
+ function convertChatMixBalanceToApi(balance) {
448
+ let result = balance / 100 * 2 - 1;
449
+ result = Math.min(Math.max(result, -1), 1);
450
+ return result;
451
+ }
452
+
453
+ // src/sonar/requests/chatmix/change-chat-mix-balance.ts
454
+ async function changeChatMixBalance(sonarEndpoint, chatBalance) {
455
+ const url = new URL(`${sonarEndpoint}/chatMix?balance=${chatBalance}`);
456
+ let response;
457
+ try {
458
+ response = await fetch(url, {
459
+ method: "PUT"
460
+ });
461
+ } catch (error) {
462
+ throw new SonarRequestException({ innerException: error });
463
+ }
464
+ if (response.ok) {
465
+ const data = await response.json();
466
+ if (data?.balance == null || data?.state == null) {
467
+ throw new SonarRequestException({ message: "Missing required data in response" });
468
+ }
469
+ return data;
470
+ } else {
471
+ const data = await response.json();
472
+ throw new SonarRequestException({ message: data.Message });
473
+ }
474
+ }
475
+
476
+ // src/functions/chatmix/set-chat-mix-balance.ts
477
+ async function setChatMixBalance(sonarEndpoint, chatBalance) {
478
+ const balance = convertChatMixBalanceToApi(chatBalance);
479
+ const data = await changeChatMixBalance(sonarEndpoint, balance);
480
+ const chatMixData = {
481
+ chatBalance: convertChatMixBalanceToUser(data.balance),
482
+ state: data.state,
483
+ isEnabled: data.state === "enabled" /* Enabled */
484
+ };
485
+ return chatMixData;
486
+ }
487
+ // src/sonar/requests/audio-devices/request-audio-devices.ts
488
+ async function requestAudioDevices(sonarEndpoint, params) {
489
+ const { deviceDataFlow, onlySteelSeriesVAD = false, removeSteelSeriesVAD = false } = params;
490
+ const url = new URL(`${sonarEndpoint}/audioDevices`);
491
+ url.searchParams.append("onlySteelSeriesVAD", String(onlySteelSeriesVAD));
492
+ url.searchParams.append("removeSteelSeriesVAD", String(removeSteelSeriesVAD));
493
+ if (deviceDataFlow !== undefined) {
494
+ url.searchParams.append("deviceDataFlow", deviceDataFlow.toString());
495
+ }
496
+ let response;
497
+ try {
498
+ response = await fetch(url);
499
+ } catch (error) {
500
+ throw new SonarRequestException({
501
+ innerException: error
502
+ });
503
+ }
504
+ if (!response.ok) {
505
+ const error = await response.text();
506
+ throw new SonarRequestException({ message: `Failed to get audio devices: ${error}` });
507
+ }
508
+ const data = await response.json();
509
+ if (!Array.isArray(data)) {
510
+ throw new SonarRequestException({ message: "Invalid audio devices response format." });
511
+ }
512
+ return data;
513
+ }
514
+
515
+ // src/functions/devices/get-audio-devices.ts
516
+ async function getAudioDevices(sonarEndpoint, deviceType) {
517
+ let deviceDataFlow;
518
+ switch (deviceType) {
519
+ case "input" /* Input */:
520
+ deviceDataFlow = "capture" /* Capture */;
521
+ break;
522
+ case "output" /* Output */:
523
+ deviceDataFlow = "render" /* Render */;
524
+ break;
525
+ case undefined:
526
+ deviceDataFlow = "all" /* All */;
527
+ break;
528
+ }
529
+ const data = await requestAudioDevices(sonarEndpoint, { deviceDataFlow, removeSteelSeriesVAD: true });
530
+ const audioDevices = data.map((device) => ({
531
+ id: device.id,
532
+ name: device.friendlyName,
533
+ type: getDeviceTypeFromDataFlow(device.dataFlow)
534
+ }));
535
+ return audioDevices;
536
+ }
537
+ function getDeviceTypeFromDataFlow(dataFlow) {
538
+ switch (dataFlow) {
539
+ case "capture" /* Capture */:
540
+ return "input" /* Input */;
541
+ case "render" /* Render */:
542
+ return "output" /* Output */;
543
+ default:
544
+ throw new SonarRequestException({ message: `Unknown device data flow: ${dataFlow}` });
545
+ }
546
+ }
547
+ // src/sonar/requests/audio-devices/change-audio-device.ts
548
+ async function changeAudioDevice(sonarEndpoint, deviceChannel, deviceId) {
549
+ let response;
550
+ const url = new URL(`${sonarEndpoint}/classicRedirections/${deviceChannel}/deviceId/${deviceId}`);
551
+ try {
552
+ response = await fetch(url, { method: "PUT" });
553
+ } catch (error) {
554
+ throw new SonarRequestException({
555
+ innerException: error
556
+ });
557
+ }
558
+ if (!response.ok) {
559
+ const error = await response.text();
560
+ throw new SonarRequestException({ message: `Failed to get audio devices: ${error}` });
561
+ }
562
+ const unknownData = await response.json();
563
+ const data = Array.isArray(unknownData) ? unknownData : [unknownData];
564
+ const devices = data.filter((x) => x?.deviceId === deviceId);
565
+ if (devices.length === 0) {
566
+ throw new SonarRequestException({ message: "The changed audio devices list is empty." });
567
+ }
568
+ return devices;
569
+ }
570
+
571
+ // src/functions/devices/set-audio-device.ts
572
+ async function setAudioDevice(sonarEndpoint, deviceChannel, deviceId) {
573
+ const data = await changeAudioDevice(sonarEndpoint, deviceChannel, deviceId);
574
+ const result = data.map((x) => ({
575
+ deviceId: x.deviceId,
576
+ deviceChannel: x.id,
577
+ isRunning: x.isRunning
578
+ }));
579
+ return result;
580
+ }
581
+ // src/functions/endpoint/get-app-endpoint.ts
582
+ import { promises as fsAsync } from "node:fs";
583
+ import { platform as getPlatform } from "node:os";
584
+ import { join as joinPath } from "node:path";
585
+ var WINDOWS_PATHS = ["SteelSeries", "SteelSeries Engine 3", "coreProps.json"];
586
+ async function getAppEndpoint() {
587
+ const appDataPath = getPath();
588
+ const fileContents = await getContents(appDataPath);
589
+ const data = parseContents(fileContents);
590
+ if (data.ggEncryptedAddress) {
591
+ return `https://${data.ggEncryptedAddress}`;
592
+ }
593
+ throw new SonarInitializationException({
594
+ reason: "Bad Config" /* BadConfig */
595
+ });
596
+ }
597
+ function getPath() {
598
+ const os = getPlatform();
599
+ switch (os) {
600
+ case "win32": {
601
+ const programData = process.env.ProgramData ?? "C:\\ProgramData";
602
+ return joinPath(programData, ...WINDOWS_PATHS);
603
+ }
604
+ default:
605
+ throw new SonarInitializationException({
606
+ reason: "OS Unsupported" /* OSUnsupported */
607
+ });
608
+ }
609
+ }
610
+ async function getContents(path) {
611
+ try {
612
+ return await fsAsync.readFile(path, "utf8");
613
+ } catch (error) {
614
+ throw new SonarInitializationException({
615
+ reason: "Bad Config" /* BadConfig */,
616
+ innerException: error
617
+ });
618
+ }
619
+ }
620
+ function parseContents(contents) {
621
+ try {
622
+ return JSON.parse(contents);
623
+ } catch (error) {
624
+ throw new SonarInitializationException({
625
+ reason: "Bad Config" /* BadConfig */,
626
+ innerException: error
627
+ });
628
+ }
629
+ }
630
+ // src/functions/endpoint/get-sonar-endpoint.ts
631
+ async function getSonarEndpoint(appEndpoint) {
632
+ let response;
633
+ try {
634
+ response = await fetch(`${appEndpoint}/subApps`, {
635
+ tls: {
636
+ rejectUnauthorized: false
637
+ }
638
+ });
639
+ } catch (error) {
640
+ throw new SonarInitializationException({
641
+ reason: "Not Responding" /* NotResponding */,
642
+ innerException: error
643
+ });
644
+ }
645
+ if (!response.ok) {
646
+ throw new SonarInitializationException({
647
+ reason: "Not Responding" /* NotResponding */
648
+ });
649
+ }
650
+ const result = await response.json();
651
+ const sonar = result?.subApps?.sonar;
652
+ if (!sonar) {
653
+ throw new SonarInitializationException({
654
+ reason: "Not Available" /* NotAvailable */
655
+ });
656
+ }
657
+ if (!sonar.isEnabled) {
658
+ throw new SonarInitializationException({
659
+ reason: "Not Enabled" /* NotEnabled */
660
+ });
661
+ }
662
+ if (!sonar.isRunning) {
663
+ throw new SonarInitializationException({
664
+ reason: "Not Running" /* NotRunning */
665
+ });
666
+ }
667
+ if (!sonar.isReady) {
668
+ throw new SonarInitializationException({
669
+ reason: "Not Ready" /* NotReady */
670
+ });
671
+ }
672
+ const sonarAddress = sonar.metadata?.webServerAddress;
673
+ if (!sonarAddress) {
674
+ throw new SonarInitializationException({
675
+ reason: "Not Available" /* NotAvailable */
676
+ });
677
+ }
678
+ return sonarAddress;
679
+ }
680
+ // src/functions/endpoint/get-sonar-endpoint-cached.ts
681
+ var cache = {
682
+ appAddress: null,
683
+ sonarAddress: null,
684
+ timestamp: 0
685
+ };
686
+ async function getSonarEndpointCached(appAddress, seconds = 60) {
687
+ const now = Date.now();
688
+ if (cache.appAddress === appAddress && cache.sonarAddress && now - cache.timestamp < seconds * 1000) {
689
+ return cache.sonarAddress;
690
+ }
691
+ try {
692
+ const sonarAddress = await getSonarEndpoint(appAddress);
693
+ cache.appAddress = appAddress;
694
+ cache.sonarAddress = sonarAddress;
695
+ cache.timestamp = now;
696
+ return sonarAddress;
697
+ } catch (error) {
698
+ cache.appAddress = null;
699
+ cache.sonarAddress = null;
700
+ cache.timestamp = 0;
701
+ throw error;
702
+ }
703
+ }
704
+ // src/functions/converters/convert-profile-channel-to-api.ts
705
+ function convertProfileChannelToApi(channel) {
706
+ switch (channel) {
707
+ case "game" /* Game */:
708
+ return "game" /* Game */;
709
+ case "chat" /* Chat */:
710
+ return "chatRender" /* ChatRender */;
711
+ case "media" /* Media */:
712
+ return "media" /* Media */;
713
+ case "aux" /* Aux */:
714
+ return "aux" /* Aux */;
715
+ case "mic" /* Mic */:
716
+ return "chatCapture" /* ChatCapture */;
717
+ default:
718
+ throw new Error(`Unsupported ProfileChannel: ${channel}`);
719
+ }
720
+ }
721
+
722
+ // src/functions/converters/convert-profile-channel-to-user.ts
723
+ function convertProfileChannelToUser(channel) {
724
+ switch (channel) {
725
+ case "game" /* Game */:
726
+ return "game" /* Game */;
727
+ case "chatRender" /* ChatRender */:
728
+ return "chat" /* Chat */;
729
+ case "media" /* Media */:
730
+ return "media" /* Media */;
731
+ case "aux" /* Aux */:
732
+ return "aux" /* Aux */;
733
+ case "chatCapture" /* ChatCapture */:
734
+ return "mic" /* Mic */;
735
+ default:
736
+ throw new Error(`Unsupported ProfileChannel: ${channel}`);
737
+ }
738
+ }
739
+
740
+ // src/sonar/requests/profiles/request-configs.ts
741
+ async function requestConfigs(sonarAddress, channel) {
742
+ let response;
743
+ try {
744
+ response = await fetch(`${sonarAddress}/configs?vad=${channel}`);
745
+ } catch (error) {
746
+ throw new SonarRequestException({ innerException: error });
747
+ }
748
+ if (response.ok) {
749
+ const data = await response.json();
750
+ if (!Array.isArray(data)) {
751
+ throw new SonarRequestException({ message: "Missing required data in response" });
752
+ }
753
+ return data;
754
+ } else {
755
+ const data = await response.json();
756
+ throw new SonarRequestException({ innerException: new Error(data?.error ?? data) });
757
+ }
758
+ }
759
+
760
+ // src/functions/profile/get-channel-profiles.ts
761
+ async function getChannelProfiles(sonarAddress, channel, favoritesOnly) {
762
+ const vad = convertProfileChannelToApi(channel);
763
+ const data = await requestConfigs(sonarAddress, vad);
764
+ const workingSetData = favoritesOnly ? data.filter((x) => x.isFavorite) : data;
765
+ return workingSetData.map((x) => {
766
+ const profile = {
767
+ id: x.id,
768
+ name: x.name,
769
+ isFavorite: x.isFavorite,
770
+ channel: convertProfileChannelToUser(x.virtualAudioDevice),
771
+ image: x.image
772
+ };
773
+ return profile;
774
+ });
775
+ }
776
+ // src/sonar/requests/profiles/request-selected-configs.ts
777
+ async function requestSelectedConfigs(sonarAddress) {
778
+ let response;
779
+ try {
780
+ response = await fetch(`${sonarAddress}/configs/selected`);
781
+ } catch (error) {
782
+ throw new SonarRequestException({ innerException: error });
783
+ }
784
+ if (response.ok) {
785
+ const data = await response.json();
786
+ if (!Array.isArray(data)) {
787
+ throw new SonarRequestException({ message: "Missing required data in response" });
788
+ }
789
+ return data;
790
+ } else {
791
+ const data = await response.json();
792
+ throw new SonarRequestException({ innerException: new Error(data?.error ?? data) });
793
+ }
794
+ }
795
+
796
+ // src/functions/profile/get-selected-profiles.ts
797
+ async function getSelectedProfiles(sonarAddress) {
798
+ const data = await requestSelectedConfigs(sonarAddress);
799
+ return data.map((x) => {
800
+ const profile = {
801
+ id: x.id,
802
+ name: x.name,
803
+ isFavorite: x.isFavorite,
804
+ channel: convertProfileChannelToUser(x.virtualAudioDevice),
805
+ image: x.image
806
+ };
807
+ return profile;
808
+ });
809
+ }
810
+ // src/sonar/requests/profiles/change-selected-config.ts
811
+ async function changeSelectedConfig(sonarAddress, configId) {
812
+ let response;
813
+ try {
814
+ response = await fetch(`${sonarAddress}/configs/${configId}/select`, {
815
+ method: "PUT"
816
+ });
817
+ } catch (error) {
818
+ throw new SonarRequestException({ innerException: error });
819
+ }
820
+ if (response.ok) {
821
+ const data = await response.json();
822
+ if (!data?.id) {
823
+ throw new SonarRequestException({ message: "Missing required data in response" });
824
+ }
825
+ return data;
826
+ } else {
827
+ const data = await response.json();
828
+ throw new SonarRequestException({ innerException: new Error(data?.error ?? data) });
829
+ }
830
+ }
831
+
832
+ // src/functions/profile/set-selected-profile.ts
833
+ async function setSelectedProfile(sonarAddress, profileId) {
834
+ const data = await changeSelectedConfig(sonarAddress, profileId);
835
+ const result = {
836
+ id: data.id,
837
+ name: data.name,
838
+ isFavorite: data.isFavorite,
839
+ channel: convertProfileChannelToUser(data.virtualAudioDevice),
840
+ image: data.image
841
+ };
842
+ return result;
843
+ }
844
+ export {
845
+ setSelectedProfile,
846
+ setChatMixBalance,
847
+ setChannelVolumeStreamer,
848
+ setChannelVolumeClassic,
849
+ setChannelMuteStreamer,
850
+ setChannelMuteClassic,
851
+ setAudioMode,
852
+ setAudioDevice,
853
+ getSonarEndpointCached,
854
+ getSonarEndpoint,
855
+ getSelectedProfiles,
856
+ getChatMixState,
857
+ getChannelProfiles,
858
+ getAudioMode,
859
+ getAudioDevices,
860
+ getAudioDataStream,
861
+ getAudioDataClassic,
862
+ getAppEndpoint,
863
+ StreamerPath,
864
+ SonarRequestException,
865
+ SonarInitializationException,
866
+ SonarException,
867
+ ProfileChannel,
868
+ InitializeErrorReason,
869
+ DeviceFlow,
870
+ DeviceChannel,
871
+ ChatMixState,
872
+ AudioMode,
873
+ AudioChannel
874
+ };