-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #419 from salemove/Create-sample-integration-app
Create example integration app
- Loading branch information
Showing
15 changed files
with
750 additions
and
0 deletions.
There are no files selected for viewing
455 changes: 455 additions & 0 deletions
455
Example/Glia Sample Integration.xcodeproj/project.pbxproj
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
11 changes: 11 additions & 0 deletions
11
Example/Glia Sample Integration/Assets.xcassets/AccentColor.colorset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"colors" : [ | ||
{ | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
Example/Glia Sample Integration/Assets.xcassets/AppIcon.appiconset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
6
Example/Glia Sample Integration/Assets.xcassets/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
Example/Glia Sample Integration/Assets.xcassets/Glia.imageset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
Binary file added
BIN
+29.5 KB
Example/Glia Sample Integration/Assets.xcassets/Glia.imageset/Glia.png
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
25
Example/Glia Sample Integration/Delegate/AppDelegate.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
17
Example/Glia Sample Integration/Extensions/GliaEnvironment.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
115
Example/Glia Sample Integration/Presenters/ContentViewPresenter.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
Example/Glia Sample Integration/Preview Content/Preview Assets.xcassets/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
Example/Glia Sample Integration/ViewModifiers/AvailabilityModifier.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
Example/Glia Sample Integration/ViewModifiers/EngagementButtonStyle.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} | ||
} |