Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix android crash in develop v2.27.5 #753

Merged
merged 2 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -878,9 +878,8 @@ public void onStreamCreated(PublisherKit publisherKit, Stream stream) {
ConcurrentHashMap<String, Stream> mSubscriberStreams = sharedState.getSubscriberStreams();
mSubscriberStreams.put(stream.getStreamId(), stream);
if (publisherId.length() > 0) {
String event = publisherId + ":" + publisherPreface + "onStreamCreated";
WritableMap streamInfo = EventUtils.prepareJSStreamMap(stream, publisherKit.getSession());
sendEventMap(this.getReactApplicationContext(), event, streamInfo);
streamInfo.putString("publisherId", publisherId);
sendEventMap(this.getReactApplicationContext(), "publisherStreamCreated", streamInfo);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

React Native on Android does now appear to like the sequential calls to emit events over the bridge, so now both the OTSubscriber and OTPublisher JS components will receive the one event. The OTPublisher will filter events based on the publisherId in the event data (not in the event name).

}
printLogs("onStreamCreated: Publisher Stream Created. Own stream "+stream.getStreamId());
Expand All @@ -891,13 +890,12 @@ public void onStreamCreated(PublisherKit publisherKit, Stream stream) {
public void onStreamDestroyed(PublisherKit publisherKit, Stream stream) {

String publisherId = Utils.getPublisherId(publisherKit);
String event = publisherId + ":" + publisherPreface + "onStreamDestroyed";
ConcurrentHashMap<String, Stream> mSubscriberStreams = sharedState.getSubscriberStreams();
String mStreamId = stream.getStreamId();
mSubscriberStreams.remove(mStreamId);
if (publisherId.length() > 0) {
WritableMap streamInfo = EventUtils.prepareJSStreamMap(stream, publisherKit.getSession());
sendEventMap(this.getReactApplicationContext(), event, streamInfo);
streamInfo.putString("publisherId", publisherId);
sendEventMap(this.getReactApplicationContext(), "publisherStreamDestroyed", streamInfo);
}
Callback mCallback = sharedState.getPublisherDestroyedCallbacks().get(publisherId);
Expand Down
4 changes: 2 additions & 2 deletions ios/OpenTokReactNative/OTSessionManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ extension OTSessionManager: OTPublisherDelegate {
if (publisherId.count > 0) {
OTRN.sharedState.isPublishing[publisherId] = true;
let streamInfo: Dictionary<String, Any> = EventUtils.prepareJSStreamEventData(stream);
self.emitEvent("\(publisherId):\(EventUtils.publisherPreface)streamCreated", data: streamInfo);
streamInfo["publisherId"] = publisherId;
self.emitEvent("publisherStreamCreated", data: streamInfo);
setStreamObservers(stream: stream, isPublisherStream: true)
}
Expand All @@ -668,7 +668,7 @@ extension OTSessionManager: OTPublisherDelegate {
if (publisherId.count > 0) {
OTRN.sharedState.isPublishing[publisherId] = false;
let streamInfo: Dictionary<String, Any> = EventUtils.prepareJSStreamEventData(stream);
self.emitEvent("\(publisherId):\(EventUtils.publisherPreface)streamDestroyed", data: streamInfo);
streamInfo["publisherId"] = publisherId;
self.emitEvent("publisherStreamDestroyed", data: streamInfo);
}
OTRN.sharedState.publishers[publisherId] = nil;
Expand Down
30 changes: 30 additions & 0 deletions src/OTPublisher.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ class OTPublisher extends Component {
}
initComponent = () => {
this.componentEvents = {
publisherStreamCreated: 'publisherStreamCreated',
publisherStreamDestroyed: 'publisherStreamDestroyed:',
sessionConnected:
Platform.OS === 'android'
? 'session:onConnected'
Expand All @@ -44,6 +46,14 @@ class OTPublisher extends Component {
);
setNativeEvents(this.publisherEvents);
OT.setJSComponentEvents(this.componentEventsArray);
this.publisherStreamCreated = nativeEvents.addListener(
'publisherStreamCreated',
stream => this.publisherStreamCreatedHandler(stream)
);
this.publisherStreamDestroyed = nativeEvents.addListener(
'publisherStreamDestroyed',
stream => this.publisherStreamDestroyedHandler(stream)
);
if (this.context.sessionId) {
this.sessionConnected = nativeEvents.addListener(
`${this.context.sessionId}:${this.componentEvents.sessionConnected}`,
Expand Down Expand Up @@ -159,6 +169,26 @@ class OTPublisher extends Component {
OT.getRtcStatsReport(this.state.publisherId);
}

publisherStreamCreatedHandler = (stream) => {
if (
this.props.eventHandlers
&& this.props.eventHandlers.streamCreated
&& stream.publisherId === this.state.publisherId
) {
this.props.eventHandlers.streamCreated(stream);
}
}

publisherStreamDestroyedHandler = (stream) => {
if (
this.props.eventHandlers
&& this.props.eventHandlers.streamCreated
&& stream.publisherId === this.state.publisherId
) {
this.props.eventHandlers.streamDestroyed(stream);
}
}

setVideoTransformers(videoTransformers) {
OT.setVideoTransformers(this.state.publisherId, videoTransformers);
}
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/OTPublisherHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ const sanitizePublisherEvents = (publisherId, events) => {
videoDisableWarningLifted: 'videoDisableWarningLifted',
},
android: {
streamCreated: 'onStreamCreated',
streamDestroyed: 'onStreamDestroyed',
streamCreated: 'streamCreated',
streamDestroyed: 'streamDestroyed',
error: 'onError',
audioLevel: 'onAudioLevelUpdated',
audioNetworkStats: 'onAudioStats',
Expand Down
4 changes: 0 additions & 4 deletions src/helpers/OTSessionHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ const sanitizeSessionEvents = (sessionId, events) => {
archiveStopped: 'archiveStoppedWithId',
streamPropertyChanged: 'streamPropertyChanged',
muteForced: 'muteForced',
publisherStreamCreated: 'publisherStreamCreated',
publisherStreamDestroyed: 'publisherStreamDestroyed',
},
android: {
streamCreated: 'onStreamReceived',
Expand All @@ -57,8 +55,6 @@ const sanitizeSessionEvents = (sessionId, events) => {
archiveStopped: 'onArchiveStopped',
streamPropertyChanged: 'onStreamPropertyChanged',
muteForced: 'onMuteForced',
publisherStreamCreated: 'publisherStreamCreated',
publisherStreamDestroyed: 'publisherStreamDestroyed',
}
};
return reassignEvents('session', customEvents, events, sessionId);
Expand Down