@capawesome/capacitor-audio-session 0.0.1

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 (35) hide show
  1. package/CapawesomeCapacitorAudioSession.podspec +17 -0
  2. package/LICENSE +21 -0
  3. package/Package.swift +28 -0
  4. package/README.md +389 -0
  5. package/android/build.gradle +58 -0
  6. package/android/src/main/AndroidManifest.xml +2 -0
  7. package/android/src/main/java/io/capawesome/capacitorjs/plugins/audiosession/AudioSessionPlugin.java +35 -0
  8. package/android/src/main/res/.gitkeep +0 -0
  9. package/dist/docs.json +759 -0
  10. package/dist/esm/definitions.d.ts +287 -0
  11. package/dist/esm/definitions.js +19 -0
  12. package/dist/esm/definitions.js.map +1 -0
  13. package/dist/esm/index.d.ts +4 -0
  14. package/dist/esm/index.js +7 -0
  15. package/dist/esm/index.js.map +1 -0
  16. package/dist/esm/web.d.ts +8 -0
  17. package/dist/esm/web.js +16 -0
  18. package/dist/esm/web.js.map +1 -0
  19. package/dist/plugin.cjs.js +49 -0
  20. package/dist/plugin.cjs.js.map +1 -0
  21. package/dist/plugin.js +52 -0
  22. package/dist/plugin.js.map +1 -0
  23. package/ios/Plugin/AudioSession.swift +127 -0
  24. package/ios/Plugin/AudioSessionPlugin.swift +103 -0
  25. package/ios/Plugin/Classes/Events/InterruptionEvent.swift +19 -0
  26. package/ios/Plugin/Classes/Events/RouteChangeEvent.swift +19 -0
  27. package/ios/Plugin/Classes/Options/ConfigureOptions.swift +101 -0
  28. package/ios/Plugin/Classes/Options/OverrideOutputOptions.swift +24 -0
  29. package/ios/Plugin/Classes/Options/SetActiveOptions.swift +27 -0
  30. package/ios/Plugin/Classes/Results/AudioSessionOutput.swift +19 -0
  31. package/ios/Plugin/Classes/Results/GetCurrentOutputsResult.swift +16 -0
  32. package/ios/Plugin/Enums/CustomError.swift +36 -0
  33. package/ios/Plugin/Info.plist +24 -0
  34. package/ios/Plugin/Protocols/Result.swift +5 -0
  35. package/package.json +91 -0
@@ -0,0 +1,287 @@
1
+ import type { PluginListenerHandle } from '@capacitor/core';
2
+ export interface AudioSessionPlugin {
3
+ /**
4
+ * Called when the audio session is interrupted, e.g. by an incoming phone call.
5
+ *
6
+ * Only available on iOS.
7
+ *
8
+ * @since 0.1.0
9
+ */
10
+ addListener(eventName: 'interruption', listenerFunc: (event: InterruptionEvent) => void): Promise<PluginListenerHandle>;
11
+ /**
12
+ * Called when the audio route changes, e.g. when headphones are plugged in or out.
13
+ *
14
+ * Only available on iOS.
15
+ *
16
+ * @since 0.1.0
17
+ */
18
+ addListener(eventName: 'routeChange', listenerFunc: (event: RouteChangeEvent) => void): Promise<PluginListenerHandle>;
19
+ /**
20
+ * Configure the audio session category, mode and options.
21
+ *
22
+ * Only available on iOS.
23
+ *
24
+ * @since 0.1.0
25
+ */
26
+ configure(options: ConfigureOptions): Promise<void>;
27
+ /**
28
+ * Get the audio outputs of the current audio route.
29
+ *
30
+ * Only available on iOS.
31
+ *
32
+ * @since 0.1.0
33
+ */
34
+ getCurrentOutputs(): Promise<GetCurrentOutputsResult>;
35
+ /**
36
+ * Override the audio output port that is used for playback.
37
+ *
38
+ * Only available on iOS.
39
+ *
40
+ * @since 0.1.0
41
+ */
42
+ overrideOutput(options: OverrideOutputOptions): Promise<void>;
43
+ /**
44
+ * Remove all listeners for this plugin.
45
+ *
46
+ * Only available on iOS.
47
+ *
48
+ * @since 0.1.0
49
+ */
50
+ removeAllListeners(): Promise<void>;
51
+ /**
52
+ * Activate or deactivate the audio session.
53
+ *
54
+ * Only available on iOS.
55
+ *
56
+ * @since 0.1.0
57
+ */
58
+ setActive(options: SetActiveOptions): Promise<void>;
59
+ }
60
+ /**
61
+ * @since 0.1.0
62
+ */
63
+ export interface ConfigureOptions {
64
+ /**
65
+ * The audio session category.
66
+ *
67
+ * @example 'playback'
68
+ * @since 0.1.0
69
+ */
70
+ category: AudioSessionCategory;
71
+ /**
72
+ * The audio session mode.
73
+ *
74
+ * @default 'default'
75
+ * @example 'moviePlayback'
76
+ * @since 0.1.0
77
+ */
78
+ mode?: AudioSessionMode;
79
+ /**
80
+ * The audio session category options.
81
+ *
82
+ * @since 0.1.0
83
+ */
84
+ options?: AudioSessionCategoryOptions;
85
+ }
86
+ /**
87
+ * @since 0.1.0
88
+ */
89
+ export interface AudioSessionCategoryOptions {
90
+ /**
91
+ * Whether AirPlay devices can be used for output.
92
+ *
93
+ * @default false
94
+ * @since 0.1.0
95
+ */
96
+ allowAirPlay?: boolean;
97
+ /**
98
+ * Whether Bluetooth hands-free devices can be used for input and output.
99
+ *
100
+ * @default false
101
+ * @since 0.1.0
102
+ */
103
+ allowBluetooth?: boolean;
104
+ /**
105
+ * Whether Bluetooth A2DP devices can be used for output.
106
+ *
107
+ * @default false
108
+ * @since 0.1.0
109
+ */
110
+ allowBluetoothA2DP?: boolean;
111
+ /**
112
+ * Whether audio is routed to the built-in speaker instead of the receiver
113
+ * when no other audio route is connected.
114
+ *
115
+ * @default false
116
+ * @since 0.1.0
117
+ */
118
+ defaultToSpeaker?: boolean;
119
+ /**
120
+ * Whether audio from other sessions is reduced in volume (ducked) while audio
121
+ * from this session plays.
122
+ *
123
+ * @default false
124
+ * @since 0.1.0
125
+ */
126
+ duckOthers?: boolean;
127
+ /**
128
+ * Whether audio from other sessions using the `spokenAudio` mode is interrupted
129
+ * and audio from this session is mixed with the remaining audio.
130
+ *
131
+ * @default false
132
+ * @since 0.1.0
133
+ */
134
+ interruptSpokenAudioAndMixWithOthers?: boolean;
135
+ /**
136
+ * Whether audio from this session mixes with audio from other active sessions
137
+ * instead of interrupting them.
138
+ *
139
+ * @default false
140
+ * @since 0.1.0
141
+ */
142
+ mixWithOthers?: boolean;
143
+ }
144
+ /**
145
+ * @since 0.1.0
146
+ */
147
+ export interface SetActiveOptions {
148
+ /**
149
+ * Whether the audio session should be activated (`true`) or deactivated (`false`).
150
+ *
151
+ * @since 0.1.0
152
+ */
153
+ active: boolean;
154
+ /**
155
+ * Whether other audio sessions are notified when this session is deactivated,
156
+ * so they can resume playback.
157
+ *
158
+ * @default true
159
+ * @since 0.1.0
160
+ */
161
+ notifyOthersOnDeactivation?: boolean;
162
+ }
163
+ /**
164
+ * @since 0.1.0
165
+ */
166
+ export interface GetCurrentOutputsResult {
167
+ /**
168
+ * The audio outputs of the current audio route.
169
+ *
170
+ * @since 0.1.0
171
+ */
172
+ outputs: AudioSessionOutput[];
173
+ }
174
+ /**
175
+ * @since 0.1.0
176
+ */
177
+ export interface OverrideOutputOptions {
178
+ /**
179
+ * The audio output port to route playback to.
180
+ *
181
+ * @example 'speaker'
182
+ * @since 0.1.0
183
+ */
184
+ type: OverrideOutputType;
185
+ }
186
+ /**
187
+ * @since 0.1.0
188
+ */
189
+ export interface AudioSessionOutput {
190
+ /**
191
+ * The human-readable name of the audio output port.
192
+ *
193
+ * @example 'Speaker'
194
+ * @since 0.1.0
195
+ */
196
+ portName: string;
197
+ /**
198
+ * The type of the audio output port.
199
+ *
200
+ * @example 'Speaker'
201
+ * @since 0.1.0
202
+ */
203
+ portType: string;
204
+ }
205
+ /**
206
+ * @since 0.1.0
207
+ */
208
+ export interface InterruptionEvent {
209
+ /**
210
+ * Whether playback should resume after the interruption ended.
211
+ *
212
+ * Only `true` if `type` is `ended`.
213
+ *
214
+ * @since 0.1.0
215
+ */
216
+ shouldResume: boolean;
217
+ /**
218
+ * The type of the interruption.
219
+ *
220
+ * @since 0.1.0
221
+ */
222
+ type: InterruptionType;
223
+ }
224
+ /**
225
+ * @since 0.1.0
226
+ */
227
+ export interface RouteChangeEvent {
228
+ /**
229
+ * The audio outputs of the audio route after the change.
230
+ *
231
+ * @since 0.1.0
232
+ */
233
+ outputs: AudioSessionOutput[];
234
+ /**
235
+ * The reason why the audio route changed.
236
+ *
237
+ * @since 0.1.0
238
+ */
239
+ reason: RouteChangeReason;
240
+ }
241
+ /**
242
+ * The audio session category.
243
+ *
244
+ * @since 0.1.0
245
+ */
246
+ export type AudioSessionCategory = 'ambient' | 'multiRoute' | 'playAndRecord' | 'playback' | 'record' | 'soloAmbient';
247
+ /**
248
+ * The audio session mode.
249
+ *
250
+ * @since 0.1.0
251
+ */
252
+ export type AudioSessionMode = 'default' | 'gameChat' | 'measurement' | 'moviePlayback' | 'spokenAudio' | 'videoChat' | 'videoRecording' | 'voiceChat' | 'voicePrompt';
253
+ /**
254
+ * The audio output port to route playback to.
255
+ *
256
+ * @since 0.1.0
257
+ */
258
+ export type OverrideOutputType = 'default' | 'speaker';
259
+ /**
260
+ * The type of an audio session interruption.
261
+ *
262
+ * @since 0.1.0
263
+ */
264
+ export type InterruptionType = 'began' | 'ended';
265
+ /**
266
+ * The reason why the audio route changed.
267
+ *
268
+ * @since 0.1.0
269
+ */
270
+ export type RouteChangeReason = 'categoryChange' | 'newDeviceAvailable' | 'noSuitableRouteForCategory' | 'oldDeviceUnavailable' | 'override' | 'routeConfigurationChange' | 'unknown' | 'wakeFromSleep';
271
+ /**
272
+ * @since 0.1.0
273
+ */
274
+ export declare enum ErrorCode {
275
+ /**
276
+ * The audio session could not be activated or deactivated.
277
+ *
278
+ * @since 0.1.0
279
+ */
280
+ ActivationFailed = "ACTIVATION_FAILED",
281
+ /**
282
+ * The audio session could not be configured.
283
+ *
284
+ * @since 0.1.0
285
+ */
286
+ ConfigurationFailed = "CONFIGURATION_FAILED"
287
+ }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * @since 0.1.0
3
+ */
4
+ export var ErrorCode;
5
+ (function (ErrorCode) {
6
+ /**
7
+ * The audio session could not be activated or deactivated.
8
+ *
9
+ * @since 0.1.0
10
+ */
11
+ ErrorCode["ActivationFailed"] = "ACTIVATION_FAILED";
12
+ /**
13
+ * The audio session could not be configured.
14
+ *
15
+ * @since 0.1.0
16
+ */
17
+ ErrorCode["ConfigurationFailed"] = "CONFIGURATION_FAILED";
18
+ })(ErrorCode || (ErrorCode = {}));
19
+ //# sourceMappingURL=definitions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"AA0TA;;GAEG;AACH,MAAM,CAAN,IAAY,SAaX;AAbD,WAAY,SAAS;IACnB;;;;OAIG;IACH,mDAAsC,CAAA;IACtC;;;;OAIG;IACH,yDAA4C,CAAA;AAC9C,CAAC,EAbW,SAAS,KAAT,SAAS,QAapB","sourcesContent":["import type { PluginListenerHandle } from '@capacitor/core';\n\nexport interface AudioSessionPlugin {\n /**\n * Called when the audio session is interrupted, e.g. by an incoming phone call.\n *\n * Only available on iOS.\n *\n * @since 0.1.0\n */\n addListener(\n eventName: 'interruption',\n listenerFunc: (event: InterruptionEvent) => void,\n ): Promise<PluginListenerHandle>;\n /**\n * Called when the audio route changes, e.g. when headphones are plugged in or out.\n *\n * Only available on iOS.\n *\n * @since 0.1.0\n */\n addListener(\n eventName: 'routeChange',\n listenerFunc: (event: RouteChangeEvent) => void,\n ): Promise<PluginListenerHandle>;\n /**\n * Configure the audio session category, mode and options.\n *\n * Only available on iOS.\n *\n * @since 0.1.0\n */\n configure(options: ConfigureOptions): Promise<void>;\n /**\n * Get the audio outputs of the current audio route.\n *\n * Only available on iOS.\n *\n * @since 0.1.0\n */\n getCurrentOutputs(): Promise<GetCurrentOutputsResult>;\n /**\n * Override the audio output port that is used for playback.\n *\n * Only available on iOS.\n *\n * @since 0.1.0\n */\n overrideOutput(options: OverrideOutputOptions): Promise<void>;\n /**\n * Remove all listeners for this plugin.\n *\n * Only available on iOS.\n *\n * @since 0.1.0\n */\n removeAllListeners(): Promise<void>;\n /**\n * Activate or deactivate the audio session.\n *\n * Only available on iOS.\n *\n * @since 0.1.0\n */\n setActive(options: SetActiveOptions): Promise<void>;\n}\n\n/**\n * @since 0.1.0\n */\nexport interface ConfigureOptions {\n /**\n * The audio session category.\n *\n * @example 'playback'\n * @since 0.1.0\n */\n category: AudioSessionCategory;\n /**\n * The audio session mode.\n *\n * @default 'default'\n * @example 'moviePlayback'\n * @since 0.1.0\n */\n mode?: AudioSessionMode;\n /**\n * The audio session category options.\n *\n * @since 0.1.0\n */\n options?: AudioSessionCategoryOptions;\n}\n\n/**\n * @since 0.1.0\n */\nexport interface AudioSessionCategoryOptions {\n /**\n * Whether AirPlay devices can be used for output.\n *\n * @default false\n * @since 0.1.0\n */\n allowAirPlay?: boolean;\n /**\n * Whether Bluetooth hands-free devices can be used for input and output.\n *\n * @default false\n * @since 0.1.0\n */\n allowBluetooth?: boolean;\n /**\n * Whether Bluetooth A2DP devices can be used for output.\n *\n * @default false\n * @since 0.1.0\n */\n allowBluetoothA2DP?: boolean;\n /**\n * Whether audio is routed to the built-in speaker instead of the receiver\n * when no other audio route is connected.\n *\n * @default false\n * @since 0.1.0\n */\n defaultToSpeaker?: boolean;\n /**\n * Whether audio from other sessions is reduced in volume (ducked) while audio\n * from this session plays.\n *\n * @default false\n * @since 0.1.0\n */\n duckOthers?: boolean;\n /**\n * Whether audio from other sessions using the `spokenAudio` mode is interrupted\n * and audio from this session is mixed with the remaining audio.\n *\n * @default false\n * @since 0.1.0\n */\n interruptSpokenAudioAndMixWithOthers?: boolean;\n /**\n * Whether audio from this session mixes with audio from other active sessions\n * instead of interrupting them.\n *\n * @default false\n * @since 0.1.0\n */\n mixWithOthers?: boolean;\n}\n\n/**\n * @since 0.1.0\n */\nexport interface SetActiveOptions {\n /**\n * Whether the audio session should be activated (`true`) or deactivated (`false`).\n *\n * @since 0.1.0\n */\n active: boolean;\n /**\n * Whether other audio sessions are notified when this session is deactivated,\n * so they can resume playback.\n *\n * @default true\n * @since 0.1.0\n */\n notifyOthersOnDeactivation?: boolean;\n}\n\n/**\n * @since 0.1.0\n */\nexport interface GetCurrentOutputsResult {\n /**\n * The audio outputs of the current audio route.\n *\n * @since 0.1.0\n */\n outputs: AudioSessionOutput[];\n}\n\n/**\n * @since 0.1.0\n */\nexport interface OverrideOutputOptions {\n /**\n * The audio output port to route playback to.\n *\n * @example 'speaker'\n * @since 0.1.0\n */\n type: OverrideOutputType;\n}\n\n/**\n * @since 0.1.0\n */\nexport interface AudioSessionOutput {\n /**\n * The human-readable name of the audio output port.\n *\n * @example 'Speaker'\n * @since 0.1.0\n */\n portName: string;\n /**\n * The type of the audio output port.\n *\n * @example 'Speaker'\n * @since 0.1.0\n */\n portType: string;\n}\n\n/**\n * @since 0.1.0\n */\nexport interface InterruptionEvent {\n /**\n * Whether playback should resume after the interruption ended.\n *\n * Only `true` if `type` is `ended`.\n *\n * @since 0.1.0\n */\n shouldResume: boolean;\n /**\n * The type of the interruption.\n *\n * @since 0.1.0\n */\n type: InterruptionType;\n}\n\n/**\n * @since 0.1.0\n */\nexport interface RouteChangeEvent {\n /**\n * The audio outputs of the audio route after the change.\n *\n * @since 0.1.0\n */\n outputs: AudioSessionOutput[];\n /**\n * The reason why the audio route changed.\n *\n * @since 0.1.0\n */\n reason: RouteChangeReason;\n}\n\n/**\n * The audio session category.\n *\n * @since 0.1.0\n */\nexport type AudioSessionCategory =\n | 'ambient'\n | 'multiRoute'\n | 'playAndRecord'\n | 'playback'\n | 'record'\n | 'soloAmbient';\n\n/**\n * The audio session mode.\n *\n * @since 0.1.0\n */\nexport type AudioSessionMode =\n | 'default'\n | 'gameChat'\n | 'measurement'\n | 'moviePlayback'\n | 'spokenAudio'\n | 'videoChat'\n | 'videoRecording'\n | 'voiceChat'\n | 'voicePrompt';\n\n/**\n * The audio output port to route playback to.\n *\n * @since 0.1.0\n */\nexport type OverrideOutputType = 'default' | 'speaker';\n\n/**\n * The type of an audio session interruption.\n *\n * @since 0.1.0\n */\nexport type InterruptionType = 'began' | 'ended';\n\n/**\n * The reason why the audio route changed.\n *\n * @since 0.1.0\n */\nexport type RouteChangeReason =\n | 'categoryChange'\n | 'newDeviceAvailable'\n | 'noSuitableRouteForCategory'\n | 'oldDeviceUnavailable'\n | 'override'\n | 'routeConfigurationChange'\n | 'unknown'\n | 'wakeFromSleep';\n\n/**\n * @since 0.1.0\n */\nexport enum ErrorCode {\n /**\n * The audio session could not be activated or deactivated.\n *\n * @since 0.1.0\n */\n ActivationFailed = 'ACTIVATION_FAILED',\n /**\n * The audio session could not be configured.\n *\n * @since 0.1.0\n */\n ConfigurationFailed = 'CONFIGURATION_FAILED',\n}\n"]}
@@ -0,0 +1,4 @@
1
+ import type { AudioSessionPlugin } from './definitions';
2
+ declare const AudioSession: AudioSessionPlugin;
3
+ export * from './definitions';
4
+ export { AudioSession };
@@ -0,0 +1,7 @@
1
+ import { registerPlugin } from '@capacitor/core';
2
+ const AudioSession = registerPlugin('AudioSession', {
3
+ web: () => import('./web').then(m => new m.AudioSessionWeb()),
4
+ });
5
+ export * from './definitions';
6
+ export { AudioSession };
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAIjD,MAAM,YAAY,GAAG,cAAc,CAAqB,cAAc,EAAE;IACtE,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,eAAe,EAAE,CAAC;CAC9D,CAAC,CAAC;AAEH,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,YAAY,EAAE,CAAC","sourcesContent":["import { registerPlugin } from '@capacitor/core';\n\nimport type { AudioSessionPlugin } from './definitions';\n\nconst AudioSession = registerPlugin<AudioSessionPlugin>('AudioSession', {\n web: () => import('./web').then(m => new m.AudioSessionWeb()),\n});\n\nexport * from './definitions';\nexport { AudioSession };\n"]}
@@ -0,0 +1,8 @@
1
+ import { WebPlugin } from '@capacitor/core';
2
+ import type { AudioSessionPlugin, ConfigureOptions, GetCurrentOutputsResult, OverrideOutputOptions, SetActiveOptions } from './definitions';
3
+ export declare class AudioSessionWeb extends WebPlugin implements AudioSessionPlugin {
4
+ configure(_options: ConfigureOptions): Promise<void>;
5
+ getCurrentOutputs(): Promise<GetCurrentOutputsResult>;
6
+ overrideOutput(_options: OverrideOutputOptions): Promise<void>;
7
+ setActive(_options: SetActiveOptions): Promise<void>;
8
+ }
@@ -0,0 +1,16 @@
1
+ import { WebPlugin } from '@capacitor/core';
2
+ export class AudioSessionWeb extends WebPlugin {
3
+ async configure(_options) {
4
+ throw this.unimplemented('Not implemented on web.');
5
+ }
6
+ async getCurrentOutputs() {
7
+ throw this.unimplemented('Not implemented on web.');
8
+ }
9
+ async overrideOutput(_options) {
10
+ throw this.unimplemented('Not implemented on web.');
11
+ }
12
+ async setActive(_options) {
13
+ throw this.unimplemented('Not implemented on web.');
14
+ }
15
+ }
16
+ //# sourceMappingURL=web.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAU5C,MAAM,OAAO,eAAgB,SAAQ,SAAS;IAC5C,KAAK,CAAC,SAAS,CAAC,QAA0B;QACxC,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC,CAAC;IACtD,CAAC;IAED,KAAK,CAAC,iBAAiB;QACrB,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC,CAAC;IACtD,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,QAA+B;QAClD,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC,CAAC;IACtD,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,QAA0B;QACxC,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC,CAAC;IACtD,CAAC;CACF","sourcesContent":["import { WebPlugin } from '@capacitor/core';\n\nimport type {\n AudioSessionPlugin,\n ConfigureOptions,\n GetCurrentOutputsResult,\n OverrideOutputOptions,\n SetActiveOptions,\n} from './definitions';\n\nexport class AudioSessionWeb extends WebPlugin implements AudioSessionPlugin {\n async configure(_options: ConfigureOptions): Promise<void> {\n throw this.unimplemented('Not implemented on web.');\n }\n\n async getCurrentOutputs(): Promise<GetCurrentOutputsResult> {\n throw this.unimplemented('Not implemented on web.');\n }\n\n async overrideOutput(_options: OverrideOutputOptions): Promise<void> {\n throw this.unimplemented('Not implemented on web.');\n }\n\n async setActive(_options: SetActiveOptions): Promise<void> {\n throw this.unimplemented('Not implemented on web.');\n }\n}\n"]}
@@ -0,0 +1,49 @@
1
+ 'use strict';
2
+
3
+ var core = require('@capacitor/core');
4
+
5
+ /**
6
+ * @since 0.1.0
7
+ */
8
+ exports.ErrorCode = void 0;
9
+ (function (ErrorCode) {
10
+ /**
11
+ * The audio session could not be activated or deactivated.
12
+ *
13
+ * @since 0.1.0
14
+ */
15
+ ErrorCode["ActivationFailed"] = "ACTIVATION_FAILED";
16
+ /**
17
+ * The audio session could not be configured.
18
+ *
19
+ * @since 0.1.0
20
+ */
21
+ ErrorCode["ConfigurationFailed"] = "CONFIGURATION_FAILED";
22
+ })(exports.ErrorCode || (exports.ErrorCode = {}));
23
+
24
+ const AudioSession = core.registerPlugin('AudioSession', {
25
+ web: () => Promise.resolve().then(function () { return web; }).then(m => new m.AudioSessionWeb()),
26
+ });
27
+
28
+ class AudioSessionWeb extends core.WebPlugin {
29
+ async configure(_options) {
30
+ throw this.unimplemented('Not implemented on web.');
31
+ }
32
+ async getCurrentOutputs() {
33
+ throw this.unimplemented('Not implemented on web.');
34
+ }
35
+ async overrideOutput(_options) {
36
+ throw this.unimplemented('Not implemented on web.');
37
+ }
38
+ async setActive(_options) {
39
+ throw this.unimplemented('Not implemented on web.');
40
+ }
41
+ }
42
+
43
+ var web = /*#__PURE__*/Object.freeze({
44
+ __proto__: null,
45
+ AudioSessionWeb: AudioSessionWeb
46
+ });
47
+
48
+ exports.AudioSession = AudioSession;
49
+ //# sourceMappingURL=plugin.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.cjs.js","sources":["esm/definitions.js","esm/index.js","esm/web.js"],"sourcesContent":["/**\n * @since 0.1.0\n */\nexport var ErrorCode;\n(function (ErrorCode) {\n /**\n * The audio session could not be activated or deactivated.\n *\n * @since 0.1.0\n */\n ErrorCode[\"ActivationFailed\"] = \"ACTIVATION_FAILED\";\n /**\n * The audio session could not be configured.\n *\n * @since 0.1.0\n */\n ErrorCode[\"ConfigurationFailed\"] = \"CONFIGURATION_FAILED\";\n})(ErrorCode || (ErrorCode = {}));\n//# sourceMappingURL=definitions.js.map","import { registerPlugin } from '@capacitor/core';\nconst AudioSession = registerPlugin('AudioSession', {\n web: () => import('./web').then(m => new m.AudioSessionWeb()),\n});\nexport * from './definitions';\nexport { AudioSession };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class AudioSessionWeb extends WebPlugin {\n async configure(_options) {\n throw this.unimplemented('Not implemented on web.');\n }\n async getCurrentOutputs() {\n throw this.unimplemented('Not implemented on web.');\n }\n async overrideOutput(_options) {\n throw this.unimplemented('Not implemented on web.');\n }\n async setActive(_options) {\n throw this.unimplemented('Not implemented on web.');\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["ErrorCode","registerPlugin","WebPlugin"],"mappings":";;;;AAAA;AACA;AACA;AACWA;AACX,CAAC,UAAU,SAAS,EAAE;AACtB;AACA;AACA;AACA;AACA;AACA,IAAI,SAAS,CAAC,kBAAkB,CAAC,GAAG,mBAAmB;AACvD;AACA;AACA;AACA;AACA;AACA,IAAI,SAAS,CAAC,qBAAqB,CAAC,GAAG,sBAAsB;AAC7D,CAAC,EAAEA,iBAAS,KAAKA,iBAAS,GAAG,EAAE,CAAC,CAAC;;AChB5B,MAAC,YAAY,GAAGC,mBAAc,CAAC,cAAc,EAAE;AACpD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,eAAe,EAAE,CAAC;AACjE,CAAC;;ACFM,MAAM,eAAe,SAASC,cAAS,CAAC;AAC/C,IAAI,MAAM,SAAS,CAAC,QAAQ,EAAE;AAC9B,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC;AAC3D,IAAI;AACJ,IAAI,MAAM,iBAAiB,GAAG;AAC9B,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC;AAC3D,IAAI;AACJ,IAAI,MAAM,cAAc,CAAC,QAAQ,EAAE;AACnC,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC;AAC3D,IAAI;AACJ,IAAI,MAAM,SAAS,CAAC,QAAQ,EAAE;AAC9B,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC;AAC3D,IAAI;AACJ;;;;;;;;;"}
package/dist/plugin.js ADDED
@@ -0,0 +1,52 @@
1
+ var capacitorAudioSession = (function (exports, core) {
2
+ 'use strict';
3
+
4
+ /**
5
+ * @since 0.1.0
6
+ */
7
+ exports.ErrorCode = void 0;
8
+ (function (ErrorCode) {
9
+ /**
10
+ * The audio session could not be activated or deactivated.
11
+ *
12
+ * @since 0.1.0
13
+ */
14
+ ErrorCode["ActivationFailed"] = "ACTIVATION_FAILED";
15
+ /**
16
+ * The audio session could not be configured.
17
+ *
18
+ * @since 0.1.0
19
+ */
20
+ ErrorCode["ConfigurationFailed"] = "CONFIGURATION_FAILED";
21
+ })(exports.ErrorCode || (exports.ErrorCode = {}));
22
+
23
+ const AudioSession = core.registerPlugin('AudioSession', {
24
+ web: () => Promise.resolve().then(function () { return web; }).then(m => new m.AudioSessionWeb()),
25
+ });
26
+
27
+ class AudioSessionWeb extends core.WebPlugin {
28
+ async configure(_options) {
29
+ throw this.unimplemented('Not implemented on web.');
30
+ }
31
+ async getCurrentOutputs() {
32
+ throw this.unimplemented('Not implemented on web.');
33
+ }
34
+ async overrideOutput(_options) {
35
+ throw this.unimplemented('Not implemented on web.');
36
+ }
37
+ async setActive(_options) {
38
+ throw this.unimplemented('Not implemented on web.');
39
+ }
40
+ }
41
+
42
+ var web = /*#__PURE__*/Object.freeze({
43
+ __proto__: null,
44
+ AudioSessionWeb: AudioSessionWeb
45
+ });
46
+
47
+ exports.AudioSession = AudioSession;
48
+
49
+ return exports;
50
+
51
+ })({}, capacitorExports);
52
+ //# sourceMappingURL=plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.js","sources":["esm/definitions.js","esm/index.js","esm/web.js"],"sourcesContent":["/**\n * @since 0.1.0\n */\nexport var ErrorCode;\n(function (ErrorCode) {\n /**\n * The audio session could not be activated or deactivated.\n *\n * @since 0.1.0\n */\n ErrorCode[\"ActivationFailed\"] = \"ACTIVATION_FAILED\";\n /**\n * The audio session could not be configured.\n *\n * @since 0.1.0\n */\n ErrorCode[\"ConfigurationFailed\"] = \"CONFIGURATION_FAILED\";\n})(ErrorCode || (ErrorCode = {}));\n//# sourceMappingURL=definitions.js.map","import { registerPlugin } from '@capacitor/core';\nconst AudioSession = registerPlugin('AudioSession', {\n web: () => import('./web').then(m => new m.AudioSessionWeb()),\n});\nexport * from './definitions';\nexport { AudioSession };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class AudioSessionWeb extends WebPlugin {\n async configure(_options) {\n throw this.unimplemented('Not implemented on web.');\n }\n async getCurrentOutputs() {\n throw this.unimplemented('Not implemented on web.');\n }\n async overrideOutput(_options) {\n throw this.unimplemented('Not implemented on web.');\n }\n async setActive(_options) {\n throw this.unimplemented('Not implemented on web.');\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["ErrorCode","registerPlugin","WebPlugin"],"mappings":";;;IAAA;IACA;IACA;AACWA;IACX,CAAC,UAAU,SAAS,EAAE;IACtB;IACA;IACA;IACA;IACA;IACA,IAAI,SAAS,CAAC,kBAAkB,CAAC,GAAG,mBAAmB;IACvD;IACA;IACA;IACA;IACA;IACA,IAAI,SAAS,CAAC,qBAAqB,CAAC,GAAG,sBAAsB;IAC7D,CAAC,EAAEA,iBAAS,KAAKA,iBAAS,GAAG,EAAE,CAAC,CAAC;;AChB5B,UAAC,YAAY,GAAGC,mBAAc,CAAC,cAAc,EAAE;IACpD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,eAAe,EAAE,CAAC;IACjE,CAAC;;ICFM,MAAM,eAAe,SAASC,cAAS,CAAC;IAC/C,IAAI,MAAM,SAAS,CAAC,QAAQ,EAAE;IAC9B,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC;IAC3D,IAAI;IACJ,IAAI,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC;IAC3D,IAAI;IACJ,IAAI,MAAM,cAAc,CAAC,QAAQ,EAAE;IACnC,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC;IAC3D,IAAI;IACJ,IAAI,MAAM,SAAS,CAAC,QAAQ,EAAE;IAC9B,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC;IAC3D,IAAI;IACJ;;;;;;;;;;;;;;;"}
@@ -0,0 +1,127 @@
1
+ import Foundation
2
+ import AVFoundation
3
+ import Capacitor
4
+
5
+ @objc public class AudioSession: NSObject {
6
+ private let plugin: AudioSessionPlugin
7
+
8
+ init(plugin: AudioSessionPlugin) {
9
+ self.plugin = plugin
10
+ super.init()
11
+ self.startObserving()
12
+ }
13
+
14
+ deinit {
15
+ stopObserving()
16
+ }
17
+
18
+ @objc public func configure(_ options: ConfigureOptions, completion: @escaping (Error?) -> Void) {
19
+ do {
20
+ try AVAudioSession.sharedInstance().setCategory(options.getCategory(), mode: options.getMode(), options: options.getCategoryOptions())
21
+ completion(nil)
22
+ } catch {
23
+ completion(CustomError.configurationFailed)
24
+ }
25
+ }
26
+
27
+ @objc public func getCurrentOutputs(completion: @escaping (GetCurrentOutputsResult?, Error?) -> Void) {
28
+ let outputs = mapOutputs(AVAudioSession.sharedInstance().currentRoute.outputs)
29
+ completion(GetCurrentOutputsResult(outputs: outputs), nil)
30
+ }
31
+
32
+ @objc public func overrideOutput(_ options: OverrideOutputOptions, completion: @escaping (Error?) -> Void) {
33
+ do {
34
+ try AVAudioSession.sharedInstance().overrideOutputAudioPort(options.getPortOverride())
35
+ completion(nil)
36
+ } catch {
37
+ completion(CustomError.configurationFailed)
38
+ }
39
+ }
40
+
41
+ @objc public func setActive(_ options: SetActiveOptions, completion: @escaping (Error?) -> Void) {
42
+ let sessionOptions: AVAudioSession.SetActiveOptions = options.getNotifyOthersOnDeactivation() ? .notifyOthersOnDeactivation : []
43
+ do {
44
+ try AVAudioSession.sharedInstance().setActive(options.getActive(), options: sessionOptions)
45
+ completion(nil)
46
+ } catch {
47
+ completion(CustomError.activationFailed)
48
+ }
49
+ }
50
+
51
+ @objc private func handleInterruptionNotification(_ notification: Notification) {
52
+ guard let userInfo = notification.userInfo,
53
+ let typeValue = userInfo[AVAudioSessionInterruptionTypeKey] as? UInt,
54
+ let type = AVAudioSession.InterruptionType(rawValue: typeValue) else {
55
+ return
56
+ }
57
+ switch type {
58
+ case .began:
59
+ plugin.notifyInterruptionListeners(InterruptionEvent(type: "began", shouldResume: false))
60
+ case .ended:
61
+ var shouldResume = false
62
+ if let optionsValue = userInfo[AVAudioSessionInterruptionOptionKey] as? UInt {
63
+ let interruptionOptions = AVAudioSession.InterruptionOptions(rawValue: optionsValue)
64
+ shouldResume = interruptionOptions.contains(.shouldResume)
65
+ }
66
+ plugin.notifyInterruptionListeners(InterruptionEvent(type: "ended", shouldResume: shouldResume))
67
+ @unknown default:
68
+ break
69
+ }
70
+ }
71
+
72
+ @objc private func handleRouteChangeNotification(_ notification: Notification) {
73
+ var reason: AVAudioSession.RouteChangeReason = .unknown
74
+ if let userInfo = notification.userInfo,
75
+ let reasonValue = userInfo[AVAudioSessionRouteChangeReasonKey] as? UInt,
76
+ let parsedReason = AVAudioSession.RouteChangeReason(rawValue: reasonValue) {
77
+ reason = parsedReason
78
+ }
79
+ let outputs = mapOutputs(AVAudioSession.sharedInstance().currentRoute.outputs)
80
+ plugin.notifyRouteChangeListeners(RouteChangeEvent(reason: mapRouteChangeReason(reason), outputs: outputs))
81
+ }
82
+
83
+ private func mapOutputs(_ ports: [AVAudioSessionPortDescription]) -> [AudioSessionOutput] {
84
+ return ports.map { AudioSessionOutput(portType: $0.portType.rawValue, portName: $0.portName) }
85
+ }
86
+
87
+ private func mapRouteChangeReason(_ reason: AVAudioSession.RouteChangeReason) -> String {
88
+ switch reason {
89
+ case .categoryChange:
90
+ return "categoryChange"
91
+ case .newDeviceAvailable:
92
+ return "newDeviceAvailable"
93
+ case .noSuitableRouteForCategory:
94
+ return "noSuitableRouteForCategory"
95
+ case .oldDeviceUnavailable:
96
+ return "oldDeviceUnavailable"
97
+ case .override:
98
+ return "override"
99
+ case .routeConfigurationChange:
100
+ return "routeConfigurationChange"
101
+ case .unknown:
102
+ return "unknown"
103
+ @unknown default:
104
+ return "unknown"
105
+ }
106
+ }
107
+
108
+ private func startObserving() {
109
+ let notificationCenter = NotificationCenter.default
110
+ notificationCenter.addObserver(
111
+ self,
112
+ selector: #selector(handleInterruptionNotification),
113
+ name: AVAudioSession.interruptionNotification,
114
+ object: nil)
115
+ notificationCenter.addObserver(
116
+ self,
117
+ selector: #selector(handleRouteChangeNotification),
118
+ name: AVAudioSession.routeChangeNotification,
119
+ object: nil)
120
+ }
121
+
122
+ private func stopObserving() {
123
+ let notificationCenter = NotificationCenter.default
124
+ notificationCenter.removeObserver(self, name: AVAudioSession.interruptionNotification, object: nil)
125
+ notificationCenter.removeObserver(self, name: AVAudioSession.routeChangeNotification, object: nil)
126
+ }
127
+ }