From 53b070d94574d704db66d3c597d306ffbeb243b3 Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Mon, 1 Jul 2024 15:05:39 +0200 Subject: [PATCH] pass realtime data from swift-land to js-land --- deltachat-ios/Controller/WebxdcViewController.swift | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/deltachat-ios/Controller/WebxdcViewController.swift b/deltachat-ios/Controller/WebxdcViewController.swift index b363031ce..54f3bba4d 100644 --- a/deltachat-ios/Controller/WebxdcViewController.swift +++ b/deltachat-ios/Controller/WebxdcViewController.swift @@ -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 @@ -99,6 +101,12 @@ class WebxdcViewController: WebViewViewController { } } + window.__webxdcRealtimeData = (intArray) => { + if (realtimeChannel) { + realtimeChannel.__receive(Uint8Array.from(intArray)) + } + } + const createRealtimeChannel = () => { let listener = null; return { @@ -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 + "])") } }