Skip to content

Commit 9e89ce3

Browse files
authored
Adjust the audio session strategy for the AudioNavigator (#357)
1 parent 73e3e35 commit 9e89ce3

File tree

4 files changed

+44
-16
lines changed

4 files changed

+44
-16
lines changed

Sources/Navigator/Audiobook/AudioNavigator.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,8 @@ open class _AudioNavigator: _MediaNavigator, AudioSessionUser, Loggable {
3131
playbackRefreshInterval: TimeInterval = 0.5,
3232
audioSession: AudioSession.Configuration = .init(
3333
category: .playback,
34-
mode: .default,
35-
routeSharingPolicy: .longForm,
36-
options: []
34+
mode: .spokenAudio,
35+
routeSharingPolicy: .longFormAudio
3736
)
3837
) {
3938
self.playbackRefreshInterval = playbackRefreshInterval

Sources/Navigator/EPUB/Assets/Static/scripts/readium-fixed.js

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8731,18 +8731,23 @@ const attributeBlacklistMatch = (0,_utilities_data_js__WEBPACK_IMPORTED_MODULE_1
87318731
// Angular attributes
87328732
"ng-*",
87338733
]);
8734+
/**
8735+
* Prevents errors when attribute name contains a colon (e.g. "xlink:href").
8736+
*/
8737+
function sanitizeAttributeName(name) {
8738+
return name.replace(/:/g, "\\:");
8739+
}
87348740
/**
87358741
* Get simplified attribute selector for an element.
87368742
*/
8737-
function attributeNodeToSimplifiedSelector({ nodeName, }) {
8738-
return `[${nodeName}]`;
8743+
function attributeNodeToSimplifiedSelector({ name, }) {
8744+
return `[${name}]`;
87398745
}
87408746
/**
87418747
* Get attribute selector for an element.
87428748
*/
8743-
function attributeNodeToSelector({ nodeName, nodeValue, }) {
8744-
const selector = `[${nodeName}='${(0,_utilities_selectors_js__WEBPACK_IMPORTED_MODULE_0__.sanitizeSelectorItem)(nodeValue)}']`;
8745-
return selector;
8749+
function attributeNodeToSelector({ name, value, }) {
8750+
return `[${name}='${value}']`;
87468751
}
87478752
/**
87488753
* Checks whether attribute should be used as a selector.
@@ -8755,11 +8760,20 @@ function isValidAttributeNode({ nodeName }, element) {
87558760
}
87568761
return !attributeBlacklistMatch(nodeName);
87578762
}
8763+
/**
8764+
* Sanitize all attribute data. We want to do it once, before we start to generate simplified/full selectors from the same data.
8765+
*/
8766+
function sanitizeAttributeData({ nodeName, nodeValue }) {
8767+
return {
8768+
name: sanitizeAttributeName(nodeName),
8769+
value: (0,_utilities_selectors_js__WEBPACK_IMPORTED_MODULE_0__.sanitizeSelectorItem)(nodeValue),
8770+
};
8771+
}
87588772
/**
87598773
* Get attribute selectors for an element.
87608774
*/
87618775
function getElementAttributeSelectors(element) {
8762-
const validAttributes = Array.from(element.attributes).filter((attributeNode) => isValidAttributeNode(attributeNode, element));
8776+
const validAttributes = Array.from(element.attributes).filter((attributeNode) => isValidAttributeNode(attributeNode, element)).map(sanitizeAttributeData);
87638777
return [
87648778
...validAttributes.map(attributeNodeToSimplifiedSelector),
87658779
...validAttributes.map(attributeNodeToSelector),

Sources/Navigator/EPUB/Assets/Static/scripts/readium-reflowable.js

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8731,18 +8731,23 @@ const attributeBlacklistMatch = (0,_utilities_data_js__WEBPACK_IMPORTED_MODULE_1
87318731
// Angular attributes
87328732
"ng-*",
87338733
]);
8734+
/**
8735+
* Prevents errors when attribute name contains a colon (e.g. "xlink:href").
8736+
*/
8737+
function sanitizeAttributeName(name) {
8738+
return name.replace(/:/g, "\\:");
8739+
}
87348740
/**
87358741
* Get simplified attribute selector for an element.
87368742
*/
8737-
function attributeNodeToSimplifiedSelector({ nodeName, }) {
8738-
return `[${nodeName}]`;
8743+
function attributeNodeToSimplifiedSelector({ name, }) {
8744+
return `[${name}]`;
87398745
}
87408746
/**
87418747
* Get attribute selector for an element.
87428748
*/
8743-
function attributeNodeToSelector({ nodeName, nodeValue, }) {
8744-
const selector = `[${nodeName}='${(0,_utilities_selectors_js__WEBPACK_IMPORTED_MODULE_0__.sanitizeSelectorItem)(nodeValue)}']`;
8745-
return selector;
8749+
function attributeNodeToSelector({ name, value, }) {
8750+
return `[${name}='${value}']`;
87468751
}
87478752
/**
87488753
* Checks whether attribute should be used as a selector.
@@ -8755,11 +8760,20 @@ function isValidAttributeNode({ nodeName }, element) {
87558760
}
87568761
return !attributeBlacklistMatch(nodeName);
87578762
}
8763+
/**
8764+
* Sanitize all attribute data. We want to do it once, before we start to generate simplified/full selectors from the same data.
8765+
*/
8766+
function sanitizeAttributeData({ nodeName, nodeValue }) {
8767+
return {
8768+
name: sanitizeAttributeName(nodeName),
8769+
value: (0,_utilities_selectors_js__WEBPACK_IMPORTED_MODULE_0__.sanitizeSelectorItem)(nodeValue),
8770+
};
8771+
}
87588772
/**
87598773
* Get attribute selectors for an element.
87608774
*/
87618775
function getElementAttributeSelectors(element) {
8762-
const validAttributes = Array.from(element.attributes).filter((attributeNode) => isValidAttributeNode(attributeNode, element));
8776+
const validAttributes = Array.from(element.attributes).filter((attributeNode) => isValidAttributeNode(attributeNode, element)).map(sanitizeAttributeData);
87638777
return [
87648778
...validAttributes.map(attributeNodeToSimplifiedSelector),
87658779
...validAttributes.map(attributeNodeToSelector),

Sources/Navigator/TTS/PublicationSpeechSynthesizer.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@ public class PublicationSpeechSynthesizer: Loggable {
122122
config: Configuration = Configuration(),
123123
audioSessionConfig: AudioSession.Configuration = .init(
124124
category: .playback,
125-
mode: .spokenAudio
125+
mode: .spokenAudio,
126+
routeSharingPolicy: .longFormAudio
126127
),
127128
engineFactory: @escaping EngineFactory = { AVTTSEngine() },
128129
tokenizerFactory: @escaping TokenizerFactory = defaultTokenizerFactory,

0 commit comments

Comments
 (0)