Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// swift-tools-version: 5.9
import PackageDescription

let package = Package(
name: "WKWebViewRTC",
defaultLocalization: "en",
platforms: [
.iOS(.v15)
],
products: [
.library(
name: "WKWebViewRTC",
targets: ["WKWebViewRTC"]
)
],
dependencies: [
.package(url: "https://github.com/stasel/WebRTC.git", from: "141.0.0")
],
targets: [
.target(
name: "WKWebViewRTC",
dependencies: [
.product(name: "WebRTC", package: "WebRTC")
],
path: "WKWebViewRTC",
sources: [
"Classes"
],
resources: [
.process("Js/jsWKWebViewRTC.js")
]
)
]
)
23 changes: 14 additions & 9 deletions WKWebViewRTC/Classes/WKWebViewRTC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,21 @@ public class WKWebViewRTC : NSObject {

setWebView(webview: wkwebview)

if let path = Bundle(for: type(of: self)).path(forResource: "jsWKWebViewRTC", ofType: "js") {
if let bindingJS = try? String(contentsOfFile: path, encoding: .utf8) {
let script = WKUserScript(source: bindingJS, injectionTime: .atDocumentStart, forMainFrameOnly: false)
self.userContentController?.addUserScript(script)
}
let jsURL =
Bundle.module.url(forResource: "jsWKWebViewRTC", withExtension: "js")
?? Bundle(for: type(of: self)).url(forResource: "jsWKWebViewRTC", withExtension: "js")

guard let jsURL, let bindingJS = try? String(contentsOf: jsURL, encoding: .utf8) else {
NSLog("Failed to add iOS RTC script")
return
}
else {
NSLog("Failed to add iosrtc script")
return
}

let script = WKUserScript(
source: bindingJS,
injectionTime: .atDocumentStart,
forMainFrameOnly: false
)
self.userContentController?.addUserScript(script)

// Initialize DTLS stuff.
RTCInitializeSSL()
Expand Down