Skip to content

Commit

Permalink
fix: fix issues when use rtc together (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
guoxianzhe authored May 29, 2024
1 parent a623e61 commit 34b3c4c
Show file tree
Hide file tree
Showing 8 changed files with 270 additions and 3 deletions.
4 changes: 4 additions & 0 deletions example/ios/AgoraRtmNgExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,8 @@
OTHER_LDFLAGS = (
"$(inherited)-Wl",
"-ld_classic",
"-Wl",
"-ld_classic",
"-Wl -ld_classic ",
);
REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
Expand Down Expand Up @@ -519,6 +521,8 @@
OTHER_LDFLAGS = (
"$(inherited)-Wl",
"-ld_classic",
"-Wl",
"-ld_classic",
"-Wl -ld_classic ",
);
REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
Expand Down
49 changes: 49 additions & 0 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,43 @@ PODS:
- AgoraRtm_iOS (= 2.1.7)
- RCT-Folly (= 2021.07.22.00)
- React-Core
- AgoraIrisRTC_iOS (4.3.1-build.1)
- AgoraIrisRTM_iOS (2.1.7-build.1)
- AgoraRtcEngine_iOS (4.3.1):
- AgoraRtcEngine_iOS/AIAEC (= 4.3.1)
- AgoraRtcEngine_iOS/AINS (= 4.3.1)
- AgoraRtcEngine_iOS/AudioBeauty (= 4.3.1)
- AgoraRtcEngine_iOS/ClearVision (= 4.3.1)
- AgoraRtcEngine_iOS/ContentInspect (= 4.3.1)
- AgoraRtcEngine_iOS/FaceCapture (= 4.3.1)
- AgoraRtcEngine_iOS/FaceDetection (= 4.3.1)
- AgoraRtcEngine_iOS/LipSync (= 4.3.1)
- AgoraRtcEngine_iOS/ReplayKit (= 4.3.1)
- AgoraRtcEngine_iOS/RtcBasic (= 4.3.1)
- AgoraRtcEngine_iOS/SpatialAudio (= 4.3.1)
- AgoraRtcEngine_iOS/VideoAv1CodecDec (= 4.3.1)
- AgoraRtcEngine_iOS/VideoAv1CodecEnc (= 4.3.1)
- AgoraRtcEngine_iOS/VideoCodecDec (= 4.3.1)
- AgoraRtcEngine_iOS/VideoCodecEnc (= 4.3.1)
- AgoraRtcEngine_iOS/VirtualBackground (= 4.3.1)
- AgoraRtcEngine_iOS/VQA (= 4.3.1)
- AgoraRtcEngine_iOS/AIAEC (4.3.1)
- AgoraRtcEngine_iOS/AINS (4.3.1)
- AgoraRtcEngine_iOS/AudioBeauty (4.3.1)
- AgoraRtcEngine_iOS/ClearVision (4.3.1)
- AgoraRtcEngine_iOS/ContentInspect (4.3.1)
- AgoraRtcEngine_iOS/FaceCapture (4.3.1)
- AgoraRtcEngine_iOS/FaceDetection (4.3.1)
- AgoraRtcEngine_iOS/LipSync (4.3.1)
- AgoraRtcEngine_iOS/ReplayKit (4.3.1)
- AgoraRtcEngine_iOS/RtcBasic (4.3.1)
- AgoraRtcEngine_iOS/SpatialAudio (4.3.1)
- AgoraRtcEngine_iOS/VideoAv1CodecDec (4.3.1)
- AgoraRtcEngine_iOS/VideoAv1CodecEnc (4.3.1)
- AgoraRtcEngine_iOS/VideoCodecDec (4.3.1)
- AgoraRtcEngine_iOS/VideoCodecEnc (4.3.1)
- AgoraRtcEngine_iOS/VirtualBackground (4.3.1)
- AgoraRtcEngine_iOS/VQA (4.3.1)
- AgoraRtm_iOS (2.1.7)
- boost (1.76.0)
- CocoaAsyncSocket (7.6.5)
Expand Down Expand Up @@ -382,6 +418,11 @@ PODS:
- React-jsinspector (0.72.5)
- React-logger (0.72.5):
- glog
- react-native-agora (4.3.1):
- AgoraIrisRTC_iOS (= 4.3.1-build.1)
- AgoraRtcEngine_iOS (= 4.3.1)
- RCT-Folly (= 2021.07.22.00)
- React-Core
- react-native-safe-area-context (4.7.4):
- React-Core
- react-native-slider (4.4.3):
Expand Down Expand Up @@ -562,6 +603,7 @@ DEPENDENCIES:
- React-jsiexecutor (from `../node_modules/react-native/ReactCommon/jsiexecutor`)
- React-jsinspector (from `../node_modules/react-native/ReactCommon/jsinspector`)
- React-logger (from `../node_modules/react-native/ReactCommon/logger`)
- react-native-agora (from `../node_modules/react-native-agora`)
- react-native-safe-area-context (from `../node_modules/react-native-safe-area-context`)
- "react-native-slider (from `../node_modules/@react-native-community/slider`)"
- React-NativeModulesApple (from `../node_modules/react-native/ReactCommon/react/nativemodule/core/platform/ios`)
Expand Down Expand Up @@ -591,7 +633,9 @@ DEPENDENCIES:

SPEC REPOS:
trunk:
- AgoraIrisRTC_iOS
- AgoraIrisRTM_iOS
- AgoraRtcEngine_iOS
- AgoraRtm_iOS
- CocoaAsyncSocket
- Flipper
Expand Down Expand Up @@ -654,6 +698,8 @@ EXTERNAL SOURCES:
:path: "../node_modules/react-native/ReactCommon/jsinspector"
React-logger:
:path: "../node_modules/react-native/ReactCommon/logger"
react-native-agora:
:path: "../node_modules/react-native-agora"
react-native-safe-area-context:
:path: "../node_modules/react-native-safe-area-context"
react-native-slider:
Expand Down Expand Up @@ -709,7 +755,9 @@ EXTERNAL SOURCES:

SPEC CHECKSUMS:
agora-react-native-rtm: db09801b83ccbde861b8261e00bc46a03f8f4136
AgoraIrisRTC_iOS: 7710d853202eca4900c2916aefc44abd5a139d4e
AgoraIrisRTM_iOS: 588c042feef52bb2545e3618da1e442f19e2cf5b
AgoraRtcEngine_iOS: f64be00fdda786bb7edd84ab461c31b7b4c93534
AgoraRtm_iOS: cd26cf8a377a79934864d37e184866dbd1430eaf
boost: 57d2868c099736d80fcd648bf211b4431e51a558
CocoaAsyncSocket: 065fd1e645c7abab64f7a6a2007a48038fdc6a99
Expand Down Expand Up @@ -744,6 +792,7 @@ SPEC CHECKSUMS:
React-jsiexecutor: ff70a72027dea5cc7d71cfcc6fad7f599f63987a
React-jsinspector: aef73cbd43b70675f572214d10fa438c89bf11ba
React-logger: 2e4aee3e11b3ec4fa6cfd8004610bbb3b8d6cca4
react-native-agora: 5aaaa7e0353ca90f53fdeb30f3ba17a6c2fd3db1
react-native-safe-area-context: 2cd91d532de12acdb0a9cbc8d43ac72a8e4c897c
react-native-slider: 1cdd6ba29675df21f30544253bf7351d3c2d68c4
React-NativeModulesApple: 797bc6078d566eef3fb3f74127e6e1d2e945a15f
Expand Down
1 change: 1 addition & 0 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"events": "^3.0.0",
"react": "18.2.0",
"react-native": "0.72.5",
"react-native-agora": "^4.3.1",
"react-native-chart-kit": "^6.12.0",
"react-native-color-picker": "^0.6.0",
"react-native-fs": "^2.20.0",
Expand Down
168 changes: 168 additions & 0 deletions example/src/advanced/UseRTC/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
import {
RTM_CONNECTION_CHANGE_REASON,
RTM_CONNECTION_STATE,
RTM_ERROR_CODE,
RtmConfig,
RtmEncryptionConfig,
RtmProxyConfig,
} from 'agora-react-native-rtm';

import React, { useCallback, useEffect, useState } from 'react';

import { KeyboardAvoidingView, Platform, ScrollView } from 'react-native';
import { ChannelProfileType, createAgoraRtcEngine } from 'react-native-agora';

import {
AgoraButton,
AgoraStyle,
AgoraText,
AgoraTextInput,
} from '../../components/ui';
import Config from '../../config/agora.config';
import { useRtmClient } from '../../hooks/useRtmClient';
import * as log from '../../utils/log';

export default function UseRTC() {
const [uid, setUid] = useState(Config.uid);
const [rtcVersion, setRtcVersion] = useState(Config.uid);
const [loginSuccess, setLoginSuccess] = useState(false);
const [initResult, setInitResult] = useState<number>(0);
const onLoginResult = useCallback((errorCode: RTM_ERROR_CODE) => {
log.log('onLoginResult', 'errorCode', errorCode);
setLoginSuccess(errorCode === RTM_ERROR_CODE.RTM_ERROR_OK);
}, []);

const onConnectionStateChanged = useCallback(
(
channelName: string,
state: RTM_CONNECTION_STATE,
reason: RTM_CONNECTION_CHANGE_REASON
) => {
log.log(
'onConnectionStateChanged',
'channelName',
channelName,
'state',
state,
'reason',
reason
);
},
[]
);

/**
* Step 1: getRtmClient
*/
const client = useRtmClient();

/**
* Step 2: initialize rtm client
*/
useEffect(() => {
if (!uid || uid.length === 0) {
return;
}
let result = client.initialize(
new RtmConfig({
userId: uid,
appId: Config.appId,
areaCode: Config.areaCode,
proxyConfig: new RtmProxyConfig({
proxyType: Config.proxyType,
server: Config.server,
port: Config.port,
account: Config.account,
password: Config.password,
}),
encryptionConfig: new RtmEncryptionConfig({
encryptionMode: Config.encryptionMode,
encryptionKey: Config.encryptionKey,
encryptionSalt: Config.encryptionSalt,
}),
eventHandler: {
onLoginResult: () => {
console.log('onLoginResult');
},
},
})
);
setInitResult(result);
return () => {
setLoginSuccess(false);
client.release();
};
}, [client, uid]);

/**
* Step 3: login to rtm
*/
const login = () => {
client.login(Config.token);
};

/**
* Step 4 (Optional): logout
*/
const logout = () => {
client.logout();
setLoginSuccess(false);
};

useEffect(() => {
client?.addEventListener('onLoginResult', onLoginResult);
client?.addEventListener(
'onConnectionStateChanged',
onConnectionStateChanged
);
return () => {
client?.removeEventListener('onLoginResult', onLoginResult);
client?.removeEventListener(
'onConnectionStateChanged',
onConnectionStateChanged
);
};
}, [client, uid, onLoginResult, onConnectionStateChanged]);

useEffect(() => {
let engine = createAgoraRtcEngine();
engine.initialize({
appId: Config.appId,
channelProfile: ChannelProfileType.ChannelProfileLiveBroadcasting,
});
setRtcVersion(engine.getVersion());
return () => {
engine.release();
};
}, []);

return (
<KeyboardAvoidingView
style={AgoraStyle.fullSize}
behavior={Platform.OS === 'ios' ? 'padding' : 'height'}
>
<ScrollView style={AgoraStyle.fullSize}>
<AgoraText>{`RTC version:${rtcVersion.version},build: ${rtcVersion.build}`}</AgoraText>
{loginSuccess ? (
<AgoraText>{`current login userId:\n${uid}`}</AgoraText>
) : (
<AgoraTextInput
onChangeText={(text) => {
setUid(text);
}}
placeholder="please input userId"
label="userId"
value={uid}
/>
)}
<AgoraButton
disabled={!uid || initResult !== 0}
title={`${loginSuccess ? 'logout' : 'login'}`}
onPress={() => {
loginSuccess ? logout() : login();
}}
/>
</ScrollView>
</KeyboardAvoidingView>
);
}
5 changes: 5 additions & 0 deletions example/src/advanced/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Presence from './Presence';
import StreamChannelChannelMetadata from './StreamChannelChannelMetadata';
import StreamChannelLock from './StreamChannelLock';
import StreamChannelUserMetadata from './StreamChannelUserMetadata';
import UseRTC from './UseRTC';
import UserMetadata from './UserMetadata';
import PublishMessage from './publishMessage';
import PublishTopicMessage from './publishTopicMessage';
Expand Down Expand Up @@ -47,6 +48,10 @@ const Advanced = {
name: 'StreamChannelLock',
component: StreamChannelLock,
},
{
name: 'UseRTC',
component: UseRTC,
},
],
};
export default Advanced;
6 changes: 4 additions & 2 deletions ios/AgoraRtmNg.mm
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ @interface AgoraRtmNg ()

namespace agora {
namespace iris {
namespace rtm {
class EventHandler : public IrisEventHandler {
public:
EventHandler(void *plugin) { plugin_ = (__bridge AgoraRtmNg *)plugin; }
Expand Down Expand Up @@ -52,12 +53,13 @@ void OnEvent(EventParam *param) override {
private:
AgoraRtmNg *plugin_;
};
} // namespace rtm
} // namespace iris
} // namespace agora

@interface AgoraRtmNg ()

@property(nonatomic) agora::iris::EventHandler *eventHandler;
@property(nonatomic) agora::iris::rtm::EventHandler *eventHandler;

@end

Expand All @@ -73,7 +75,7 @@ + (instancetype)shareInstance {
- (instancetype)init {
if (self = [super init]) {
self.irisRtmEngine = nullptr;
self.eventHandler = new agora::iris::EventHandler((__bridge void *)self);
self.eventHandler = new agora::iris::rtm::EventHandler((__bridge void *)self);
instance = self;
}
return instance;
Expand Down
1 change: 0 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export * from './AgoraRtmBase';
export * from './IAgoraRtmClient';
export * from './IAgoraRtmLock';
export * from './IAgoraRtmPresence';
export * from './IAgoraRtmService';
export * from './IAgoraRtmStorage';
export * from './IAgoraStreamChannel';
export {
Expand Down
Loading

0 comments on commit 34b3c4c

Please sign in to comment.