Swiftpack.co -  Bandwidth/bandwidth-webrtc-swift as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
An OSS implementation of Bandwidth WebRTC suitable for iOS devices.
.package(url: "https://github.com/Bandwidth/bandwidth-webrtc-swift.git", from: "v0.4.0")

Bandwidth WebRTC Swift

Bandwidth WebRTC Swift is an open-source implementation of Bandwidth WebRTC suitable for iOS devices.

In order to take advantage of this package a Bandwidth account with WebRTC Audio and/or Video must be enabled.

Quick Start

import WebRTC
import BandwidthWebRTC

class WebRTCService {
    let bandwidth = RTCBandwidth()
    var localVideoTrack: RTCVideoTrack?
    var localCameraVideoCapturer: RTCCameraVideoCapturer?

    var remoteVideoTrack: RTCVideoTrack?

    init() {
        bandwidth.delegate = self

        getToken { token in
            try? self.bandwidth.connect(using: token) {
                self.bandwidth.publish(alias: "Bolg") { stream in
                    self.localVideoTrack = stream.mediaStream.track as? RTCVideoTrack
                    // localRenderer should be a UIView of type RTCVideoRenderer. This is the view which displays the local video.

                    self.localCameraVideoCapturer = RTCCameraVideoCapturer()
                    self.localCameraVideoCapturer?.delegate = self.localVideoTrack?.source

                    // Grab the front facing camera. TODO: Add support for additional cameras.
                    guard let device = RTCCameraVideoCapturer.captureDevices().first(where: { $0.position == .front }) else {
                    // Grab the highest resolution available.
                    guard let format = RTCCameraVideoCapturer.supportedFormats(for: device)
                        .sorted(by: { CMVideoFormatDescriptionGetDimensions($0.formatDescription).width < CMVideoFormatDescriptionGetDimensions($1.formatDescription).width })
                        .last else {
                    // Grab the highest fps available.
                    guard let fps = format.videoSupportedFrameRateRanges
                        .compactMap({ $0.maxFrameRate })
                        .last else {
                    // Start capturing local video with the given parameters.
                    self.localCameraVideoCapturer?.startCapture(with: device, format: format, fps: Int(fps))

    func getToken(completion: @escaping (String) -> Void) {
        // Return a Bandwidth WebRTC participant token from your application server. https://dev.bandwidth.com/webrtc/methods/participants/createParticipant.html

extension WebRTCService: RTCBandwidthDelegate {
    func bandwidth(_ bandwidth: RTCBandwidth, streamAvailable stream: RTCStream) {
        if let remoteVideoTrack = stream.mediaStream.track as? RTCVideoTrack {
            self.remoteVideoTrack = remoteVideoTrack
            DispatchQueue.main.async {
                // remoteRenderer should be a UIView of type RTCVideoRenderer. This is the view which displays the remote video.

    func bandwidth(_ bandwidth: RTCBandwidth, streamUnavailable stream: RTCStream) {


A number of samples using Bandwidth WebRTC Swift may be found within Bandwidth-Samples.


Bandwidth WebRTC Swift follows SemVer 2.0.0.


Stars: 1
Last commit: 5 weeks ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Release Notes

Bandwidth WebRTC v0.4.0
5 weeks ago


  • Update to Bandwidth's latest signaling server implementation.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API