Glance Voice with a Custom Implementation

If you are not going to use the default UI, you must configure your custom implementation to use Glance Voice.

iOS Custom Configuration

Import the Glance Voice header into your implementation:

Objective-C:

#import <Glance_iOS/GlanceVoice.h>

Swift:

Within your Swift implementation import the framework:

import Glance_iOS

Additionally, the following needs to be included in the Objective-C bridging header to access Glance Voice.

#import <Glance_iOS/GlanceVoice.h>

Android Custom Configuration

Include the Glance Voice header file.

Java

import net.glance.glancevoicesdk.GlanceVoice;

Kotlin

import net.glance.glancevoicesdk.GlanceVoice

Availability

Glance Voice requires the Twilio SDK to work. Use the following methods to quickly check if Glance Voice is ready to be used and available.

iOS Availability

Objective-C:

if ([GlanceVoice isAvailable]){
// Twilio SDK present and GlanceVoice is available
}

Swift:

if (GlanceVoice.isAvailable()){
// Twilio SDK present and GlanceVoice is available
}

Android Availability

An instance of the Context object must be passed to the isAvailable function.

Java:

if (GlanceVoice.isAvailable(context)){
// Twilio SDK present and GlanceVoice is available
}

Kotlin:

if (GlanceVoice.isAvailable(context)){
// Twilio SDK present and GlanceVoice is available
}

Events

If you’re doing a custom implementation, you must implement a delegate or listener to react events. Here are the protocols or interfaces for the delegates and listeners and how to set them up on each platform.

iOS Events

The protocol is shared between Objective-C and Swift:

@protocol GlanceVoiceDelegate <NSObject>

@optional

- (void) glanceVoiceAuthenticateDidSucceed:(NSString*)value;
- (void) glanceVoiceAuthenticateDidFail:(NSError*) error;
- (void) glanceVoiceStartDidSucceed;
- (void) glanceVoiceStartDidFail:(NSError*)error;
- (void) glanceVoiceDidDisconnectWithError:(NSError*)error;
- (void) glanceVoiceReconnecting;
- (void) glanceVoiceDidReconnect;
- (void) glanceVoiceReconnectDidTimeout;

@end

Objective-C:

[GlanceVoice setDelegate: this];

Swift:

GlanceVoice.setDelegate(self)

Android Events

public interface GlanceVoice.VoiceListener {
/**
* Called when {@link net.glance.glancevoicesdk.GlanceVoice#authenticate(String, String)} is successful.
*
* @param value The json encoded string with the params needed to make the call.
*/
void authenticationSucceeded(String value);

/**
* Called when {@link net.glance.glancevoicesdk.GlanceVoice#authenticate(String, String)} fails
* @param t A throwable that represents the cause of the failure.
*/
void authenticationFailed(Throwable t);

/**
* Callback for when {@link net.glance.glancevoicesdk.GlanceVoice#startCall(Context, String)} or
{@link net.glance.glancevoicesdk.GlanceVoice#startCall(Context, String, String, String, String)} is successful.
*/
void startSucceeded();

/**
* Called when {@link net.glance.glancevoicesdk.GlanceVoice#startCall(Context, String)} or
{@link net.glance.glancevoicesdk.GlanceVoice#startCall(Context, String, String, String, String)} fails
* @param t A throwable that represents the cause of the failure.
*/
void startFailed(Throwable t);

/**
* Called when the call terminates
*/
void ended(Throwable t);

/**
* Called when a dropped call is attempting to reconnect
*/
void reconnecting();

/**
* Called when a dropped call successfully reconnects
*/
void reconnected();

/**
* Called when a dropped call times out attempting reconnect
*/
void reconnectTimedOut();
}

Android:

GlanceVoice.setListener(listener)

Kotlin:

GlanceVoice.setListener(listener)

Authenticate

With the delegate or listener in place, now you can make the first call to Glance Voice to authenticate with the Glance Voice group ID and API key.

iOS Authentication

Objective-C:

[GlanceVoice authenticate: 1234 apiKey: @yourApiKey];

Swift:

GlanceVoice.authenticate(1234, apiKey: "yourApiKey")

Android Authentication

Java:

GlanceVoice.authenticate("1234", "yourApiKey");

Kotlin:

GlanceVoice.authenticate("1234", "yourApiKey")

Starting a Voice Session

The call to authenticate results in your delegate or listener invoking when the call succeeds or fails. If authentication succeeds, the JSON string passed to the delegate or listener method is required when starting a session. Verify that startCall does in fact succeed or manage its failure with the methods within the delegate or listener.

Start iOS Voice Sessions

Objective-C:

- (void)glanceVoiceAuthenticateDidSucceed:(NSString *)authenticationValue {
[GlanceVoice startCall:authenticationValue];
}

Swift:

func glanceVoiceAuthenticateDidSucceed(_ authenticationValue: String!) {
GlanceVoice.startCall(authenticationValue)
}

Start Android Voice Sessions

Java:

public void authenticationSucceeded(String authenticationValue) {
try {
// mContext is a Context (an Activity or the ApplicationContext)
GlanceVoice.startCall(mContext, authenticationValue);
} catch (SecurityException e) {
// Handle security exception that might occur
}
}

Kotlin:

override fun authenticationSucceeded(authenticationValue : String){
try {
// mContext is a Context (an Activity or the ApplicationContext)
GlanceVoice.startCall(mContext, authenticationValue);
} catch (SecurityException e) {
// Handle security exception that might occur
}
}

Ending a VoiceSession

To end a voice session, invoke endCall.

End an iOS VoiceSession

Objective-C:

[GlanceVoice endCall];

Swift:

GlanceVoice.endCall()

End an Android VoiceSession

Java:

GlanceVoice.endCall();

Kotlin:

GlanceVoice.endCall()

Mute or Unmute a Session

Set the mute state with a boolean yes/no or true/false.

Mute an iOS Session

Objective-C:

[GlanceVoice setMuted: YES];

Swift:

GlanceVoice.setMuted(true)

Mute an Android Session

Java:

GlanceVoice.mute(true);

Kotlin:

GlanceVoice.mute(true)

Enable or Disable Speakerphone

Toggle whether or not the audio of the call is played through the speaker of the phone.

Enable iOS Speakerphone

Objective-C:

[GlanceVoice setSpeakerphoneEnabled:YES];

Swift:

GlanceVoice.setSpeakerphoneEnabled(true)

Enable Android Speakerphone

Java:

GlanceVoice.speakerphone(true);

Kotlin:

GlanceVoice.speakerphone(true)

By continuing to use the site, you agree to the use of cookies. Learn More