Getting Started

This guide will help you to get started with the SDK. The SDK is a set of tools that allows you to interact with the API.

Pre-requisite:

  • Firebase Project(Used for account management) - Create a Firebase project in the Firebase console if you don’t already have one. You can do this by visiting the Firebase Console.
  • Register your project on firebase.

Integrating the SDK

  • Download the google-services.json file from the firebase console and place it in the <project>/<app-module> directory of your project.
  • Add the plugin to your <project>/build.gradle.kts file.
plugins {
  id("com.google.gms.google-services") version "4.5.0" apply false
}
  • Add the plugin to your <project>/<app-module>/build.gradle.kts file.
plugins {
  id("com.google.gms.google-services")
}
  • Add the following repository to your <project>/settings.gradle.kts file.
    dependencyResolutionManagement {
      repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
      repositories {
          google()
          mavenCentral()
          maven("https://nexus.instavision.ai/repository/maven-releases/") // This line needs to be added
      }
    }
    
  • Add the following dependency to your <project>/<app-module>/build.gradle.kts file.
dependencies {
  implementation("ai.instavision:guardian:<version>") // version can be found in the change log.
}

Initializing the SDK

  • Create an Application file and initialize the SDK and firebase.
class SampleApp : Application() {
  override fun onCreate() {
    super.onCreate()
    FirebaseApp.initializeApp(this)
    InstaVision.initialize(
      applicationContext = this@SampleApp,
      config = InstaVisionConfig(
        partnerId =  "Your-Partner-Id",
        clientId = "Your-Client-Id",
        deviceId = "Your-Device-Id",
        sessionId = "Your-Session-Id",
        region = ServerRegions.US, // Optional, defaults to ServerRegions.US
        environment = Environment.RELEASE, // Optional, defaults to Environment.RELEASE
        analytics = analytics, // Optional, an InsightEngine implementation, defaults to a no-op
        useOnlySoftwareCodec = false // Optional, forces software video codecs, defaults to false
      )
    )
  }
}
  • Add the following code to your <project>/<app-module>/AndroidManifest.xml file.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
  <uses-permission android:name="android.permission.INTERNET" />
  <application android:name=".SampleApp" android:icon="@mipmap/ic_launcher"
      android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round"
      android:supportsRtl="true" android:theme="@android:style/Theme.Material.Light.NoActionBar">
    <activity android:name=".MainActivity" android:exported="true">
      <intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>
    </activity>
  </application>
</manifest>
  • Report foreground changes so the SDK can release the microphone while the app is backgrounded.
class MainActivity : ComponentActivity() {
  override fun onStart() {
    super.onStart()
    InstaVision.setAppInForeground(true)
  }

  override fun onStop() {
    super.onStop()
    InstaVision.setAppInForeground(false)
  }
}
  • To change the region after initialization, use InstaVision.setRegion(...). The SDK reconnects its services, including the realtime event connection, on its own.
InstaVision.setRegion(ServerRegions.EU)

Waiting for initialisation

initialize assigns the services synchronously, but WebRTC set-up and persisting the partner / client ids finish on a background thread. Observe InstaVision.isInitialized and make the first network call only once it is true:

lifecycleScope.launch {
  InstaVision.isInitialized.collect { ready ->
    if (ready) { /* InstaVision.userServices … */ }
  }
}

This site uses Just the Docs, a documentation theme for Jekyll.