Skip to content

Commit

Permalink
feat(example): Presence (#2)
Browse files Browse the repository at this point in the history
* feat(example): Presence
  • Loading branch information
guoxianzhe authored Nov 21, 2023
1 parent dc256f3 commit 0f347b3
Show file tree
Hide file tree
Showing 18 changed files with 386 additions and 160 deletions.
394 changes: 278 additions & 116 deletions example/src/advanced/Presence/index.tsx

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions example/src/advanced/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Presence from './Presence';
import PublishMessage from './publishMessage';
import PublishTopicMessage from './publishTopicMessage';

Expand All @@ -12,6 +13,10 @@ const Advanced = {
name: 'PublishTopicMessage',
component: PublishTopicMessage,
},
{
name: 'Presence',
component: Presence,
},
],
};
export default Advanced;
7 changes: 3 additions & 4 deletions example/src/basic/Login/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ import {
} from 'agora-react-native-rtm';
import React, { useCallback, useEffect, useState } from 'react';

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

import {
AgoraButton,
AgoraStyle,
AgoraText,
AgoraTextInput,
AgoraView,
} from '../../components/ui';
import Config from '../../config/agora.config';
import { useRtmClient } from '../../hooks/useRtmClient';
Expand Down Expand Up @@ -110,7 +109,7 @@ export default function Login() {
style={AgoraStyle.fullSize}
behavior={Platform.OS === 'ios' ? 'padding' : 'height'}
>
<AgoraView style={AgoraStyle.fullWidth}>
<ScrollView style={AgoraStyle.fullSize}>
{loginSuccess ? (
<AgoraText>{`current login userId:\n${uid}`}</AgoraText>
) : (
Expand All @@ -129,7 +128,7 @@ export default function Login() {
loginSuccess ? logout() : login();
}}
/>
</AgoraView>
</ScrollView>
</KeyboardAvoidingView>
);
}
6 changes: 3 additions & 3 deletions example/src/basic/createStreamChannel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from 'agora-react-native-rtm';
import React, { useCallback, useEffect, useState } from 'react';

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

import BaseComponent from '../../components/BaseComponent';
import { AgoraButton, AgoraStyle, AgoraView } from '../../components/ui';
Expand Down Expand Up @@ -178,7 +178,7 @@ export default function CreateStreamChannel() {
style={AgoraStyle.fullSize}
behavior={Platform.OS === 'ios' ? 'padding' : 'height'}
>
<AgoraView style={AgoraStyle.fullWidth}>
<ScrollView style={AgoraStyle.fullSize}>
<BaseComponent
onChannelNameChanged={(v) => setCName(v)}
onUidChanged={(v) => setUid(v)}
Expand Down Expand Up @@ -208,7 +208,7 @@ export default function CreateStreamChannel() {
}
}}
/>
</AgoraView>
</ScrollView>
</KeyboardAvoidingView>
);
}
12 changes: 7 additions & 5 deletions example/src/components/BaseComponent.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RTM_ERROR_CODE } from 'agora-react-native-rtm';
import { RTM_ERROR_CODE, RtmConfig } from 'agora-react-native-rtm';
import React, { useCallback, useEffect, useState } from 'react';

import Config from '../config/agora.config';
Expand Down Expand Up @@ -37,10 +37,12 @@ export default function BaseComponent({
if (!uid || uid.length === 0) {
return;
}
client.initialize({
userId: uid,
appId: Config.appId,
});
client.initialize(
new RtmConfig({
userId: uid,
appId: Config.appId,
})
);

return () => {
setLoginSuccess(false);
Expand Down
14 changes: 11 additions & 3 deletions example/src/components/ui/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export const AgoraButton = (props: ButtonProps) => {
export const AgoraDivider = (props: DividerProps) => {
return (
<>
<Divider width={1} color={'grey'} {...props} />
<Divider width={10} color={'transparent'} {...props} />
</>
);
};
Expand Down Expand Up @@ -197,7 +197,8 @@ export const AgoraCard = (
export interface AgoraDropdownItem extends Item {}

export const AgoraDropdown = (
props: PickerSelectProps & PickerProps & { title: string }
props: PickerSelectProps &
PickerProps & { title: string; titleStyle?: TextProps['style'] }
) => {
const [value, setValue] = useState(props.value);

Expand All @@ -207,7 +208,7 @@ export const AgoraDropdown = (

return (
<AgoraView style={AgoraStyle.fullWidth}>
<AgoraText children={props.title} />
<AgoraText style={props.titleStyle} children={props.title} />
<PickerSelect
{...props}
pickerProps={{
Expand Down Expand Up @@ -290,4 +291,11 @@ export const AgoraStyle = StyleSheet.create({
width: '100%',
height: 200,
},
dropdownTitle: {
fontWeight: 'bold',
fontSize: 16,
color: '#86939e',
paddingHorizontal: 10,
marginVertical: 10,
},
});
28 changes: 28 additions & 0 deletions scripts/terra/config/impl_special_return_list.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"agora::rtm::IRtmPresence.whoNow": "requestId",
"agora::rtm::IRtmPresence.whereNow": "requestId",
"agora::rtm::IRtmPresence.setState": "requestId",
"agora::rtm::IRtmPresence.removeState": "requestId",
"agora::rtm::IRtmPresence.getState": "requestId",
"agora::rtm::IRtmLock.setLock": "requestId",
"agora::rtm::IRtmLock.getLocks": "requestId",
"agora::rtm::IRtmLock.removeLock": "requestId",
"agora::rtm::IRtmLock.acquireLock": "requestId",
"agora::rtm::IRtmLock.releaseLock": "requestId",
"agora::rtm::IRtmLock.revokeLock": "requestId",
"agora::rtm::IRtmStorage.setChannelMetadata": "requestId",
"agora::rtm::IRtmStorage.updateChannelMetadata": "requestId",
"agora::rtm::IRtmStorage.removeChannelMetadata": "requestId",
"agora::rtm::IRtmStorage.getChannelMetadata": "requestId",
"agora::rtm::IRtmStorage.setUserMetadata": "requestId",
"agora::rtm::IRtmStorage.updateUserMetadata": "requestId",
"agora::rtm::IRtmStorage.removeUserMetadata": "requestId",
"agora::rtm::IRtmStorage.getUserMetadata": "requestId",
"agora::rtm::IRtmStorage.subscribeUserMetadata": "requestId",
"agora::rtm::IStreamChannel.join": "requestId",
"agora::rtm::IStreamChannel.leave": "requestId",
"agora::rtm::IStreamChannel.joinTopic": "requestId",
"agora::rtm::IStreamChannel.leaveTopic": "requestId",
"agora::rtm::IRtmClient.publish": "requestId",
"agora::rtm::IRtmClient.subscribe": "requestId"
}
1 change: 1 addition & 0 deletions scripts/terra/config/param_type_list.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"agora::rtm::IMetadata.getMetadataItems.items@type": "MetadataItem*",
"agora::rtm::IChannelMember\\*": "IChannelMember",
"agora::rtm::IRtmClient.createStreamChannel@return_type": "IStreamChannel",
"agora::rtm::IRtmClient.getPresence@return_type": "IRtmPresence",
"^Optional<(.*)>": "$1",
"^util::(.*)": "$1",
"^agora::(.*)": "$1",
Expand Down
8 changes: 8 additions & 0 deletions scripts/terra/impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
isMatch,
} from './utils';

const implSpecialReturnList = require('./config/impl_special_return_list.json');
const paramOptionalList = require('./config/param_optional_list.json');

interface CXXFileUserData {
Expand All @@ -31,6 +32,7 @@ interface ClazzMethodUserData {
hasParameters: boolean;
bindingFunctionName?: string;
bindingIrisKey?: string;
returnParamName?: string;
}

export function impl(parseResult: ParseResult) {
Expand Down Expand Up @@ -65,6 +67,12 @@ export function impl(parseResult: ParseResult) {
bindingFunctionName: `getApiTypeFrom${
method.name.charAt(0).toUpperCase() + method.name.slice(1)
}`,
returnParamName:
method.parameters.filter((param) => {
return param.name === implSpecialReturnList[method.fullName];
}).length > 0
? implSpecialReturnList[method.fullName]
: 'result',
bindingIrisKey: `${node.asClazz().name.slice(1)}_${method.name}`,
};
method.user_data = clazzMethodUserData;
Expand Down
2 changes: 1 addition & 1 deletion scripts/terra/templates/impl/file_content.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class {{name}}Impl implements {{name}}{
{{/user_data.hasParameters}}
};
const jsonResults = callIrisApi.call(this, apiType, jsonParams);
return jsonResults.result;
return jsonResults.{{user_data.returnParamName}};
}

protected {{user_data.bindingFunctionName}}(): string {
Expand Down
2 changes: 1 addition & 1 deletion src/IAgoraRtmClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ export abstract class IRtmClient {
abstract logout(): number;
abstract getStorage(): IRtmStorage[];
abstract getLock(): IRtmLock[];
abstract getPresence(): IRtmPresence[];
abstract getPresence(): IRtmPresence;
abstract renewToken(token: string): number;
abstract publish(
channelName: string,
Expand Down
6 changes: 3 additions & 3 deletions src/impl/IAgoraRtmClientImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ export class IRtmClientImpl implements IRtmClient {
return 'RtmClient_getLock';
}

getPresence(): IRtmPresence[] {
getPresence(): IRtmPresence {
const apiType = this.getApiTypeFromGetPresence();
const jsonParams = {};
const jsonResults = callIrisApi.call(this, apiType, jsonParams);
Expand Down Expand Up @@ -490,7 +490,7 @@ export class IRtmClientImpl implements IRtmClient {
},
};
const jsonResults = callIrisApi.call(this, apiType, jsonParams);
return jsonResults.result;
return jsonResults.requestId;
}

protected getApiTypeFromPublish(): string {
Expand All @@ -516,7 +516,7 @@ export class IRtmClientImpl implements IRtmClient {
},
};
const jsonResults = callIrisApi.call(this, apiType, jsonParams);
return jsonResults.result;
return jsonResults.requestId;
}

protected getApiTypeFromSubscribe(): string {
Expand Down
12 changes: 6 additions & 6 deletions src/impl/IAgoraRtmLockImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class IRtmLockImpl implements IRtmLock {
},
};
const jsonResults = callIrisApi.call(this, apiType, jsonParams);
return jsonResults.result;
return jsonResults.requestId;
}

protected getApiTypeFromSetLock(): string {
Expand All @@ -57,7 +57,7 @@ export class IRtmLockImpl implements IRtmLock {
},
};
const jsonResults = callIrisApi.call(this, apiType, jsonParams);
return jsonResults.result;
return jsonResults.requestId;
}

protected getApiTypeFromGetLocks(): string {
Expand Down Expand Up @@ -86,7 +86,7 @@ export class IRtmLockImpl implements IRtmLock {
},
};
const jsonResults = callIrisApi.call(this, apiType, jsonParams);
return jsonResults.result;
return jsonResults.requestId;
}

protected getApiTypeFromRemoveLock(): string {
Expand Down Expand Up @@ -118,7 +118,7 @@ export class IRtmLockImpl implements IRtmLock {
},
};
const jsonResults = callIrisApi.call(this, apiType, jsonParams);
return jsonResults.result;
return jsonResults.requestId;
}

protected getApiTypeFromAcquireLock(): string {
Expand Down Expand Up @@ -147,7 +147,7 @@ export class IRtmLockImpl implements IRtmLock {
},
};
const jsonResults = callIrisApi.call(this, apiType, jsonParams);
return jsonResults.result;
return jsonResults.requestId;
}

protected getApiTypeFromReleaseLock(): string {
Expand Down Expand Up @@ -179,7 +179,7 @@ export class IRtmLockImpl implements IRtmLock {
},
};
const jsonResults = callIrisApi.call(this, apiType, jsonParams);
return jsonResults.result;
return jsonResults.requestId;
}

protected getApiTypeFromRevokeLock(): string {
Expand Down
10 changes: 5 additions & 5 deletions src/impl/IAgoraRtmPresenceImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class IRtmPresenceImpl implements IRtmPresence {
},
};
const jsonResults = callIrisApi.call(this, apiType, jsonParams);
return jsonResults.result;
return jsonResults.requestId;
}

protected getApiTypeFromWhoNow(): string {
Expand All @@ -53,7 +53,7 @@ export class IRtmPresenceImpl implements IRtmPresence {
},
};
const jsonResults = callIrisApi.call(this, apiType, jsonParams);
return jsonResults.result;
return jsonResults.requestId;
}

protected getApiTypeFromWhereNow(): string {
Expand Down Expand Up @@ -85,7 +85,7 @@ export class IRtmPresenceImpl implements IRtmPresence {
},
};
const jsonResults = callIrisApi.call(this, apiType, jsonParams);
return jsonResults.result;
return jsonResults.requestId;
}

protected getApiTypeFromSetState(): string {
Expand Down Expand Up @@ -117,7 +117,7 @@ export class IRtmPresenceImpl implements IRtmPresence {
},
};
const jsonResults = callIrisApi.call(this, apiType, jsonParams);
return jsonResults.result;
return jsonResults.requestId;
}

protected getApiTypeFromRemoveState(): string {
Expand Down Expand Up @@ -146,7 +146,7 @@ export class IRtmPresenceImpl implements IRtmPresence {
},
};
const jsonResults = callIrisApi.call(this, apiType, jsonParams);
return jsonResults.result;
return jsonResults.requestId;
}

protected getApiTypeFromGetState(): string {
Expand Down
Loading

0 comments on commit 0f347b3

Please sign in to comment.