Skip to content

Commit

Permalink
Merge pull request #753 from opentok/fix-android-crash-v2.27.5
Browse files Browse the repository at this point in the history
Fix android crash in develop v2.27.5
  • Loading branch information
marinaserranomontes authored Jun 19, 2024
2 parents ae06aa5 + d6c8b89 commit 91abf9d
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 12 deletions.
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);
}
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

0 comments on commit 91abf9d

Please sign in to comment.