```javascript
async function uploadMedia() {
- // ask the user to choose their media
+ // ask the user to choose their media asynchronously
// upload the media to your storage service
// return a unique identifier for the media
@@ -43,6 +43,82 @@ async function uploadMedia() {
return { id: mediaId, title, width, height };
}
```
+
+```swift
+func uploadMedia() async -> JSONObject {
+ // ask the user to choose their media asynchronously
+ // upload the media to your storage service
+ // return a unique identifier for the media
+
+ // mock implementation:
+ let mediaId = "abcd123abcd"
+
+ // Some media metadata, useful for displaying the media in the UI
+ let title = "A beautiful image"
+ let width = 1024
+ let height = 768
+
+ // Return the object
+ return [
+ "id": .string(mediaId),
+ "title": .string(title),
+ "width": .number(Double(width)),
+ "height": .number(Double(height))
+ ]
+}
+```
+
+```kotlin
+import com.ably.chat.json.*
+
+suspend fun uploadMedia(): JsonObject {
+ // ask the user to choose their media asynchronously
+ // upload the media to your storage service
+ // return a unique identifier for the media
+
+ // mock implementation:
+ val mediaId = "abcd123abcd"
+
+ // Some media metadata, useful for displaying the media in the UI
+ val title = "A beautiful image"
+ val width = 1024
+ val height = 768
+
+ // Return the object
+ return jsonObject {
+ put("id", mediaId)
+ put("title", title)
+ put("width", width)
+ put("height", height)
+ }
+}
+```
+
+```jetpack
+import com.ably.chat.json.*
+
+suspend fun uploadMedia(): JsonObject {
+ // ask the user to choose their media asynchronously
+ // upload the media to your storage service
+ // return a unique identifier for the media
+
+ // mock implementation:
+ val mediaId = "abcd123abcd"
+
+ // Some media metadata, useful for displaying the media in the UI
+ val title = "A beautiful image"
+ val width = 1024
+ val height = 768
+
+ // Return the object
+ return jsonObject {
+ put("id", mediaId)
+ put("title", title)
+ put("width", width)
+ put("height", height)
+ }
+}
+```
Use the `uploadMedia()` flow to save the resulting object. In your UI, the `mediaToAttach` array should be displayed so that users can see which which media will be attached to their message. It also enables users to add or remove selected media.
@@ -77,6 +153,59 @@ const ChatComponent = () => {
);
};
```
+
+```swift
+var mediaToAttach: [JSONObject] = []
+
+func onMediaAttach() async {
+ let mediaData = await uploadMedia()
+ mediaToAttach.append(mediaData)
+}
+```
+
+```kotlin
+import com.ably.chat.json.JsonObject
+
+var mediaToAttach = mutableListOfTyping Error: {error.message}
} -Currently typing: {Array.from(currentlyTyping).join(', ')}
+ {roomError &&Typing Error: {roomError.message}
} +Currently typing: {Array.from(currentlyTyping).join(', ')}
Typing Error: {error.message}
} + {roomError &&Typing Error: {roomError.message}
}Currently typing: {Array.from(currentlyTyping).join(', ')}
Typing Error: {error.message}
} + {roomError &&Typing Error: {roomError.message}
}