Using Both Manual and One-Click Sessions in the Same Application

Use the following instructions to make screen share available for both pre and post-login scenarios. The examples in this page are macOS specific in Swift, but the concepts are similar in other platforms.

Initialization

After the application launches (most likely in UIApplicationDelegate application:didFinishLaunchingWithOptions: or the UIViewController viewDidLoad delegate method for the main view) the application should call GlanceVisitor.initVisitor without a visitor ID:

let GLANCE_GROUP_ID : Int32 = 12345  // Replace the group ID number with your group ID.      

GlanceVisitor.initVisitor(GLANCE_GROUP_ID, token: "",
  	  name: "", email: "", phone: "")

Upon receiving EventVisitorInitialized the screen share button should be made visible.

UI

If you are implementing your own custom UI, you must disable the Glance Default UI. After calling initVisitor the first time, the application calls: GlanceVisitor.defaultUI(false);

Starting a Session

The handler for the screen share button starts the session with a random key:GlanceVisitor.startSession("GLANCE_KEYTYPE_RANDOM")

Upon receiving EventConnectedToSession, the key is retrieved from the event and displayed to the customer.

        case EventConnectedToSession:
            // Show any UI to indicate the session has started
            // event.properties includes the sessionKey which can be
            // displayed to the user to read to the agent
            myShowKeyMethod(event.properties["sessionkey"] as! String)
            Break

The customer will verbally give the key to the agent. After the agent enters the key and connects, the application will receive EventGuestCountChanged.

After Login

After the customer logs in and is identified, the implementation uses the Glance Presence (“One-click Screen share”) functionality. In addition, to support the case where the support agent is not on the correct customer record in the CRM, there is a manual verbal key fallback that works similarly to the pre-login case.

Initialization

After customer login, the application calls GlanceVisitor.initVisitor again with a visitor ID. The application must pass the same Glance Group ID used in the initial call above:

GlanceVisitor.initVisitor(GLANCE_GROUP_ID, token: "",
  	  name: "", email: "", phone: "",
  	  visitorid: visitorid)

Upon receiving EventVisitorInitialized the application calls GlancePresenceVisitor.connect.

If you are implementing your own custom Presence UI, disable the Glance default Presence UI.
Example:

        switch event.code {
            case EventVisitorInitialized:
                DispatchQueue.main.async {
                    GlancePresenceVisitor.connect()
                    GlancePresenceVisitor.setDefaultUI(false)
                }
                break;

One-Click Session Start

The agent is notified when the customer is online and may start a screen sharing session. Typically, a button will light up on the CRM record in the agent’s browser. When the Agent clicks the button, a signal is relayed to the SDK where an EventPresenceShowTerms event fires.

If you have a custom Presence UI, when EventPresenceShowTerms is received, the application will show any terms and conditions and display buttons for the customer to Accept or Decline screen sharing.

When terms and conditions are presented to the customer, the application should signal the agent by calling:

GlancePresenceVisitor.signalAgent("terms", map: ["status": "displayed"])

If the customer declines screen sharing, the application notifies the agent by calling:

GlancePresenceVisitor.signalAgent("terms", map: ["status": "declined"])

If the customer accepts screen sharing the application notifies the agent and starts the session by calling GlanceVisitor.startSession with NO arguments:

GlancePresenceVisitor.signalAgent("terms", map: ["status": "accepted"])
GlanceVisitor.startSession()

Calling startSession with no arguments starts a session using the visitor ID supplied in initVisitor. The agent will be waiting for a session with this key.

The same session events as noted above are posted, specifically, EventSessionConnected when the application connects to the server and EventGuestCountChanged when the agent connects to the session. Unlike the pre-login case above, or manual case below, the application will not show the session key to the customer on EventSessionConnected.

Manual Session Start

Although the visitor may be logged in and connected to the Presence service, the agent may be on the wrong customer record in the CRM or have some other difficulty initiating the session automatically.

As a fallback for this case the application can also contain a screen share button that the agent may direct the customer to tap.

The button handler for the screen share button starts a session with a random key by calling:

GlanceVisitor.startSession("GLANCE_KEYTYPE_RANDOM")

This is the same call as in the pre-login case, manually taping the screen share button should always invoke this method.

Again, as in the pre-login case, on receiving EventSessionConnected the application must display the random key retrieved from the event. The application should keep track of whether a session was manually started or not to decide whether or not to show the key to the customer.

The application should call PresenceVisitor.disconnect() when the user logs out or when exiting.

The SDK automatically manages the presence connection when the application goes into the background and when it is reactivated; the application should not attempt to handle this with calls to disconnect and connect.