Closed yash-luna closed 1 year ago
Just to add some context here, right now our RN sdk only supports one content type: Text. We want to support more content types which means we need a few things:
Content types are defined by creating a ContentTypeId
(see example here). We'll need to introduce that type to our React Native SDK.
Once you've got your content type, you need to define a codec so that the client knows how to serialize whatever type of content you're trying to send (in our example, Attachment is the type of content we're trying to send). Adding codec support to React Native will consist of introducing a ContentCodec
interface that codecs can implement as well as its supporting types like:
EncodedContent
Represents the serialized encoded content. This is backed by a protocol buffer which enables us to send it over the networkCodecRegistry
A list of codecs stored by the client, keyed by a ContentTypeId
. Content types must be registered before they can be used.Once the basics of content types are introduced we'll need to actually be able to use them. We'll need to modify conversations.send
to take content options:
const number: number = 123
await conversation.send(number, {
contentType: ContentTypeNumber, // Assume we've defined a Number content type
contentFallback: "a string that gets used when clients don't know this type"
})
This will require some changes to our native code. I think the best approach might be to expose a way to send EncodedContent directly in swift/kotlin. That way we could just use a codec react native to get EncodedContent, serialize that so that we can pass it to the native code, then the native code can send without needing to know about the codecs.
We'll need to teach the RN decodeMessage
method how to deal with non-text content types. I think at a high level we can decrypt the message in the native code to get an instance of EncodedContent
, then serialize it and pass it back to the RN code. This might be a bit tricky because we're just using JSON for serializing in native -> RN code and JSON doesn't support binary, but I think we can figure that out in a follow up if we just have the basics done.
--
I think those are the broad strokes of what needs to happen here. Feel free to hit me up with any questions at any time!
For reference, here's the PR that introduced content types into the iOS SDK. It's not going to be the same with RN but it should give a sense of all the moving parts: https://github.com/xmtp/xmtp-ios/pull/26.
@nakajima Are Javascript ContentCodec
s going to be portable to the RN SDK with this feature? Feels like that would be pretty slick. Write the codec once, publish it as a package, and then you can import it in both your web and mobile SDKs.
@nakajima Are Javascript ContentCodecs going to be portable to the RN SDK with this feature? Feels like that would be pretty slick. Write the codec once, publish it as a package, and then you can import it in both your web and mobile SDKs.
I think that'll eventually be the case. First we might need to extract the content type plumbing (EncodedContent, ContentCodec etc) to its own package so that they can be imported by xmtp-js OR xmtp-react-native. Definitely do-able, probably better to just get stuff working in RN first though.
Closed with merging of https://github.com/xmtp/xmtp-react-native/pull/63
Support for content types in React Native
Typescript
No native modules need to be touched for this initial step.
Test