基于socket.io实现
npm install @activatortube/supernova-sdk
# 或者
yarn add @activatortube/supernova-sdk
- 添加依赖
# 1. 添加依赖
npm install @activatortube/supernova-sdk
# 或者
yarn add @activatortube/supernova-sdk
# 2. 添加react-native-get-random-values,比Web需要多一步
yarn add react-native-get-random-values
- 安装依赖
npx pod-install
- 然后在项目的起始位置引用
import 'react-native-get-random-values';
import 'react-native-get-random-values';
import SuperNova from '@activatortube/supernova-sdk';
const Chat = () => {
useEffect(() => {
// 初始化项目
SuperNova.init(Config.SUPERNOVA_ENDPOINT, 'debug');
// 登录到聊天服务器
const instance = SuperNova.getInstance();
instance.login('', '');
// 添加消息事件
const messageHandler = (message: Message) => {
console.log(`收到一条新消息:`, message);
// TODO
};
SuperNova.getInstance().addMessageHandler(messageHandler);
return () => {
SuperNova.getInstance().removeMessageHandler(messageHandler);
};
}, []);
// TODO
};