Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
Elixxir dApps SDK Swift
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mobile
iOS
Elixxir dApps SDK Swift
Commits
5a5091ad
Commit
5a5091ad
authored
2 years ago
by
Dariusz Rybicki
Browse files
Options
Downloads
Patches
Plain Diff
Add MessageListener
parent
5f4dd230
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!2
Bindings API wrapper
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Sources/ElixxirDAppsSDK/Connection.swift
+7
-3
7 additions, 3 deletions
Sources/ElixxirDAppsSDK/Connection.swift
Sources/ElixxirDAppsSDK/MessageListener.swift
+72
-0
72 additions, 0 deletions
Sources/ElixxirDAppsSDK/MessageListener.swift
with
79 additions
and
3 deletions
Sources/ElixxirDAppsSDK/Connection.swift
+
7
−
3
View file @
5a5091ad
...
@@ -3,6 +3,7 @@ import Bindings
...
@@ -3,6 +3,7 @@ import Bindings
public
struct
Connection
{
public
struct
Connection
{
public
var
isAuthenticated
:
()
->
Bool
public
var
isAuthenticated
:
()
->
Bool
public
var
send
:
MessageSender
public
var
send
:
MessageSender
public
var
listen
:
MessageListener
}
}
extension
Connection
{
extension
Connection
{
...
@@ -11,7 +12,8 @@ extension Connection {
...
@@ -11,7 +12,8 @@ extension Connection {
)
->
Connection
{
)
->
Connection
{
Connection
(
Connection
(
isAuthenticated
:
{
false
},
isAuthenticated
:
{
false
},
send
:
.
live
(
bindingsConnection
:
bindingsConnection
)
send
:
.
live
(
bindingsConnection
:
bindingsConnection
),
listen
:
.
live
(
bindingsConnection
:
bindingsConnection
)
)
)
}
}
...
@@ -20,7 +22,8 @@ extension Connection {
...
@@ -20,7 +22,8 @@ extension Connection {
)
->
Connection
{
)
->
Connection
{
Connection
(
Connection
(
isAuthenticated
:
bindingsAuthenticatedConnection
.
isAuthenticated
,
isAuthenticated
:
bindingsAuthenticatedConnection
.
isAuthenticated
,
send
:
.
live
(
bindingsAuthenticatedConnection
:
bindingsAuthenticatedConnection
)
send
:
.
live
(
bindingsAuthenticatedConnection
:
bindingsAuthenticatedConnection
),
listen
:
.
live
(
bindingsAuthenticatedConnection
:
bindingsAuthenticatedConnection
)
)
)
}
}
}
}
...
@@ -29,7 +32,8 @@ extension Connection {
...
@@ -29,7 +32,8 @@ extension Connection {
extension
Connection
{
extension
Connection
{
public
static
let
failing
=
Connection
(
public
static
let
failing
=
Connection
(
isAuthenticated
:
{
false
},
isAuthenticated
:
{
false
},
send
:
.
failing
send
:
.
failing
,
listen
:
.
failing
)
)
}
}
#endif
#endif
This diff is collapsed.
Click to expand it.
Sources/ElixxirDAppsSDK/MessageListener.swift
0 → 100644
+
72
−
0
View file @
5a5091ad
import
Bindings
public
struct
MessageListener
{
public
var
listen
:
(
Int
,
String
,
@escaping
(
Data
)
->
Void
)
->
Data
public
func
callAsFunction
(
messageType
:
Int
,
listenerName
:
String
=
"MessageListener"
,
callback
:
@escaping
(
Data
)
->
Void
)
->
Data
{
listen
(
messageType
,
listenerName
,
callback
)
}
}
extension
MessageListener
{
public
static
func
live
(
bindingsConnection
:
BindingsConnection
)
->
MessageListener
{
MessageListener
.
live
(
register
:
bindingsConnection
.
registerListener
(
_
:
newListener
:)
)
}
public
static
func
live
(
bindingsAuthenticatedConnection
:
BindingsAuthenticatedConnection
)
->
MessageListener
{
MessageListener
.
live
(
register
:
bindingsAuthenticatedConnection
.
registerListener
(
_
:
newListener
:)
)
}
private
static
func
live
(
register
:
@escaping
(
Int
,
BindingsListenerProtocol
)
->
Data
?
)
->
MessageListener
{
MessageListener
{
messageType
,
listenerName
,
callback
in
let
listener
=
Listener
(
listenerName
:
listenerName
,
onHear
:
callback
)
let
listenerId
=
register
(
messageType
,
listener
)
guard
let
listenerId
=
listenerId
else
{
fatalError
(
"BindingsConnection.registerListener returned `nil`"
)
}
return
listenerId
}
}
}
private
class
Listener
:
NSObject
,
BindingsListenerProtocol
{
init
(
listenerName
:
String
,
onHear
:
@escaping
(
Data
)
->
Void
)
{
self
.
listenerName
=
listenerName
self
.
onHear
=
onHear
super
.
init
()
}
let
listenerName
:
String
let
onHear
:
(
Data
)
->
Void
func
hear
(
_
item
:
Data
?)
{
guard
let
item
=
item
else
{
return
}
onHear
(
item
)
}
func
name
()
->
String
{
listenerName
}
}
#if DEBUG
extension
MessageListener
{
public
static
let
failing
=
MessageListener
{
_
,
_
,
_
in
Data
()
}
}
#endif
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment