Skip to content

Commit 869e258

Browse files
author
Maciej Makowski
committed
feat: added state to payload of onended event
1 parent 93d6edd commit 869e258

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

packages/react-native-audio-api/common/cpp/audioapi/core/sources/AudioScheduledSourceNode.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,17 @@ void AudioScheduledSourceNode::updatePlaybackInfo(
144144
void AudioScheduledSourceNode::disable() {
145145
AudioNode::disable();
146146

147-
std::unordered_map<std::string, EventValue> body = {{"value", getStopTime()}};
147+
std::string state = "stopped";
148+
149+
// if it has not been stopped, it is ended
150+
if (stopTime_ < 0) {
151+
state = "ended";
152+
}
153+
154+
std::unordered_map<std::string, EventValue> body = {
155+
{"value", getStopTime()},
156+
{"state", state}
157+
};
148158

149159
context_->audioEventHandlerRegistry_->invokeHandlerWithEventBody(
150160
"ended", onEndedCallbackId_, body);

packages/react-native-audio-api/src/events/types.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ export interface EventTypeWithValue {
66
value: number;
77
}
88

9+
export interface EventTypeWithValueAndState {
10+
value: number;
11+
state: 'stopped' | 'ended';
12+
}
13+
914
interface OnInterruptionEventType {
1015
type: 'ended' | 'began';
1116
shouldResume: boolean;
@@ -40,7 +45,7 @@ export interface OnAudioReadyEventType {
4045
}
4146

4247
interface AudioAPIEvents {
43-
ended: EventTypeWithValue;
48+
ended: EventTypeWithValueAndState;
4449
audioReady: OnAudioReadyEventType;
4550
audioError: EventEmptyType; // to change
4651
systemStateChanged: EventEmptyType; // to change

0 commit comments

Comments
 (0)