Skip to content

About

In-app remote support for macOS apps: a "Get help" button that shares your app window with your support team, consent first, with masking and optional guided control. Screen sharing SDK for Swift (Swift Package Manager, ScreenCaptureKit).

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

GaiaDeskEmbed (Swift, macOS)

CI Release SwiftPM compatible License: MIT + binary licence

A "Get help" button for your Mac app: in-app remote support and a screen sharing SDK for macOS in Swift, for customer support with optional guided control. Your customer clicks it and agrees; your app's window is shared with your support team, who see it in the GaiaDesk console's Support page and, if you allow it, guide it: click and type inside your app only.

  • Swift Package wrapping libgaiadesk_embed (a prebuilt universal XCFramework, Apple silicon and Intel, macOS 12.3+).
  • Consent first: the library refuses to start until your user has agreed. Its consent step shows a live preview of exactly what support will see, lets the customer choose, and keeps a consent receipt (0.4.0).
  • Shares your app's own window by default (ScreenCaptureKit window capture). Your app's other windows, other apps and the desktop are never in the picture unless you opt into .app or .screen.
  • A visible "Sharing with Acme · Stop sharing" panel, drawn by the library, for as long as anything is shared. Frames only leave while it is on screen.
  • Mask password fields, card numbers, anything: they are painted black before a frame is encoded.
  • View-only by default. Guided mode delivers clicks and typing inside your process (to your own windows, never through the system's input stream), only while your app is in front, and your customer can pause it.
  • No install, no service, nothing written to disk: the session ends when your app calls stop() or quits.

Install

// Package.swift
.package(url: "https://github.com/Gaia-Desk/gaiadesk-embed-swift.git", from: "0.4.0"),
// target:
.product(name: "GaiaDeskEmbed", package: "gaiadesk-embed-swift"),

SwiftPM downloads the native library (GaiaDeskEmbedFFI.xcframework) from this repository's release and checks it against the checksum in Package.swift. To build against a local copy (scripts/fetch-binary.sh 0.4.0 puts the release's in Frameworks/), set GAIADESK_EMBED_LOCAL_BINARY=1. Your app needs the Screen Recording permission (NSScreenCaptureUsageDescription is not required, but macOS asks the user the first time).

Quick start

Your backend creates a support session with a secret API key (scope support) and hands the app its embed_token; the session's mode (view or cobrowse) is your backend's choice:

curl -s -X POST https://api.gaiadesk.net/v1/support/sessions \
  -H "Authorization: Bearer $GAIADESK_API_KEY" -H "Content-Type: application/json" \
  -d '{"mode": "view", "customer": {"name": "Ada", "plan": "pro"}}'
# → {"id": "ss_…", "join_code": "123456789", "embed_token": "gdemb_…", …}

(A native app uses a token from its backend, never a publishable key: a key in a shipped binary is anyone's.)

import GaiaDeskEmbed

@MainActor func getHelp(token: String, window: NSWindow) {
    do {
        let decision = try GaiaDeskEmbed.consent(.init(company: "Acme", parentWindow: window, windowNumber: window.windowNumber))
        guard decision.decision == .accepted else { return }
        let help = try GaiaDeskEmbed.start(
            .init(embedToken: token, company: "Acme", windowNumber: window.windowNumber),
            consent: decision
        ) { event in
            switch event {
            case let .code(code, _, _): print("support code", code)   // read it to the agent
            case let .joined(agent): print(agent ?? "an agent", "is viewing")
            case let .ended(reason): print("ended:", reason)
            default: break
            }
        }
        try help.setMaskedViews([cardNumberField, passwordField])
        self.help = help
    } catch let e as GaiaDeskEmbedError {
        print("could not start:", e.code, e.message)
    } catch {}
}

The consent step

Use the library's consent step, consent(_:) (libgaiadesk_embed 0.4.0), rather than consentGranted: true after a dialog of your own. It gives you, with no UI to build:

  • a live preview of exactly what support will see, masked fields already black;
  • per-session choices for the customer: allow click-and-type or keep it view-only, share app logs, one window or the whole screen (each only when you offer it);
  • a consent receipt (who agreed to what, when, to which wording, hashed), stored on the support session and shown in the console;
  • wording localized into 14 languages (or your own), and an accessible dialog: keyboard only, Enter accepts, Esc declines, VoiceOver labels, reduced motion.
let decision = try GaiaDeskEmbed.consent(.init(
    company: "Acme", guided: true, masked: true, parentWindow: window,
    theme: .init(accent: "#0f766e", radius: 12),
    choices: .init(offerGuided: true, offerLogs: true),
    privacyURL: URL(string: "https://acme.example/privacy"),
    server: URL(string: "https://gaiadesk.net"), embedToken: token, sessionId: sessionId,
                                                 // all three: the library posts the receipt, shows who is waiting
    windowNumber: window.windowNumber, maskedRects: masks
)) { event in print(event) }                     // .consentShown, .consentAccepted / .consentDeclined
switch decision.decision {
case .accepted: help = try GaiaDeskEmbed.start(config, consent: decision) { event in /* … */ }
case .declined, .timeout: break                  // the receipt says so; the session leaves the queue
case .unavailable: break                         // no dialog here: ask with your own, then recordConsent
}

start(_:consent:onEvent:) sends the decision's consentToken and consentReceipt with the join and starts with what the customer chose (their capture; guided only if they allowed it). Main thread only (wrong_thread otherwise); refused options throw bad_config, never a decline. preview(_:) gives you the same picture (ConsentPreview: PNG Data, size, masked count) for a UI of your own; recordConsent(_:) turns your own UI's answer (ConsentAnswer: decision, choices, the strings you showed) into the same ConsentDecision and receipt. requestConsent still works as in 0.3.

Your support team opens Support in the GaiaDesk console, sees the waiting customer and joins (or types the nine-digit code).

Configuration

Field
embedToken gdemb_…, from your backend
company shown on the consent dialog and the indicator
server default https://gaiadesk.net
capture .window (default: windowNumber, or your frontmost window), .app (every window of your app), .screen (the whole display — opt-in)
guided false (default). true allows guided input in a cobrowse session
fps 1–30 (default 15)
maskedRects regions painted out from the first frame (see Masking)
brandColor "#RRGGBB", the indicator's accent (see Branding)
logoPNG your logo, PNG Data of at most 256 KiB (see Branding)
parentWindow the window asking for help; default your app's focused window (see The indicator)
indicatorPosition .topLeft, .topRight (default), .bottomLeft, .bottomRight
indicatorOrigin where the customer last dragged the indicator (see The indicator)
consentToken, consentReceipt from consent(_:) / recordConsent(_:); start(_:consent:onEvent:) sets both (0.4.0)

Branding

Your customer sees your brand, not ours: company on the consent dialog and the indicator, plus (libgaiadesk_embed 0.2.0) your colour and logo.

let logo = try Data(contentsOf: Bundle.main.url(forResource: "logo", withExtension: "png")!)
let brand = (color: "#0f766e", logo: logo)   // a PNG, at most 256 KiB

guard try GaiaDeskEmbed.requestConsent(.init(company: "Acme", brandColor: brand.color, logoPNG: brand.logo)) == true else { return }
help = try GaiaDeskEmbed.start(
    .init(embedToken: token, company: "Acme", windowNumber: window.windowNumber, brandColor: brand.color, logoPNG: brand.logo),
    consentGranted: true
) { event in /* … */ }

A colour that is not #RRGGBB throws GaiaDeskEmbedError (bad_config) before anything native runs; a logo the library refuses (not a PNG, over 256 KiB) throws bad_config from requestConsent(_:) or start, and is never read as a decline.

With libgaiadesk_embed 0.3.0, ConsentOptions also takes masked: true (the dialog says private fields stay hidden; pass the masks too) and parentWindow: the dialog is a sheet on that window, never behind it (default: your app's focused window). Without a logo it shows your app icon.

The indicator

(libgaiadesk_embed 0.3.0) The indicator starts top right, clear of parentWindow, or in the corner indicatorPosition names. Your customer can drag it; each drag sends .indicatorMoved(x:y:). The library writes nothing to disk, so keep the place yourself and pass it back as indicatorOrigin next time (restored while it fits on a screen):

case let .indicatorMoved(x, y): UserDefaults.standard.set([x, y], forKey: "helpIndicator")
// next start:
if let p = UserDefaults.standard.array(forKey: "helpIndicator") as? [Double], p.count == 2 {
    config.indicatorOrigin = CGPoint(x: p[0], y: p[1])
}

Until an agent is admitted the indicator offers Cancel: the request leaves your support team's queue at once and the session ends with customer_cancelled (as does stop() before an agent was admitted).

Masking

Pass the regions you already know in maskedRects when you start (rectInWindow(_:) turns a view into one): an agent can join straight away, and only start-time masks are guaranteed to cover the first frame. Afterwards, setMaskedViews(_:) takes views; setMaskedRects(_:) takes rects relative to the top-left of the shared window's frame, in points. Call again when your layout changes. If the window cannot be located, the whole picture is painted out rather than risk a leak.

Guided mode

Only when your app passes guided: true and your backend created the session as cobrowse. Then the agent's clicks, scrolling and typing are delivered to your app's own windows, inside your process, and only while your app is the active app; a click outside your windows, on the indicator or on a masked view is refused. Your customer pauses it with Pause control on the indicator (or you call setPaused(true)). Highlights are not supported natively.

Events

Event
.state(s) starting, waiting, connected, ended
.choices(_) right after .state("waiting"): the consent step's choices the session runs with (0.4.0)
.code(code, sessionId:, mode:) registered; code is what the agent joins with
.joined(agent:) / .left an agent joined / left
.control(allowed:) guided input paused or resumed
.action(_, applied:, reason:) a guided request and its outcome
.error(code:, message:) e.g. capture_failed, connect_failed, indicator_unavailable
.indicatorMoved(x:, y:) the customer dragged the indicator (keep it for indicatorOrigin; 0.3.0)
.ended(reason:) stopped (the customer), app_stopped, customer_cancelled (Cancel or stop() before an agent was admitted; 0.3.0), customer_declined / consent_timeout (the consent step said no or timed out; 0.4.0), disconnected, expired, error — always last

Events arrive on the main queue. consent(_:)'s handler gets .consentShown(locale:wordingVersion:), .consentAccepted(choices:) and .consentDeclined(reason:) (declined or timeout) before it returns.

Example

Examples/HelpDeskDemo is a small AppKit app with a Get help button and a masked card number:

GAIADESK_EMBED_TOKEN=gdemb_… swift run HelpDeskDemo

Links

Licence

The Swift sources here are MIT (LICENSE). The prebuilt libgaiadesk_embed binary is licensed under the GaiaDesk Native Binary Licence (LICENSE-BINARY): free to use in your apps, linked into them, unmodified.

About

In-app remote support for macOS apps: a "Get help" button that shares your app window with your support team, consent first, with masking and optional guided control. Screen sharing SDK for Swift (Swift Package Manager, ScreenCaptureKit).

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages