是否可以在不弹出的情况下将 GetStream.io 与使用 Create React Native App 构建的 React Native 应用程序集成?

Is it possible to integrate GetStream.io with a React Native app built with Create React Native App without ejecting?

我正在尝试使用 getstream.io 的客户端功能 (特别是提要拉取和实时更新)在使用 react-native 构建的本机应用程序上构建流。当我尝试使用从我的服务器传递的令牌在 javascript 代码中初始化客户端时,出现错误:

[Error: Missing app id, which is needed to subscribe, use var client = stream.connect(key, secret, appId);]

但是,当我添加密钥和 appId(出于测试目的,我会非常谨慎地部署)时出现错误:

[Error: You are publicly sharing your private key. Dont use the private key while in the browser.]

有没有办法在不从 Create React Native App 弹出的情况下使用 Expo(Create React Native App 默认设置)获取客户端版本 运行?

出于安全原因,您无法使用 JS 客户端在客户端生成令牌,因为这需要共享您的 Api 密钥。

要走的路是让您的后端创建特定于提要的令牌并将它们发送到您的客户端应用程序。

服务器端 (Ruby):

require 'stream'
client = Stream::Client.new('YOUR_API_KEY', 'API_KEY_SECRET')
feed = client.feed('user', '1')
token = feed.token

客户端 (JS):

client = stream.connect('YOUR_API_KEY', null, 'SITE_ID');
user1 = client.feed('user', '1', token);