Giter VIP home page Giter VIP logo

swiftywebrtc's Introduction

SwiftyWebRTC

As the name suggests, this is an framework for iOS implementation of the Google WebRTC framework, it contains build in WebRTC.Framework and RTCClient (written in swift) to let you easily add video/audio call capability to your app.

About

This Framework provides you with a resuable wrapper written in swift (swift3) for comfortable and easy using of Google WebRTC framework and making your ios app video call enabled. WebRTC is an open-source project (libjingle_peerConnection) maintained by google with high-level API implementations for both iOS and Android. WebRTC api can be read from here. WebRTC Framework used in project has been build from here

If you want to know about the wrapper implementation that can be checked from my blog in here

Source

Carthage

Framework can be added using following to your cartfile

github "Ankit-Aggarwal/SwiftyWebRTC" 

Usage:

Integration RTCClient to your controller is easy.

  1. You need to add following two properties to your controller
    var videoClient: RTCClient?
    var captureController: RTCCapturer! // custom capturer that can be used to switch camera (front/back camera)
  1. Configure Client:
    func configureVideoClient() {
    // You can pass on iceServers your app wanna use 
    // RTCClient can be used for only audio call also where videoCall is by default
        let client = RTCClient(iceServers: iceServers, videoCall: true)
        client.delegate = self
        self.videoClient = client
        client.startConnection()
    }
  1. Your controller needs to conform to RTCClientDelegate, which will help your client to interact with server for passing info
extension VideoChatViewController: RTCClientDelegate {

    func rtcClient(client: RTCClient, didCreateLocalCapturer capturer: RTCCameraVideoCapturer) {
    // To handle when camera is not available
        if UIDevice.current.modelName != "Simulator" {
            let settingsModel = RTCCapturerSettingsModel()
            self.captureController = RTCCapturer.init(withCapturer: capturer, settingsModel: settingsModel)
            captureController.startCapture()
        }
    }
    
    func rtcClient(client : RTCClient, didReceiveError error: Error) {
        // Error Received
        }
    }

    func rtcClient(client : RTCClient, didGenerateIceCandidate iceCandidate: RTCIceCandidate) {
     // iceCandidate generated, pass this to other user using any signal method your app uses
    }

    func rtcClient(client : RTCClient, startCallWithSdp sdp: String) {
       // SDP generated, pass this to other user using any signal method your app uses
    }

    func rtcClient(client : RTCClient, didReceiveLocalVideoTrack localVideoTrack: RTCVideoTrack) {
    // Use localVideoTrack generated for rendering stream to remoteVideoView
        localVideoTrack.add(self.localVideoView)
        self.localVideoTrack = localVideoTrack
    }
    func rtcClient(client : RTCClient, didReceiveRemoteVideoTrack remoteVideoTrack: RTCVideoTrack) {
    // Use remoteVideoTrack generated for rendering stream to remoteVideoView
        remoteVideoTrack.add(self.remoteVideoView)
        self.remoteVideoTrack = remoteVideoTrack
    }
}
  1. After setting all this, you can easily switch between front/back camera as follows
        self.captureController.switchCamera()

This is all you need to let the data flowing :)

Contributing

If you'd like to contribute, please fork the repository and issue pull requests. If you have any special requests and want to collaborate, please contact me directly. Thanks!

May add a example project in the repo, depending on the requests i get...

swiftywebrtc's People

Contributors

ankit-aggarwal avatar frimicc avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.