Skip to content

Commit

Permalink
pass realtime data from swift-land to js-land
Browse files Browse the repository at this point in the history
  • Loading branch information
r10s committed Jul 4, 2024
1 parent 3c31792 commit 53b070d
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion deltachat-ios/Controller/WebxdcViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ class WebxdcViewController: WebViewViewController {
let should_run_again = false;
let running = false;
let lastSerial = 0;
let realtimeChannel = null;
window.__webxdcUpdate = async () => {
if (running) {
should_run_again = true
Expand All @@ -99,6 +101,12 @@ class WebxdcViewController: WebViewViewController {
}
}
window.__webxdcRealtimeData = (intArray) => {
if (realtimeChannel) {
realtimeChannel.__receive(Uint8Array.from(intArray))
}
}
const createRealtimeChannel = () => {
let listener = null;
return {
Expand Down Expand Up @@ -334,7 +342,9 @@ class WebxdcViewController: WebViewViewController {
) { [weak self] notification in
guard let self, let userInfo = notification.userInfo, let messageId = userInfo["message_id"] as? Int else { return }
if messageId == self.messageId, let data = userInfo["data"] as? Data {
// TODO: pass to js-land
let byteArray = [UInt8](data)
let commaSeparatedString = byteArray.map { String($0) }.joined(separator: ",")
webView.evaluateJavaScript("window.__webxdcRealtimeData([" + commaSeparatedString + "])")
}
}

Expand Down

0 comments on commit 53b070d

Please sign in to comment.