-
Notifications
You must be signed in to change notification settings - Fork 191
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 #320 from WalletConnect/feature/chat-app-sdk-integ…
…ration [Chat] Sample app (demo)
- Loading branch information
Showing
28 changed files
with
309 additions
and
179 deletions.
There are no files selected for viewing
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
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
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 |
---|---|---|
@@ -1,8 +1,9 @@ | ||
import Foundation | ||
import Chat | ||
|
||
final class Application { | ||
|
||
let chatService: ChatService = { | ||
return ChatService() | ||
return ChatService(client: ChatFactory.create()) | ||
}() | ||
} |
23 changes: 23 additions & 0 deletions
23
Example/Showcase/Classes/ApplicationLayer/Configurator/ApplicationConfigurator.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 |
---|---|---|
@@ -1,14 +1,37 @@ | ||
import Combine | ||
|
||
struct ApplicationConfigurator: Configurator { | ||
|
||
private var publishers = Set<AnyCancellable>() | ||
|
||
private let app: Application | ||
|
||
init(app: Application) { | ||
self.app = app | ||
} | ||
|
||
func configure() { | ||
registerAccount() | ||
|
||
ChatListModule.create(app: app) | ||
.wrapToNavigationController() | ||
.present() | ||
} | ||
} | ||
|
||
private extension ApplicationConfigurator { | ||
|
||
func registerAccount() { | ||
Task(priority: .high) { | ||
for await status in app.chatService.connectionPublisher { | ||
guard status == .connected else { | ||
fatalError("Not Connected") | ||
} | ||
|
||
print("Socket connected") | ||
|
||
try! await app.chatService.register(account: ChatService.selfAccount) | ||
} | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
Example/Showcase/Classes/DomainLayer/Chat/ChatFactory.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,22 @@ | ||
import Foundation | ||
import Chat | ||
import WalletConnectKMS | ||
import WalletConnectRelay | ||
|
||
class ChatFactory { | ||
|
||
static func create() -> ChatClient { | ||
let relayHost = "relay.walletconnect.com" | ||
let projectId = "8ba9ee138960775e5231b70cc5ef1c3a" | ||
let keychain = KeychainStorage(serviceIdentifier: "com.walletconnect.showcase") | ||
let client = HTTPClient(host: "159.65.123.131") | ||
let registry = KeyserverRegistryProvider(client: client) | ||
let relayClient = RelayClient(relayHost: relayHost, projectId: projectId, keychainStorage: keychain, socketFactory: SocketFactory()) | ||
return ChatClient( | ||
registry: registry, | ||
relayClient: relayClient, | ||
kms: KeyManagementService(keychain: keychain), | ||
keyValueStorage: UserDefaults.standard | ||
) | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
Example/Showcase/Classes/DomainLayer/Chat/ChatService.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,70 @@ | ||
import Foundation | ||
import Combine | ||
import Chat | ||
import WalletConnectUtils | ||
import WalletConnectRelay | ||
|
||
typealias Stream<T> = AsyncPublisher<AnyPublisher<T, Never>> | ||
|
||
final class ChatService { | ||
|
||
static let selfAccount = Account("eip155:1:0xab16a96d359ec26a11e2c2b3d8f8b8942d5bfcdb")! | ||
|
||
private let client: ChatClient | ||
|
||
init(client: ChatClient) { | ||
self.client = client | ||
} | ||
|
||
var connectionPublisher: Stream<SocketConnectionStatus> { | ||
return client.socketConnectionStatusPublisher.values | ||
} | ||
|
||
var messagePublisher: Stream<Message> { | ||
return client.messagePublisher.values | ||
} | ||
|
||
var threadPublisher: Stream<Chat.Thread> { | ||
return client.newThreadPublisher.values | ||
} | ||
|
||
var invitePublisher: Stream<Invite> { | ||
return client.invitePublisher.values | ||
} | ||
|
||
func getMessages(thread: Chat.Thread) async -> [Chat.Message] { | ||
await client.getMessages(topic: thread.topic) | ||
} | ||
|
||
func getThreads() async -> [Chat.Thread] { | ||
await client.getThreads() | ||
} | ||
|
||
func getInvites(account: Account) async -> [Chat.Invite] { | ||
client.getInvites(account: account) | ||
} | ||
|
||
func sendMessage(topic: String, message: String) async throws { | ||
try await client.message(topic: topic, message: message) | ||
} | ||
|
||
func accept(invite: Invite) async throws { | ||
try await client.accept(inviteId: invite.pubKey) | ||
} | ||
|
||
func reject(invite: Invite) async throws { | ||
try await client.reject(inviteId: invite.pubKey) | ||
} | ||
|
||
func invite(peerPubkey publicKey: String, peerAccount: Account, message: String, selfAccount: Account) async throws { | ||
try await client.invite(publicKey: publicKey, peerAccount: peerAccount, openingMessage: message, account: selfAccount) | ||
} | ||
|
||
func register(account: Account) async throws { | ||
_ = try await client.register(account: account) | ||
} | ||
|
||
func resolve(account: Account) async throws -> String { | ||
return try await client.resolve(account: account) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
11 changes: 11 additions & 0 deletions
11
Example/Showcase/Classes/DomainLayer/SocketFactory/SocketFactory.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,11 @@ | ||
import Foundation | ||
import Starscream | ||
import WalletConnectRelay | ||
|
||
extension WebSocket: WebSocketConnecting { } | ||
|
||
struct SocketFactory: WebSocketFactory { | ||
func create(with url: URL) -> WebSocketConnecting { | ||
return WebSocket(url: url) | ||
} | ||
} |
Oops, something went wrong.