Skip to content
This repository was archived by the owner on Aug 25, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
244 commits
Select commit Hold shift + click to select a range
8d96392
add isDisabled flag for username tokens
cjmconie Feb 18, 2019
4d29671
username as a token type
cjmconie Feb 18, 2019
2be16ac
add username update and disable endpoints
cjmconie Feb 18, 2019
ec01b57
add username as a transfer option
cjmconie Feb 18, 2019
01cae94
Merge branch 'master' into core/feature/username
cjmconie Feb 18, 2019
46ec748
Add Result type from Swift
cjmconie Mar 12, 2019
99996d2
Merge pull request #178 from BLOCKvIO/core/feature/result-type
cjmconie Mar 12, 2019
e57219f
Add didSelectFaceView and didLoadFaceView methods
cjmconie Mar 20, 2019
01c8786
Support didSelectFaceView and didLoadFaceView
cjmconie Mar 20, 2019
1874738
Convert to result type completion
cjmconie Mar 20, 2019
5f911aa
Allow delegate propagation on init
cjmconie Mar 20, 2019
bf72690
Add result type
cjmconie Mar 20, 2019
74b956d
Fix typos
cjmconie Mar 20, 2019
cf9df9f
Update to result type delegate
cjmconie Mar 20, 2019
0811807
lint
cjmconie Mar 20, 2019
2063ea1
Merge pull request #179 from BLOCKvIO/face/fix/typos
cjmconie Mar 22, 2019
231a5ef
Merge pull request #180 from BLOCKvIO/face/fix/vatom-view-lifecycle
cjmconie Mar 25, 2019
5c09a4d
Constrain Starscream to 3.0.6
cjmconie Mar 26, 2019
78a915b
Convert hasValue to hash(into:)
cjmconie Mar 26, 2019
1a4f18a
Lint
cjmconie Mar 26, 2019
533f757
Merge pull request #181 from BLOCKvIO/core/fix-issues
cjmconie Mar 26, 2019
f5e7005
Add basic action support
cjmconie Mar 28, 2019
8544cdf
Rename file
cjmconie Mar 28, 2019
c516575
Add convenience clone and redeem funcitons
cjmconie Mar 28, 2019
d26aab0
Shift extensions to new file
cjmconie Mar 28, 2019
f29c9fa
Merge pull request #182 from BLOCKvIO/sample/feature/basic-actions
cjmconie Mar 28, 2019
eb595b7
Fix error handling
cjmconie Mar 28, 2019
25c90d7
Merge pull request #183 from BLOCKvIO/fix/sample/action-completion
cjmconie Mar 29, 2019
68de976
Core: Feature - Data pool (#185)
cjmconie Apr 2, 2019
f6d9dee
Core: Feature - Client updates (#184)
cjmconie Apr 2, 2019
1d7afd9
Integrate data pool into session launch
cjmconie Apr 3, 2019
cc4d5ab
Call onLogin in auth requests
cjmconie Apr 3, 2019
4ba646a
Clean up
cjmconie Apr 3, 2019
f5dc902
Remove uneccessary pods
cjmconie Apr 3, 2019
e625a3b
Update UI
cjmconie Apr 3, 2019
c0d1eb2
Add available actions
cjmconie Apr 3, 2019
ca7deb8
Update actions to call into data pool
cjmconie Apr 3, 2019
88d18df
Add confirm alert
cjmconie Apr 3, 2019
89c3c1b
Add orange color
cjmconie Apr 3, 2019
3936897
Merge pull request #186 from BLOCKvIO/core/feature/data-pool-creation
cjmconie Apr 3, 2019
a37027a
Merge pull request #188 from BLOCKvIO/sample/feature/action-sheet
cjmconie Apr 3, 2019
efd0e13
Merge pull request #187 from BLOCKvIO/core/fix/pod-cleanup
cjmconie Apr 3, 2019
fbd19f2
Add preemptive actions
cjmconie Apr 3, 2019
c521dfd
Remove import
cjmconie Apr 3, 2019
7675abd
Merge pull request #189 from BLOCKvIO/core/feature/preemptive-actions
cjmconie Apr 3, 2019
d849b3a
Remove old actions
cjmconie Apr 5, 2019
6b57e56
Merge pull request #190 from BLOCKvIO/core/fix/action
cjmconie Apr 5, 2019
33937d9
Response json overlay
cjmconie Apr 5, 2019
ae47129
Use responseJSON method
cjmconie Apr 5, 2019
7063e3e
Lint
cjmconie Apr 5, 2019
3792164
Add raw vatom patch
cjmconie Apr 5, 2019
2de5960
Merge pull request #191 from BLOCKvIO/core/fix/vatom-patch
cjmconie Apr 5, 2019
f9cee10
Parse response on concurrent queue
cjmconie Apr 9, 2019
7e4fceb
Merge pull request #193 from BLOCKvIO/core/fix/data-pool-issues
cjmconie Apr 10, 2019
989db80
Add VatomChildRegion.swift
cjmconie Apr 10, 2019
77ebb04
Update ids to use class variables
cjmconie Apr 10, 2019
2fd3b15
Merge pull request #194 from BLOCKvIO/core/feature/child-region
cjmconie Apr 10, 2019
322e4c7
Improve safety
cjmconie Apr 11, 2019
01d86f4
Add unpacked payload parsing
cjmconie Apr 11, 2019
7dfc34a
Leverage superclass parse function
cjmconie Apr 11, 2019
478517a
Add VatomIDRegion.swift
cjmconie Apr 11, 2019
77761c2
Comment clean up
cjmconie Apr 11, 2019
430d49b
User descriptor initialization
cjmconie Apr 11, 2019
b1eaa33
Elevate access control
cjmconie Apr 11, 2019
42b29d0
Descriptor initialiser
cjmconie Apr 11, 2019
0093105
Use Result type for completion handlers
cjmconie Apr 11, 2019
6d1c83a
Wrap result completion with promise
cjmconie Apr 11, 2019
8492aa6
Merge pull request #195 from BLOCKvIO/core/fix/data-pool-improvements
cjmconie Apr 11, 2019
fe1aa84
Merge branch 'dev-open-viewer' into core/fix/vatom-descriptable
cjmconie Apr 11, 2019
e7a7630
Merge pull request #196 from BLOCKvIO/core/feature/use-result
cjmconie Apr 11, 2019
393cac4
Core: Feature - Vatom containment (#192)
cjmconie Apr 13, 2019
de4639e
Fix naming
cjmconie Apr 13, 2019
064db8c
Core: Feature - Expose endpoint generic constructors (#198)
cjmconie Apr 15, 2019
867ea28
Core: Feature - Native bridge 2.1 (#199)
cjmconie Apr 15, 2019
b7dc5dd
Sample: Fix - Result type (#197)
cjmconie Apr 15, 2019
35bf5ec
Core: Feature - Native bridge result (#200)
cjmconie Apr 15, 2019
76fa5f1
Apply linter (#201)
cjmconie Apr 15, 2019
d79eb98
Face: Fix- Data pool integration (#202)
cjmconie Apr 15, 2019
2e8c247
Merge branch 'dev-open-viewer' into core/fix/vatom-descriptable
cjmconie Apr 15, 2019
c1bb4d0
Add missing this.id parameter
cjmconie Apr 15, 2019
4b91300
Merge pull request #203 from BLOCKvIO/core/fix/drop
cjmconie Apr 15, 2019
5a9b047
Help complier with type
cjmconie Apr 15, 2019
3d7c84b
Merge pull request #204 from BLOCKvIO/core/fix/drop-2
cjmconie Apr 15, 2019
559f321
Update: Migrate to Swift 5.0 (#205)
cjmconie Apr 15, 2019
d2cc30a
Move completion handling to main queue
cjmconie Apr 17, 2019
79a7dee
Merge pull request #206 from BLOCKvIO/core/fix/request-queue
cjmconie Apr 17, 2019
cd5c73f
Remove debouncer
cjmconie Apr 17, 2019
a7c986f
Convert load from a taking a closure to taking no arguments. Instead,…
cjmconie Apr 17, 2019
b9a381b
Adopt standard pattern
cjmconie Apr 17, 2019
96e5728
Adopt standard pattern
cjmconie Apr 17, 2019
e53ee3b
Improve documentation
cjmconie Apr 17, 2019
354405a
Remove debouncer
cjmconie Apr 17, 2019
75b9c47
Update load completion
cjmconie Apr 17, 2019
3a323cc
Fix stray comment
cjmconie Apr 17, 2019
4b9d22b
Call UI update once
cjmconie Apr 17, 2019
e54ec16
Merge pull request #207 from BLOCKvIO/face/fix/face-view-lifecycle
cjmconie Apr 17, 2019
5c31e3e
Move roll back onto main queue
cjmconie Apr 18, 2019
570e942
Merge pull request #208 from BLOCKvIO/core/fix/threading
cjmconie Apr 18, 2019
ee3a86b
Core: Feature - Geopos region (#209)
cjmconie Apr 18, 2019
0d1d02f
Improve message handling
cjmconie Apr 28, 2019
facf4d0
Expose groups
cjmconie Apr 28, 2019
d454c84
Add acquire pub variation convenience actinon
cjmconie Apr 28, 2019
31182a4
Add gif support to error view
cjmconie Apr 28, 2019
ac69d9c
fix missing common setup path
cjmconie Apr 28, 2019
8ef71d2
Lint
cjmconie Apr 28, 2019
ed8df7c
Set deployment target as 11.0
cjmconie Apr 28, 2019
06510a0
Merge pull request #213 from BLOCKvIO/core/update-podspec
cjmconie Apr 29, 2019
7b435b6
Merge pull request #212 from BLOCKvIO/face/vatom-view-fixes
cjmconie Apr 29, 2019
24345b6
Merge pull request #211 from BLOCKvIO/core/feature/map-support
cjmconie Apr 29, 2019
5e41a5e
Core: Feature - OAuth (#210)
cjmconie Apr 29, 2019
668fc74
Invoke viewer's logout closure
cjmconie Apr 30, 2019
c2683e9
Merge pull request #214 from BLOCKvIO/core/fix/logout
cjmconie Apr 30, 2019
0205273
Core: Fix - OAuth V2 (#215)
cjmconie Apr 30, 2019
6ce108c
Merge branch 'dev-open-viewer' into core/fix/vatom-descriptable
cjmconie Apr 30, 2019
70a5e2c
Add member-wise initializers to vatom, face, and action
cjmconie Apr 30, 2019
78c5c34
Fix folder containment
cjmconie May 1, 2019
b3ccedd
Fix action name
cjmconie May 1, 2019
219a48f
Merge pull request #217 from BLOCKvIO/core/fix/issues
cjmconie May 2, 2019
36b4fc1
Fix issue with reuse pool where the vatom of the error view was not u…
cjmconie May 2, 2019
29ba500
Merge pull request #218 from BLOCKvIO/face/fix/perf-issues
cjmconie May 2, 2019
8487f8e
Add image scaling to lower memory impact
cjmconie May 2, 2019
ad306a2
Merge pull request #219 from BLOCKvIO/face/fix/image-scaling
cjmconie May 2, 2019
60b989c
Remove redundant assignment
cjmconie May 2, 2019
2902abc
Merge pull request #220 from BLOCKvIO/face/fix/error-view
cjmconie May 2, 2019
1c3bedc
Merge branch 'dev-open-viewer' into core/fix/vatom-descriptable
cjmconie May 2, 2019
b8cb447
Fix child template variation filter
cjmconie May 15, 2019
caa5165
Merge pull request #221 from BLOCKvIO/core/fix/vatom-containment
cjmconie May 16, 2019
545dfa1
Add view reuse for vatom-view with matching face model and vatom temp…
cjmconie May 16, 2019
5ac061f
Lint
cjmconie May 16, 2019
b2dd9e0
remove comment
cjmconie May 16, 2019
77a18f1
Merge pull request #222 from BLOCKvIO/core/fix/vatom-view-reuse-pool
cjmconie May 16, 2019
a62a8af
Add AppUpdateModel
cjmconie May 17, 2019
88f9877
Expose getSupportedVersion endpoint
cjmconie May 17, 2019
3874a10
Merge pull request #223 from BLOCKvIO/core/feature/app-version-support
cjmconie May 17, 2019
4209d7b
Add push token endpoint
cjmconie May 22, 2019
91f9ce3
Merge pull request #224 from BLOCKvIO/feature/push-notification-endpoint
cjmconie May 23, 2019
5a1de88
Fix caching policy
cjmconie May 23, 2019
ade4aaa
Merge pull request #225 from BLOCKvIO/fix/web-face-cache
cjmconie May 23, 2019
7b36ab3
Ensure load completion is executed on the main queue
cjmconie May 23, 2019
7f9e118
Merge branch 'dev-open-viewer' into core/fix/vatom-descriptable
cjmconie May 23, 2019
0826692
Merge pull request #226 from BLOCKvIO/fix/face/vvlc-load-queue
cjmconie May 23, 2019
1d56f13
Set padding to remove border
cjmconie May 24, 2019
5bb7151
Add nonpushNotification property
cjmconie May 24, 2019
c4c2f36
Merge pull request #227 from BLOCKvIO/core/fix/oauth-border
cjmconie May 24, 2019
ef4debd
Merge pull request #228 from BLOCKvIO/core/fix/nonpush-notification
cjmconie May 24, 2019
09aec43
Add reason associated value
cjmconie May 26, 2019
9c582f1
Fix crash were selected face view was nil
cjmconie May 26, 2019
2a2ad58
Fix safe area content behaviour
cjmconie May 26, 2019
a9a4e58
Merge pull request #229 from BLOCKvIO/face/fix/web-view-content-behav…
cjmconie May 27, 2019
0c74582
Merge pull request #230 from BLOCKvIO/core/fix/vatom-view-vvlc
cjmconie May 27, 2019
8f402fc
Comment out print statement
cjmconie May 28, 2019
2de1157
Merge pull request #231 from BLOCKvIO/face/fix/stray-print
cjmconie May 28, 2019
7bc1113
Improve page fetching
cjmconie May 28, 2019
79cde02
Add region error
cjmconie May 28, 2019
b364d55
Add region error
cjmconie May 28, 2019
d33a4e0
Fix spelling
cjmconie May 28, 2019
3537641
Merge pull request #232 from BLOCKvIO/core/fix/inventory-fetch
cjmconie May 28, 2019
bcea506
Minor clean up and refactor
cjmconie May 28, 2019
f2ea9bc
Merge pull request #233 from BLOCKvIO/core/fix/region-refactor
cjmconie May 28, 2019
85f65c4
Add io serial queue to perform disk io tasks
cjmconie May 28, 2019
8e0b3e9
Merge pull request #234 from BLOCKvIO/core/fix/io-queue
cjmconie May 29, 2019
2787b64
Re-connect to the socket on session launch
cjmconie May 30, 2019
7bd7bae
Merge pull request #236 from BLOCKvIO/core/fix/web-socket-connect
cjmconie May 31, 2019
6e79906
Add write ping
cjmconie Jun 5, 2019
b27b244
Add debug HUD
cjmconie Jun 5, 2019
9cb3088
Lint
cjmconie Jun 5, 2019
01d6236
Merge pull request #237 from BLOCKvIO/core/feature/degub-hud
cjmconie Jun 5, 2019
4fd04f3
Create a BoundedView to inform its subclass once the bounds have been…
cjmconie Jun 5, 2019
87496bd
Update cacheKey to include the target size
cjmconie Jun 5, 2019
fd6270a
Add extension to generate a cache key
cjmconie Jun 5, 2019
8f5bca6
Use `generateCacheKey(url:targetSize:)` function
cjmconie Jun 5, 2019
f487bb9
Merge pull request #238 from BLOCKvIO/face/fix/cache-target-size
cjmconie Jun 5, 2019
ce639c3
Fix increment of processed page count
cjmconie Jun 5, 2019
7f40ed4
Add source key pair to better inform the listen of the source of the …
cjmconie Jun 6, 2019
5ba1b7f
Merge pull request #239 from BLOCKvIO/core/fix/region-max-page
cjmconie Jun 6, 2019
7ad0b4b
Merge pull request #240 from BLOCKvIO/core/fix/region-update-source
cjmconie Jun 6, 2019
90156f0
Fix transformation and encoding issue preventing ui.qr.scan in v1 of …
cjmconie Jun 7, 2019
a5adf50
Merge pull request #241 from BLOCKvIO/face/fix/custom-qr-scan-message
cjmconie Jun 8, 2019
216b41a
Add pixelSize property to UIImageView
cjmconie Jun 8, 2019
bd95b0b
Make FaceView a subclass of BoundedView
cjmconie Jun 8, 2019
8c57d05
Update to use bounded view lifecycle
cjmconie Jun 8, 2019
e626c46
Merge pull request #242 from BLOCKvIO/face/fix/image-target-size
cjmconie Jun 10, 2019
982adca
Merge branch 'dev-open-viewer' into core/fix/vatom-descriptable
cjmconie Jun 11, 2019
40c1db6
Auto reconnect the socket after an unintentional disconnect
cjmconie Jun 11, 2019
c5a1968
Add delay options
cjmconie Jun 12, 2019
46226c3
Update to use delay options
cjmconie Jun 12, 2019
a3488e2
Merge pull request #243 from BLOCKvIO/core/feature/web-socket-auto-re…
cjmconie Jun 12, 2019
299f663
Add support for bridge 2.1 core.user.current.get
cjmconie Jun 12, 2019
3b4d6f8
Merge dev-open-viewer into core/feature/vatom-descriptable
cjmconie Jun 13, 2019
afcb537
Remove comment
cjmconie Jun 13, 2019
6877ca8
Merge pull request #216 from BLOCKvIO/core/fix/vatom-descriptable
cjmconie Jun 13, 2019
d604694
Merge branch 'dev-open-viewer' into core/feature/bridge-2.1/user-curr…
cjmconie Jun 13, 2019
54243ac
Merge pull request #244 from BLOCKvIO/core/feature/bridge-2.1/user-cu…
cjmconie Jun 13, 2019
9bea286
Fix key look-up
cjmconie Jun 14, 2019
556b966
Merge pull request #246 from BLOCKvIO/core/fix/member-wise-init-root-…
cjmconie Jun 14, 2019
b5e30a4
Explicitly set sharedUrlCache capacities
cjmconie Jun 18, 2019
d4dd597
Merge pull request #247 from BLOCKvIO/core/fix/nuke-http-cache
cjmconie Jun 20, 2019
86a5f3c
Add 1604 error message
cjmconie Jun 20, 2019
1cd2fcd
Merge pull request #248 from BLOCKvIO/core/fix/add-1604-error
cjmconie Jun 21, 2019
6d90d05
Update error bindings
cjmconie Jun 27, 2019
59f3bbe
Fix typo
cjmconie Jun 27, 2019
25b70b4
Pin GenericJSON to 2.0
cjmconie Jul 8, 2019
2747e91
Fix migration issues
cjmconie Jul 8, 2019
27ffcaa
Merge pull request #249 from BLOCKvIO/core/fix/error-bindings
cjmconie Jul 8, 2019
9c642b6
Merge pull request #250 from BLOCKvIO/core/fix/generic-json
cjmconie Jul 8, 2019
cc9b3c4
Add root props lookup for cloning_score and num_direct_clones
cjmconie Jul 8, 2019
123095e
Merge pull request #251 from BLOCKvIO/fix/image-policy-face
cjmconie Jul 8, 2019
5507748
added accounds api call
MalcolmnDEV Jul 14, 2019
7553554
added docs
MalcolmnDEV Jul 14, 2019
c39dd04
Update AddressAccountModel.swift
MalcolmnDEV Jul 14, 2019
c78919a
Update AddressAccountModel.swift
MalcolmnDEV Jul 15, 2019
c06e21d
update model
MalcolmnDEV Jul 15, 2019
a3f623d
adjust access control to open
cjmconie Jul 15, 2019
076dad4
Merge pull request #253 from BLOCKvIO/fix/expose-bounded-view
cjmconie Jul 17, 2019
2c617cd
added unit tests forr address accounts model
MalcolmnDEV Jul 19, 2019
8f7f641
Update project.pbxproj
MalcolmnDEV Jul 19, 2019
62cf97c
Add sync
cjmconie Jul 19, 2019
467d08b
Update AddressAccountModel.swift
MalcolmnDEV Jul 19, 2019
ae47f28
Merge pull request #252 from BLOCKvIO/feature/eth-address
MalcolmnDEV Jul 19, 2019
b758ec9
Merge branch 'dev-open-viewer' into core/feature/inventory-hash
cjmconie Jul 19, 2019
d34b8fb
Merge pull request #254 from BLOCKvIO/core/feature/inventory-hash
cjmconie Jul 19, 2019
dac850b
Fix spelling
cjmconie Jul 22, 2019
4483f16
Add WSMapEvent
cjmconie Jul 22, 2019
0de1605
Observer map event updates
cjmconie Jul 22, 2019
245fe39
Fix linter issues
cjmconie Jul 23, 2019
9b2ce92
Merge branch 'fix/linter' into core/feature/websocket-map-update
cjmconie Jul 23, 2019
997421e
Add map event unit test
cjmconie Jul 23, 2019
af0da73
Merge pull request #255 from BLOCKvIO/fix/linter
cjmconie Jul 23, 2019
35aae28
Remove example payload
cjmconie Jul 23, 2019
295d50c
Merge pull request #256 from BLOCKvIO/core/feature/websocket-map-update
cjmconie Jul 23, 2019
7cf2ba6
Add resource downloader
cjmconie Jul 24, 2019
a9e6f53
Add md5 hash extension
cjmconie Jul 24, 2019
b4d0974
Clean up and docs
cjmconie Jul 24, 2019
ac8518d
Add data downloader
cjmconie Jul 26, 2019
837e5ce
Remove file
cjmconie Jul 26, 2019
a53efe5
Fix docs
cjmconie Jul 26, 2019
0a440f0
Merge pull request #257 from BLOCKvIO/face/feature/resource-cache
cjmconie Jul 26, 2019
e81a0e7
Extensions to compute allocated size of directory
cjmconie Jul 29, 2019
3e66e95
Extract useful properties
cjmconie Jul 29, 2019
7f1c580
Add recommended cache directory property
cjmconie Jul 29, 2019
bcbd29a
Add debug section
cjmconie Jul 29, 2019
7099556
Fix docs
cjmconie Jul 30, 2019
8d54e71
Merge pull request #258 from BLOCKvIO/core/debug-tools
cjmconie Jul 30, 2019
5d4f98f
Merge branch 'dev-open-viewer' into core/feature/username
cjmconie Jul 30, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions BLOCKv.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,19 @@ Pod::Spec.new do |s|
s.author = { 'BLOCKv' => 'developer.blockv.io' }
s.source = { :git => 'https://github.com/BLOCKvIO/ios-sdk.git', :tag => s.version.to_s }
s.social_media_url = 'https://twitter.com/blockv_io'
s.ios.deployment_target = '10.0'
s.swift_version = '4.2'
s.ios.deployment_target = '11.0'
s.swift_version = '5.0'
s.default_subspecs = 'Face'

s.subspec 'Core' do |s|
s.source_files = 'BlockV/Core/**/*.{swift}'
s.dependency 'Alamofire', '~> 4.7' # Networking
s.dependency 'Starscream', '~> 3.0' # Web socket
s.dependency 'JWTDecode', '~> 2.1' # JWT decoding
s.dependency 'Signals', '~> 6.0' # Elegant eventing
s.dependency 'SwiftLint', '~> 0.26' # Linter
s.dependency 'GenericJSON', '~> 1.2' # JSON
s.dependency 'Alamofire', '~> 4.7' # Networking
s.dependency 'Starscream', '~> 3.0.6' # Web socket
s.dependency 'JWTDecode', '~> 2.1' # JWT decoding
s.dependency 'Signals', '~> 6.0' # Elegant eventing
s.dependency 'SwiftLint', '~> 0.26' # Linter
s.dependency 'GenericJSON', '~> 2.0' # JSON
s.dependency 'PromiseKit', '~> 6.8' # Promises
#s.exclude_files = '**/Info*.plist'
end

Expand Down
152 changes: 112 additions & 40 deletions BlockV/Core/BLOCKv.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
import Foundation
import Alamofire
import JWTDecode
import Nuke

/*
Goal:
BLOCKv should be invariant over App ID and Environment. In other words, the properties should
BLOCKv should be invariant over App ID and Environment. In other words, the properties should not
change, once set. Possibly targets for each environemnt?
*/

Expand All @@ -27,7 +28,7 @@ public final class BLOCKv {
/// The App ID to be passed to the BLOCKv platform.
///
/// Must be set once by the host app.
fileprivate static var appID: String? {
internal fileprivate(set) static var appID: String? {
// willSet is only called outside of the initialisation context, i.e.
// setting the appID after its init will cause a fatal error.
willSet {
Expand All @@ -42,7 +43,7 @@ public final class BLOCKv {
/// The BLOCKv platform environment to use.
///
/// Must be set by the host app.
fileprivate static var environment: BVEnvironment? {
internal fileprivate(set) static var environment: BVEnvironment? {
willSet {
if environment != nil { reset() }
}
Expand All @@ -60,31 +61,6 @@ public final class BLOCKv {
public static func configure(appID: String) {
self.appID = appID

// NOTE: Since `configure` is called only once in the app's lifecycle. We do not
// need to worry about multiple registrations.
NotificationCenter.default.addObserver(BLOCKv.self,
selector: #selector(handleUserAuthorisationRequired),
name: Notification.Name.BVInternal.UserAuthorizationRequried,
object: nil)
}

// MARK: - Client

// FIXME: Should this be nil on logout?
// FIXME: This MUST become a singleton (since only a single instance should ever exist).
private static let oauthHandler = OAuth2Handler(appID: BLOCKv.appID!,
baseURLString: BLOCKv.environment!.apiServerURLString,
refreshToken: CredentialStore.refreshToken?.token ?? "")

/// Computes the configuration object needed to initialise clients and sockets.
fileprivate static var clientConfiguration: Client.Configuration {
// ensure host app has set an app id
let warning = """
Please call 'BLOCKv.configure(appID:)' with your issued app ID before making network
requests.
"""
precondition(BLOCKv.appID != nil, warning)

// - CONFIGURE ENVIRONMENT

// only modify if not set
Expand Down Expand Up @@ -117,6 +93,44 @@ public final class BLOCKv {

}

// NOTE: Since `configure` is called only once in the app's lifecycle. We do not
// need to worry about multiple registrations.
NotificationCenter.default.addObserver(BLOCKv.self,
selector: #selector(handleUserAuthorisationRequired),
name: Notification.Name.BVInternal.UserAuthorizationRequried,
object: nil)

// configure in-memory cache (store processed images ready for display)
ImageCache.shared.costLimit = ImageCache.defaultCostLimit()

// configure http cache (store unprocessed image data at the http level)
DataLoader.sharedUrlCache.memoryCapacity = 80 * 1024 * 1024 // 80 MB
DataLoader.sharedUrlCache.diskCapacity = 180 // 180 MB

// handle session launch
if self.isLoggedIn {
self.onSessionLaunch()
}

}

// MARK: - Client

// FIXME: Should this be nil on logout?
// FIXME: This MUST become a singleton (since only a single instance should ever exist).
private static let oauthHandler = OAuth2Handler(appID: BLOCKv.appID!,
baseURLString: BLOCKv.environment!.apiServerURLString,
refreshToken: CredentialStore.refreshToken?.token ?? "")

/// Computes the configuration object needed to initialise clients and sockets.
fileprivate static var clientConfiguration: Client.Configuration {
// ensure host app has set an app id
let warning = """
Please call 'BLOCKv.configure(appID:)' with your issued app ID before making network
requests.
"""
precondition(BLOCKv.appID != nil, warning)

// return the configuration (inexpensive object)
return Client.Configuration(baseURLString: BLOCKv.environment!.apiServerURLString,
appID: BLOCKv.appID!)
Expand Down Expand Up @@ -171,7 +185,7 @@ public final class BLOCKv {
fileprivate static var _socket: WebSocketManager?

//TODO: What if this is accessed before the client is accessed?
//TODO: What if the viewer suscribes to an event before auth (login/reg) has occured?
//TODO: What if the viewer subscribes to an event before auth (login/reg) has occured?
public static var socket: WebSocketManager {
if _socket == nil {
_socket = WebSocketManager(baseURLString: self.environment!.webSocketURLString,
Expand All @@ -194,8 +208,10 @@ public final class BLOCKv {
// disconnect and nil out socekt
self._socket?.disconnect()
self._socket = nil
// clear data pool
DataPool.clear()

printBV(info: "Reset")
printBV(info: "Reseting SDK")
}

// - Public Lifecycle
Expand Down Expand Up @@ -223,10 +239,10 @@ public final class BLOCKv {
BLOCKv.client.getAccessToken(completion: completion)
}

/// Called when the networking client detects the user is unathorized.
/// Called when the networking client detects the user is unauthenticated.
///
/// This method perfroms a clean up operation before notifying the viewer that the SDK requires
/// user authorization.
/// user authentication.
///
/// - important: This method may be called multiple times. For example, consider the case where
/// multiple requests fail due to the refresh token being invalid.
Expand All @@ -245,20 +261,50 @@ public final class BLOCKv {

}

/// Called when the user authenticates (logs in).
///
/// - important:
/// This method is *not* called when the access token refreshes.
static internal func onLogin() {

// stand up the session
self.onSessionLaunch()

}

/// Holds a closure to call on logout
public static var onLogout: (() -> Void)?

/// Sets the BLOCKv platform environment.
/// This function is called everytime a user session is launched.
///
/// By setting the environment you are informing the SDK which BLOCKv
/// platform environment to interact with.
/// A 'session launch' means the user has logged in (received a new refresh token), or the app has been cold
/// launched with an existing *valid* refresh token.
///
/// Typically, you would call `setEnvironment` in `application(_:didFinishLaunchingWithOptions:)`.
@available(*, deprecated, message: "BLOCKv now defaults to production. You may remove this call.")
public static func setEnvironment(_ environment: BVEnvironment) {
self.environment = environment
/// - note:
/// This is slightly broader than 'log in' since it includes the lifecycle of the app. This function is responsible
/// for creating objects which are depenedent on a user session, e.g. data pool.
///
/// Its compainion `onSessionTerminated` is `onLogout` since there is no app event signalling app termination.
///
/// Triggered by:
/// - User authentication
/// - App launch & user is authenticated
static private func onSessionLaunch() {

guard let refreshToken = CredentialStore.refreshToken?.token else {
fatalError("Invlalid session")
}

guard let claim = try? decode(jwt: refreshToken).claim(name: "user_id"), let userId = claim.string else {
fatalError("Invalid cliam")
}

// standup the client & socket
_ = client
_ = socket.connect()

//FIXME: *Changing* the environment should nil out the client and access credentials.
// standup data pool
DataPool.sessionInfo = ["userID": userId]

}

Expand Down Expand Up @@ -304,3 +350,29 @@ func printBV(info string: String) {
func printBV(error string: String) {
print("\nBV SDK >>> Error: \(string)")
}

extension BLOCKv {

public enum Debug {

//// Returns the cache size of the face data resource disk caches.
public static var faceDataResourceCacheSize: UInt64? {
return try? FileManager.default.allocatedSizeOfDirectory(at: DataDownloader.recommendedCacheDirectory)
}

/// Returns the cache size of all data pool region disk caches.
public static var regionCacheSize: UInt64? {
return try? FileManager.default.allocatedSizeOfDirectory(at: Region.recommendedCacheDirectory)
}

/// Clears all disk caches.
public static func clearCache() {
ImageCache.shared.removeAll()
DataLoader.sharedUrlCache.removeAllCachedResponses()
try? FileManager.default.removeItem(at: DataDownloader.recommendedCacheDirectory)
try? FileManager.default.removeItem(at: Region.recommendedCacheDirectory)
}

}

}
7 changes: 7 additions & 0 deletions BlockV/Core/BVEnvironment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,11 @@ public enum BVEnvironment: String {
}
}

var oauthWebApp: String {
switch self {
case .production: return "https://login.blockv.io"
case .development: return "https:/login.blockv.net"
}
}

}
Loading