{"id":24905662,"url":"https://github.com/zcduthie/webviewrtcdatachannel","last_synced_at":"2025-08-06T11:09:31.885Z","repository":{"id":56927492,"uuid":"180776318","full_name":"zcduthie/WebViewRTCDataChannel","owner":"zcduthie","description":"A simple working iOS RTCDataChannel built using WKWebView","archived":false,"fork":false,"pushed_at":"2019-04-15T13:11:41.000Z","size":209,"stargazers_count":11,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-07T13:16:46.289Z","etag":null,"topics":["data-channel","datachannel","ios","rtcdatachannel","webrtc","webview","wkwebview"],"latest_commit_sha":null,"homepage":null,"language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zcduthie.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-04-11T11:18:14.000Z","updated_at":"2024-09-06T15:23:22.000Z","dependencies_parsed_at":"2022-08-21T05:50:52.276Z","dependency_job_id":null,"html_url":"https://github.com/zcduthie/WebViewRTCDataChannel","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/zcduthie/WebViewRTCDataChannel","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zcduthie%2FWebViewRTCDataChannel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zcduthie%2FWebViewRTCDataChannel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zcduthie%2FWebViewRTCDataChannel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zcduthie%2FWebViewRTCDataChannel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zcduthie","download_url":"https://codeload.github.com/zcduthie/WebViewRTCDataChannel/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zcduthie%2FWebViewRTCDataChannel/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269067431,"owners_count":24354270,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-06T02:00:09.910Z","response_time":99,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["data-channel","datachannel","ios","rtcdatachannel","webrtc","webview","wkwebview"],"created_at":"2025-02-02T00:23:51.437Z","updated_at":"2025-08-06T11:09:31.841Z","avatar_url":"https://github.com/zcduthie.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# WebViewRTCDataChannel\n\nA simple working iOS RTCDataChannel built using WKWebView.\n\nRather than include the external native WebRTC iOS framework at [https://webrtc.org/native-code/ios](https://webrtc.org/native-code/ios/), this library leverages WebKit's inbuilt WebRTC functionality and exposes WebRTC functionality through the WKWebView control.\n\n[![CI Status](https://img.shields.io/travis/zcduthie/WebViewRTCDataChannel.svg?style=flat)](https://travis-ci.org/zcduthie/WebViewRTCDataChannel)\n[![Version](https://img.shields.io/cocoapods/v/WebViewRTCDataChannel.svg?style=flat)](https://cocoapods.org/pods/WebViewRTCDataChannel)\n[![License](https://img.shields.io/cocoapods/l/WebViewRTCDataChannel.svg?style=flat)](https://cocoapods.org/pods/WebViewRTCDataChannel)\n[![Platform](https://img.shields.io/cocoapods/p/WebViewRTCDataChannel.svg?style=flat)](https://cocoapods.org/pods/WebViewRTCDataChannel)\n\n## Example\n\nThe example included for this project is built as an end point to the 'as simple as it gets' [WebRTC-Example-DataChannel](https://github.com/zcduthie/WebRTC-Example-RTCDataChannel) project.\n\nThe [WebRTC-Example-DataChannel](https://github.com/zcduthie/WebRTC-Example-RTCDataChannel) project contains both a signaling server, and sample clients that can run and communicate through the server.\n\nThe example included in this project acts as one of the clients. Follow the instructions given in the [WebRTC-Example-DataChannel](https://github.com/zcduthie/WebRTC-Example-RTCDataChannel) project to start a copy of the server and open one client, and then use this project's included example as the other client. You'll need to update the following line in ViewController.swift:\n```swift\nlet WEBSOCKET_SERVER = \"wss://10.0.0.30:8443\"\n```\n\nTo run the example project, clone the repo, and run `pod install` from the Example directory first.\n\n## Installation\n\nWebViewRTCDataChannel is available through [CocoaPods](https://cocoapods.org). To install\nit, simply add the following line to your Podfile:\n\n```ruby\npod 'WebViewRTCDataChannel'\n```\n\n## Usage\n\nTo create a data channel, first you'll need to fetch and provide ice servers that include TURN servers.\n```swift\n// Fetch Ice Servers\n// Use Twilio helper (provided for convenience), or provide yourself\nTwilio.fetchNTSToken { (iceServers) in\n    DispatchQueue.main.async { // data channel must be created on main thread\n        createWebViewRTCDataChannel(withConfiguration: Configuration(iceServers: iceServers))\n    }\n}\n\n// Create an instance of the data channel\nprivate func createWebViewRTCDataChannel(withConfiguration configuration: Configuration) {\n    var webViewRTCDataChannel = WebViewRTCDataChannel(delegate: self,\n                                                    view: view,\n                                                    configuration: configuration)\n}\n\n\n```\n\nOnce it's created, you can listen for messages received through the data channel.\n```swift\n// Listen for data channel events\nextension ViewController: WebViewRTCDataChannelDelegate {\n\n    func webViewRTCDataChannelDidOpen(_ dataChannel: WebViewRTCDataChannel) {\n        print(\"webViewRTCDataChannelDidOpen\")\n    }\n\n    func webViewRTCDataChannelDidClose(_ dataChannel: WebViewRTCDataChannel) {\n        print(\"webViewRTCDataChannelDidClose\")\n    }\n\n    func webViewRTCDataChannel(_ dataChannel: WebViewRTCDataChannel, didError error: String) {\n        print(\"webViewRTCDataChannel didError: \\(error)\")\n    }\n\n    func webViewRTCDataChannel(_ dataChannel: WebViewRTCDataChannel, didSetLocalDescription sessionDescription: Dictionary\u003cString, Any\u003e) {\n        signallingChannel.sendSessionDescription(sdp: sessionDescription)\n    }\n\n    func webViewRTCDataChannel(_ dataChannel: WebViewRTCDataChannel, didGetIceCandidate candidate: Dictionary\u003cString, Any\u003e) {\n        signallingChannel.sendIce(ice: candidate)\n    }\n\n    func webViewRTCDataChannel(_ dataChannel: WebViewRTCDataChannel, didReceiveMessage message: String) {\n        print(message)\n    }\n}\n```\n\n## iOS WebRTC Support Summary\n(Relevant as of March 2019)\n\nWebKit announced support for WebRTC from iOS 11.\u003cbr\u003e\n\nBoth WKWebView and Safari are built on top of WebKit, however their WebRTC support differs as follows:\n\n### **Safari**\n\nSince iOS11, **Safari App Browser now fully supports WebRTC**.\n\nThe caveat to this is that by default Safari does not expose 'Host' ICE Candidates for security reasons. This means that WebRTC likely won't be able to establish a connection over STUN - and will require a TURN server.\n\nYou can get around this by:\n- Manually disabling the Ice Candidate Restrictions in Developer Settings in Safari Browser (you can do this on both desktop and mobile)\n- Calling getUserMedia()!!! Safari have implemented their security restrictions such that the 'Host' ICE Candidates are disabled *until* you accept Camera/Microphone permissions via getUserMedia(). As such, many people do something like the following (and prompt the user to accept):\n```javascript\n// (taken from WebRTC Samples GitHub)\nif (adapter.browserDetails.browser === 'safari') {\n    try {\n        console.log('Call getUserMedia() to trigger media permission request.');\n        const stream = await navigator.mediaDevices.getUserMedia({'audio': true, 'video': true});\n        stream.getTracks().forEach(t=\u003e t.stop());\n    } catch (e) {\n        console.error('Error requesting permission: ', e);\n        return;\n    }\n}\n```\n\n### **WKWebView**\n\nWebRTC has three main Javascript components:\n- MediaStream (aka getUserMedia)\n- RTCPeerConnection\n- RTCDataChannel\n\nFortunately for us, **WKWebView supports both RTCPeerConnection and RTCDataChannel**. And that's all we need for an RTCDataChannel.\n\nUnfortunately for us, due to security reasons **WKWebView does not yet support MediaStream**. This appears to still be true as of iOS 12. As described in the Safari section above, this is not good news for us, because it means that we can't discover 'Host' ICE Candidates. This leaves us requiring TURN (unless srflx - Server Reflexive candidates work on your network).\n\n\u003cbr\u003e\n\ntldr; WebRTC is **fully supported in Safari**, and **partially supported in WKWebView** (RTCDataChannel works via TURN)\n\n## Roadmap\n\nAs it currently stands, the project exposes a basic implementation of a WebRTC DataChannel through a WKWebView. Whilst the aim of the library is to be very basic, there are numerous improvements that can be made. Some of which include:\n- Add convenient method for enabling / disabling logging\n- Update example to contain it's own README.md with better instructions\n- Update example to use a GUI that matches the Web GUI included in [WebRTC-Example-DataChannel](https://github.com/zcduthie/WebRTC-Example-RTCDataChannel)\n\n## License\n\nWebViewRTCDataChannel is available under the MIT license. See the LICENSE file for more info.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzcduthie%2Fwebviewrtcdatachannel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzcduthie%2Fwebviewrtcdatachannel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzcduthie%2Fwebviewrtcdatachannel/lists"}