Git Product home page Git Product logo

spark-ios-sdk-example's Introduction

Kitchen Sink

Kitchen Sink is a developer friendly sample implementation of Spark client SDK and showcases all SDK features.

Download App

You can download our Demo App from TestFlight.

  1. Download TestFlight from App Stroe.
  2. Use this portal to register as our external tester:register portal
  3. Check your Email to get your test Redeem code,put this code into TestFlight.
  4. Install Ktichen Sink App from TestFlight.

Setup

Here are the steps to setup Xcode project using CocoaPods:

  1. Install CocoaPods:

    gem install cocoapods
  2. Setup Cocoapods:

    pod setup
  3. Install SparkSDK and other dependencies from your project directory:

    pod install

Example

The "// MARK: " labels in source code have distinguished the SDK calling and UI views paragraphes.
Below is code snippets of the SDK calling in the demo.

  1. Setup SDK with app infomation, and authorize access to Spark service

    class SparkEnvirmonment {
        static let ClientId = "your client ID"
        static let ClientSecret = ProcessInfo().environment["CLIENTSECRET"] ?? "your secret"
        static let Scope = "spark:all"
        static let RedirectUri = "KitchenSink://response"
     }
  2. Register the device to send and receive calls.

    var sparkSDK: Spark?
    /*  
    Register phone to Cisco cloud on behalf of the authenticated user.
    It also creates the websocket and connects to Cisco Spark cloud.
    - note: make sure register phone before calling
    */
    sparkSDK?.phone.register() { [weak self] error in
        if let strongSelf = self {
            if error != nil {
                //success...
            } else {
                //fail...
            }
        }
    }
  3. Spark calling API

     // Self video view and Remote video view
     @IBOutlet weak var selfView: MediaRenderView!
     @IBOutlet weak var remoteView: MediaRenderView!
    
     var sparkSDK: Spark?
     // currentCall represents current dailing/received call instance
     var currentCall: Call?
     
     // Make an outgoing call.
     // audioVideo as making a Video call,audioOnly as making Voice only call.The default is audio call.
         var mediaOption = MediaOption.audioOnly()
         if globalVideoSetting.isVideoEnabled() {
             mediaOption = MediaOption.audioVideo(local: self.selfView, remote: self.remoteView)
         }
         // Makes a call to an intended recipient on behalf of the authenticated user.
         sparkSDK?.phone.dial(remoteAddr, option: mediaOption) { [weak self] result in
             if let strongSelf = self {
                 switch result {
                 case .success(let call):
                     self.currentCall = call
                     // Callback when remote participant(s) is ringing.
                     call.onRinging = { [weak self] in
                         if let strongSelf = self {
                             //...
                         }
                     }
                     // Callback when remote participant(s) answered and this *call* is connected.
                     call.onConnected = { [weak self] in
                         if let strongSelf = self {
                             //...
                         }
                      }
                     //Callback when this *call* is disconnected (hangup, cancelled, get declined or other self device pickup the call).
                     call.onDisconnected = {[weak self] disconnectionType in
                         if let strongSelf = self {
                             //...
                         }
                     }
                     // Callback when the media types of this *call* have changed.
                     call.onMediaChanged = {[weak self] mediaChangeType in
                         if let strongSelf = self {
                             strongSelf.updateAvatarViewVisibility()
                             switch mediaChangeType {
                             //Local/Remote video rendering view size has changed
                             case .localVideoViewSize,.remoteVideoViewSize:
                                 break
                             // This might be triggered when the remote party muted or unmuted the audio.
                             case .remoteSendingAudio(let isSending):
                                 break
                             // This might be triggered when the remote party muted or unmuted the video.
                             case .remoteSendingVideo(let isSending):
                                 break
                             // This might be triggered when the local party muted or unmuted the video.
                             case .sendingAudio(let isSending):
                                 break
                             // This might be triggered when the local party muted or unmuted the aideo.
                             case .sendingVideo(let isSending):
                                 break
                             // Camera FacingMode on local device has switched.
                             case .cameraSwitched:
                                 break
                             // Whether loud speaker on local device is on or not has switched.
                             case .spearkerSwitched:
                                 break
                             default:
                                 break
                             }
                         }
                     }
                 case .failure(let error):
                     _ = strongSelf.navigationController?.popViewController(animated: true)
                     print("Dial call error: \(error)")
                 }
             }
         }
         
     // Receive a call
     if let phone = self.spark?.phone {
             // Callback when call is incoming.
             phone.onIncoming = { [weak self] call in
                 if let strongSelf = self {
                     self.currentCall = call
                     //...
                 }
             }
     }
     
     /* 
      Answers this call.
      This can only be invoked when this call is incoming and in rining status.
      Otherwise error will occur and onError callback will be dispatched.
      */
      self.currentCall?.answer(option: mediaOption) { [weak self] error in
          if let strongSelf = self {
              if error != nil {
                     //...
              }
          }
      }
     
     /* 
      Rejects this call. 
      This can only be invoked when this call is incoming and in rining status.
      Otherwise error will occur and onError callback will be dispatched. 
     */
     self.currentCall?.reject() { error in
             if error != nil {
                 //...
             }
     }

Buddies-App

Here is another demo app-"Buddies", which is more implemented as production application, combined call functionalities with CallKit, included message/call UI-implementation which could be used as widgets. GitHub-Buddies

spark-ios-sdk-example's People

Contributors

xiuwwu avatar qucui avatar kliu avatar xu0101 avatar joe-still avatar

Watchers

James Cloos avatar Jason Wu 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.