@superinterface/react 5.3.0-beta.15 → 5.3.0-beta.17
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.cjs +122 -74
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +122 -74
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -47568,6 +47568,18 @@ var useMessageAudio = function(_ref) {
|
|
|
47568
47568
|
var superinterfaceContext = useSuperinterfaceContext();
|
|
47569
47569
|
var _$_ref1 = _sliced_to_array((0, import_react67.useState)(false), 2), isPlaying = _$_ref1[0], setIsPlaying = _$_ref1[1];
|
|
47570
47570
|
var _$_ref2 = _sliced_to_array((0, import_react67.useState)([]), 2), audioQueue = _$_ref2[0], setAudioQueue = _$_ref2[1];
|
|
47571
|
+
var commitAudioQueue = (0, import_react67.useCallback)(function(next) {
|
|
47572
|
+
if (typeof next === "function") {
|
|
47573
|
+
setAudioQueue(function(prev) {
|
|
47574
|
+
var computed = next(prev);
|
|
47575
|
+
audioQueueRef.current = computed;
|
|
47576
|
+
return computed;
|
|
47577
|
+
});
|
|
47578
|
+
} else {
|
|
47579
|
+
audioQueueRef.current = next;
|
|
47580
|
+
setAudioQueue(next);
|
|
47581
|
+
}
|
|
47582
|
+
}, []);
|
|
47571
47583
|
var audioQueueRef = (0, import_react67.useRef)([]);
|
|
47572
47584
|
(0, import_react67.useEffect)(function() {
|
|
47573
47585
|
audioQueueRef.current = audioQueue;
|
|
@@ -47592,7 +47604,7 @@ var useMessageAudio = function(_ref) {
|
|
|
47592
47604
|
var checkForCompletion = (0, import_react67.useCallback)(function() {
|
|
47593
47605
|
if (activeSegmentsRef.current > 0) return;
|
|
47594
47606
|
var hasPending = audioQueueRef.current.some(function(m) {
|
|
47595
|
-
return !m.stopped &&
|
|
47607
|
+
return !m.stopped && m.nextIndex < m.segments.length;
|
|
47596
47608
|
});
|
|
47597
47609
|
if (hasPending) {
|
|
47598
47610
|
onEndPendingRef.current = true;
|
|
@@ -47744,16 +47756,16 @@ var useMessageAudio = function(_ref) {
|
|
|
47744
47756
|
];
|
|
47745
47757
|
case 6:
|
|
47746
47758
|
unfinished = nextQueue.filter(function(m_7) {
|
|
47747
|
-
return !m_7.stopped &&
|
|
47759
|
+
return !m_7.stopped && m_7.nextIndex < m_7.segments.length;
|
|
47748
47760
|
});
|
|
47749
47761
|
finished = nextQueue.filter(function(m_8) {
|
|
47750
|
-
return !(!m_8.stopped &&
|
|
47762
|
+
return !(!m_8.stopped && m_8.nextIndex < m_8.segments.length);
|
|
47751
47763
|
});
|
|
47752
47764
|
prunedFinished = finished.length > KEEP_FINISHED_MESSAGES ? finished.slice(finished.length - KEEP_FINISHED_MESSAGES) : finished;
|
|
47753
47765
|
combined = _to_consumable_array(unfinished).concat(_to_consumable_array(prunedFinished));
|
|
47754
47766
|
if (combined.some(function(m_9) {
|
|
47755
|
-
return !m_9.stopped &&
|
|
47756
|
-
})) {
|
|
47767
|
+
return !m_9.stopped && m_9.nextIndex < m_9.segments.length;
|
|
47768
|
+
}) || activeSegmentsRef.current > 0) {
|
|
47757
47769
|
onEndPendingRef.current = true;
|
|
47758
47770
|
}
|
|
47759
47771
|
if (!changed) {
|
|
@@ -47811,7 +47823,7 @@ var useMessageAudio = function(_ref) {
|
|
|
47811
47823
|
}
|
|
47812
47824
|
}
|
|
47813
47825
|
}
|
|
47814
|
-
if (changed)
|
|
47826
|
+
if (changed) commitAudioQueue(combined);
|
|
47815
47827
|
if (segCache.size > MAX_SEG_CACHE) {
|
|
47816
47828
|
entries = Array.from(segCache.entries());
|
|
47817
47829
|
entries.sort(function(a, b) {
|
|
@@ -48090,8 +48102,8 @@ var useMessageAudio = function(_ref) {
|
|
|
48090
48102
|
defaultPlaySegments
|
|
48091
48103
|
]);
|
|
48092
48104
|
var handleStop = (0, import_react67.useCallback)(function(messageId) {
|
|
48093
|
-
|
|
48094
|
-
return
|
|
48105
|
+
commitAudioQueue(function(prev_0) {
|
|
48106
|
+
return prev_0.map(function(m_13) {
|
|
48095
48107
|
return m_13.id === messageId ? _objectSpread47(_objectSpread47({}, m_13), {}, {
|
|
48096
48108
|
stopped: true
|
|
48097
48109
|
}) : m_13;
|
|
@@ -48110,7 +48122,6 @@ var useMessageAudio = function(_ref) {
|
|
|
48110
48122
|
if (activeSegmentsRef.current === 0) {
|
|
48111
48123
|
setIsPlaying(false);
|
|
48112
48124
|
currentSegmentRef.current = null;
|
|
48113
|
-
pickLockRef.current = false;
|
|
48114
48125
|
checkForCompletion();
|
|
48115
48126
|
}
|
|
48116
48127
|
}, [
|
|
@@ -48118,10 +48129,9 @@ var useMessageAudio = function(_ref) {
|
|
|
48118
48129
|
]);
|
|
48119
48130
|
(0, import_react67.useEffect)(function() {
|
|
48120
48131
|
var allowParallel = Boolean(providedPlaySegments);
|
|
48121
|
-
if (!allowParallel && isPlaying) return;
|
|
48132
|
+
if (!allowParallel && (isPlaying || audioPlayer.playing)) return;
|
|
48122
48133
|
if (pickLockRef.current) return;
|
|
48123
48134
|
if (audioQueue.length === 0) return;
|
|
48124
|
-
if (!allowParallel && audioPlayer.playing) return;
|
|
48125
48135
|
var candidate = null;
|
|
48126
48136
|
for(var i_3 = 0; i_3 < audioQueue.length; i_3++){
|
|
48127
48137
|
var msg = audioQueue[i_3];
|
|
@@ -48140,73 +48150,111 @@ var useMessageAudio = function(_ref) {
|
|
|
48140
48150
|
}
|
|
48141
48151
|
if (!candidate || candidate.segments.length === 0) return;
|
|
48142
48152
|
pickLockRef.current = true;
|
|
48143
|
-
setIsPlaying(true);
|
|
48144
|
-
|
|
48145
|
-
|
|
48146
|
-
|
|
48147
|
-
|
|
48153
|
+
if (!allowParallel) setIsPlaying(true);
|
|
48154
|
+
var selected = candidate;
|
|
48155
|
+
commitAudioQueue(function(prev_1) {
|
|
48156
|
+
return prev_1.map(function(m_14) {
|
|
48157
|
+
return m_14.id === selected.messageId ? _objectSpread47(_objectSpread47({}, m_14), {}, {
|
|
48158
|
+
nextIndex: selected.startIndex
|
|
48148
48159
|
}) : m_14;
|
|
48149
48160
|
});
|
|
48150
48161
|
});
|
|
48151
|
-
var runPlayback = function() {
|
|
48152
|
-
var
|
|
48153
|
-
|
|
48154
|
-
return
|
|
48155
|
-
|
|
48156
|
-
|
|
48157
|
-
|
|
48158
|
-
|
|
48159
|
-
|
|
48160
|
-
|
|
48161
|
-
|
|
48162
|
-
|
|
48163
|
-
|
|
48164
|
-
|
|
48165
|
-
|
|
48166
|
-
|
|
48167
|
-
|
|
48168
|
-
|
|
48169
|
-
|
|
48170
|
-
|
|
48171
|
-
|
|
48172
|
-
|
|
48173
|
-
|
|
48174
|
-
|
|
48175
|
-
|
|
48176
|
-
|
|
48177
|
-
|
|
48162
|
+
var runPlayback = /* @__PURE__ */ function() {
|
|
48163
|
+
var _ref0 = _asyncToGenerator11(function() {
|
|
48164
|
+
var launchedCount;
|
|
48165
|
+
return _ts_generator(this, function(_state) {
|
|
48166
|
+
switch(_state.label){
|
|
48167
|
+
case 0:
|
|
48168
|
+
launchedCount = 0;
|
|
48169
|
+
return [
|
|
48170
|
+
4,
|
|
48171
|
+
playSegmentsImpl({
|
|
48172
|
+
segments: selected.segments,
|
|
48173
|
+
startIndex: selected.startIndex,
|
|
48174
|
+
message: selected.message,
|
|
48175
|
+
play: function() {
|
|
48176
|
+
var _play = _asyncToGenerator11(function(segment_0) {
|
|
48177
|
+
var advanceTo;
|
|
48178
|
+
return _ts_generator(this, function(_state) {
|
|
48179
|
+
switch(_state.label){
|
|
48180
|
+
case 0:
|
|
48181
|
+
activeSegmentsRef.current += 1;
|
|
48182
|
+
launchedCount += 1;
|
|
48183
|
+
advanceTo = selected.startIndex + launchedCount;
|
|
48184
|
+
onEndPendingRef.current = true;
|
|
48185
|
+
commitAudioQueue(function(prev_2) {
|
|
48186
|
+
return prev_2.map(function(m_15) {
|
|
48187
|
+
return m_15.id === selected.messageId ? _objectSpread47(_objectSpread47({}, m_15), {}, {
|
|
48188
|
+
nextIndex: m_15.nextIndex >= advanceTo ? m_15.nextIndex : advanceTo
|
|
48189
|
+
}) : m_15;
|
|
48190
|
+
});
|
|
48191
|
+
});
|
|
48192
|
+
currentSegmentRef.current = {
|
|
48193
|
+
messageId: selected.messageId,
|
|
48194
|
+
nextIndex: advanceTo
|
|
48195
|
+
};
|
|
48196
|
+
return [
|
|
48197
|
+
4,
|
|
48198
|
+
playInternal(segment_0, {
|
|
48199
|
+
onPlay: function() {},
|
|
48200
|
+
onStop: function() {
|
|
48201
|
+
return handleStop(selected.messageId);
|
|
48202
|
+
},
|
|
48203
|
+
onEnd: function() {
|
|
48204
|
+
commitAudioQueue(function(prev_3) {
|
|
48205
|
+
return prev_3.map(function(m_16) {
|
|
48206
|
+
return m_16.id === selected.messageId ? _objectSpread47(_objectSpread47({}, m_16), {}, {
|
|
48207
|
+
nextIndex: m_16.nextIndex >= advanceTo ? m_16.nextIndex : advanceTo
|
|
48208
|
+
}) : m_16;
|
|
48209
|
+
});
|
|
48210
|
+
});
|
|
48211
|
+
handleSegmentEnd();
|
|
48212
|
+
}
|
|
48213
|
+
})
|
|
48214
|
+
];
|
|
48215
|
+
case 1:
|
|
48216
|
+
_state.sent();
|
|
48217
|
+
return [
|
|
48218
|
+
2
|
|
48219
|
+
];
|
|
48178
48220
|
}
|
|
48179
|
-
})
|
|
48180
|
-
|
|
48181
|
-
|
|
48182
|
-
|
|
48183
|
-
|
|
48184
|
-
|
|
48185
|
-
|
|
48186
|
-
}
|
|
48187
|
-
|
|
48188
|
-
|
|
48189
|
-
|
|
48190
|
-
return
|
|
48191
|
-
|
|
48192
|
-
|
|
48193
|
-
}
|
|
48221
|
+
});
|
|
48222
|
+
});
|
|
48223
|
+
function play(_x6) {
|
|
48224
|
+
return _play.apply(this, arguments);
|
|
48225
|
+
}
|
|
48226
|
+
return play;
|
|
48227
|
+
}()
|
|
48228
|
+
})
|
|
48229
|
+
];
|
|
48230
|
+
case 1:
|
|
48231
|
+
_state.sent();
|
|
48232
|
+
return [
|
|
48233
|
+
2
|
|
48234
|
+
];
|
|
48235
|
+
}
|
|
48194
48236
|
});
|
|
48237
|
+
});
|
|
48238
|
+
return function runPlayback2() {
|
|
48239
|
+
return _ref0.apply(this, arguments);
|
|
48195
48240
|
};
|
|
48196
|
-
|
|
48197
|
-
|
|
48198
|
-
|
|
48199
|
-
|
|
48200
|
-
|
|
48201
|
-
|
|
48202
|
-
|
|
48203
|
-
|
|
48204
|
-
|
|
48205
|
-
|
|
48206
|
-
|
|
48207
|
-
|
|
48208
|
-
|
|
48209
|
-
|
|
48241
|
+
}();
|
|
48242
|
+
Promise.resolve(runPlayback()).catch(function(error) {
|
|
48243
|
+
handleStop(selected.messageId);
|
|
48244
|
+
console.error(error);
|
|
48245
|
+
}).finally(function() {
|
|
48246
|
+
var finalNextIndex = selected.startIndex + selected.segments.length;
|
|
48247
|
+
commitAudioQueue(audioQueueRef.current.map(function(m_17) {
|
|
48248
|
+
return m_17.id === selected.messageId ? _objectSpread47(_objectSpread47({}, m_17), {}, {
|
|
48249
|
+
nextIndex: m_17.nextIndex >= finalNextIndex ? m_17.nextIndex : finalNextIndex
|
|
48250
|
+
}) : m_17;
|
|
48251
|
+
}));
|
|
48252
|
+
pickLockRef.current = false;
|
|
48253
|
+
checkForCompletion();
|
|
48254
|
+
});
|
|
48255
|
+
if (allowParallel) {
|
|
48256
|
+
pickLockRef.current = false;
|
|
48257
|
+
}
|
|
48210
48258
|
}, [
|
|
48211
48259
|
audioQueue,
|
|
48212
48260
|
isPlaying,
|
|
@@ -48264,8 +48312,8 @@ var useMessageAudio = function(_ref) {
|
|
|
48264
48312
|
audioEngine
|
|
48265
48313
|
]);
|
|
48266
48314
|
var isPending = (0, import_react67.useMemo)(function() {
|
|
48267
|
-
return isPlaying || audioQueue.some(function(
|
|
48268
|
-
return !
|
|
48315
|
+
return isPlaying || audioQueue.some(function(m_18) {
|
|
48316
|
+
return !m_18.stopped && (m_18.nextIndex < m_18.segments.length || m_18.status === "in_progress");
|
|
48269
48317
|
});
|
|
48270
48318
|
}, [
|
|
48271
48319
|
isPlaying,
|