Skip to content

Commit

Permalink
Merge pull request #419 from salemove/Create-sample-integration-app
Browse files Browse the repository at this point in the history
Create example integration app
  • Loading branch information
rasmustautsglia authored Nov 25, 2022
2 parents 23d4225 + cd3955e commit ba77ef8
Show file tree
Hide file tree
Showing 15 changed files with 750 additions and 0 deletions.
455 changes: 455 additions & 0 deletions Example/Glia Sample Integration.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions Example/Glia Sample Integration/Appearance/Colors.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import SwiftUI

enum Colors {
static let gliaPurple = Color(red: 0.52, green: 0.11, blue: 0.92)
static let shadow = Color.black.opacity(0.3)
static let gray = Color(red: 0.4, green: 0.4, blue: 0.4)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"images" : [
{
"idiom" : "universal",
"platform" : "ios",
"size" : "1024x1024"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
6 changes: 6 additions & 0 deletions Example/Glia Sample Integration/Assets.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"images" : [
{
"filename" : "Glia.png",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"preserves-vector-representation" : true
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions Example/Glia Sample Integration/Delegate/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import SalemoveSDK
import SwiftUI

class AppDelegate: NSObject, UIApplicationDelegate {
private let gliaDelegate = GliaCore.AppDelegate()

func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil
) -> Bool {
gliaDelegate.application(application, didFinishLaunchingWithOptions: launchOptions)
return true
}

func application(
_ application: UIApplication,
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data
) {
GliaCore.sharedInstance.pushNotifications.application(application, didRegisterForRemoteNotificationsWithDeviceToken: deviceToken)
}

func applicationDidBecomeActive(_ application: UIApplication) {
gliaDelegate.applicationDidBecomeActive(application)
}
}
17 changes: 17 additions & 0 deletions Example/Glia Sample Integration/Extensions/GliaEnvironment.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import GliaWidgets
import SalemoveSDK

extension Environment {
var gliaCoreRegion: GliaCore.Region {
switch self {
case .europe:
return .eu
case .usa:
return .us
case .beta:
return .custom(URL(string: "https://api.beta.salemove.com")!)
case .custom(let url):
return .custom(url)
}
}
}
115 changes: 115 additions & 0 deletions Example/Glia Sample Integration/Presenters/ContentViewPresenter.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import GliaWidgets
import SalemoveSDK
import SwiftUI

class ContentViewPresenter: ObservableObject {
private let gliaConfiguration: GliaConfiguration
private var theme = Theme()
private var queue: Queue?

@Published var isVideoAvailable = false
@Published var isAudioAvailable = false
@Published var isChatAvailable = false

init() {
gliaConfiguration = GliaConfiguration()
theme = customizeTheme()

// To use any methods from iOS Core SDK (e.g. `GliaCore.listQueues`),
// you need to initialize `CoreSDK` separately with your site's credentials.
initializeCoreSDK {
GliaCore.sharedInstance.listQueues { [weak self] queues, error in
guard error == nil else {
print("Error has happened: \(error!.reason)")
return
}
let queue = queues?.first(where: { $0.id == self?.gliaConfiguration.queueId })
self?.queue = queue
self?.isVideoAvailable = queue?.isMediaTypeSupported(.video) ?? false
self?.isAudioAvailable = queue?.isMediaTypeSupported(.audio) ?? false
self?.isChatAvailable = queue?.isMediaTypeSupported(.text) ?? false
}
}
}

// Configure listening of Glia's events
private func eventListener() {
Glia.sharedInstance.onEvent = { event in
switch event {
case .started:
break
case .engagementChanged:
break
case .ended:
break
case .minimized:
break
case .maximized:
break
}
}
}

// Start the engagement of a desired `EngagementKind`.
func startEngagement(_ kind: EngagementKind) {
do {
try Glia.sharedInstance.start(
kind,
configuration: gliaConfiguration.composeConfiguration(),
queueID: gliaConfiguration.queueId,
visitorContext: nil,
theme: theme
)
} catch {
print("Error starting engagement")
}
}

// Configure Glia, for Core SDK.
private func initializeCoreSDK(completion: @escaping () -> Void) {
do {
let configuration = try GliaCore.Configuration(
siteId: gliaConfiguration.siteId,
region: gliaConfiguration.environment.gliaCoreRegion,
authorizingMethod: .siteApiKey(id: gliaConfiguration.siteApiId, secret: gliaConfiguration.siteApiSecret)
)

GliaCore.sharedInstance.configure(
with: configuration,
completion: completion
)
} catch {
print("Error has happened: \(error.localizedDescription)")
}
}

// Customize and apply Theme
private func customizeTheme() -> Theme {
let themeColors = ThemeColor(
primary: .init(Colors.gliaPurple),
baseLight: .white,
baseDark: .init(Colors.gray),
systemNegative: .systemPink
)
let colorStyle = ThemeColorStyle.custom(themeColors)

theme = Theme(
colorStyle: colorStyle,
fontStyle: .default,
showsPoweredBy: true
)
theme.chat.backgroundColor = .white
theme.minimizedBubble.badge?.backgroundColor = .systemPink
theme.minimizedBubble.badge?.fontColor = .white
theme.minimizedBubble.badge?.font = .systemFont(ofSize: 14)

return theme
}
}

// Check if the desired queue is open and available for a certain media.
private extension SalemoveSDK.Queue {
func isMediaTypeSupported(_ mediaType: MediaType) -> Bool {
state.status == .open && state.media.contains(mediaType)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import SwiftUI

struct IsAvailable: ViewModifier {
let isAvailable: Bool

init(_ isAvailable: Bool) {
self.isAvailable = isAvailable
}

func body(content: Content) -> some View {
content
.disabled(!isAvailable)
.opacity(isAvailable ? 1 : 0.5)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import SwiftUI

struct EngagementButtonStyle: ButtonStyle {
func makeBody(configuration: Configuration) -> some View {
configuration.label
.foregroundColor(.white)
.font(.headline.weight(.regular))
.padding(.vertical, 12)
.padding(.horizontal)
.frame(maxWidth: .infinity)
.background(Colors.gliaPurple)
.clipShape(
RoundedRectangle(cornerRadius: 12, style: .continuous)
)
.shadow(color: Colors.shadow, radius: 16, x: 0, y: 0)
.padding(.horizontal, 32)
}
}
35 changes: 35 additions & 0 deletions Example/Glia Sample Integration/Views/ContentView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import SwiftUI

struct ContentView: View {
@ObservedObject var presenter = ContentViewPresenter()

var body: some View {
VStack(spacing: 16){
Image("Glia")
.resizable()
.aspectRatio(contentMode: .fit)
.padding(80)

Spacer()

Button("Chat") {
presenter.startEngagement(.chat)
}
.buttonStyle(EngagementButtonStyle())
.modifier(IsAvailable(presenter.isChatAvailable))

Button("Audio Call") {
presenter.startEngagement(.audioCall)
}
.buttonStyle(EngagementButtonStyle())
.modifier(IsAvailable(presenter.isAudioAvailable))

Button("Video Call") {
presenter.startEngagement(.videoCall)
}
.buttonStyle(EngagementButtonStyle())
.modifier(IsAvailable(presenter.isVideoAvailable))
}
.padding(.vertical, 48)
}
}
12 changes: 12 additions & 0 deletions Example/Glia Sample Integration/Views/RootView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import SwiftUI

@main
struct GliaSampleIntegrationApp: App {
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate

var body: some Scene {
WindowGroup {
ContentView()
}
}
}

0 comments on commit ba77ef8

Please sign in to comment.