Skip to main content

Custom WebSocket client

Overview

The DuoNetworkClient class is a WebSocket client operations implements transport agnostic NetworkClient.

1. DuoNetworkClient implements NetworkClient

  • Responsibility:
    • Raw WebSocket connection management
    • Message queueing and asynchronous I/O
    • Binary/text data transmission
  • Customization Use Cases:
    • Add Action specific logic for example perform some logic on keygen connect
    • Replace WebSocket library (e.g., Socket.IO, different WebSocket impl)
    • Modify low-level message queueing logic

Example

App.tsx
import duoinitiator

class CustomNetworkClient: DuoNetworkClient {

override func connect(websocketAction: DuoNetworkAction, params: String?) async throws {
var customAction: WebsocketAction = websocketAction

// Customize the action based on the specific type
if var keygenAction = websocketAction as? ECDSAKeygen {
// Example: Customize path, action, or protocol
keygenAction.path = "custom-duo"
customAction = keygenAction
} else if var keygenAction = websocketAction as? EdDSAKeygen {
// Example: Customize path, action, or protocol
keygenAction.path = "custom-duo"
customAction = keygenAction
} else if var signAction = websocketAction as? ECDSASignature {
// Example: Customize signature action
signAction.protocol = "custom-duo-instance"
customAction = signAction
} else if var signAction = websocketAction as? EdDSASignature {
// Example: Customize signature action
signAction.protocol = "custom-duo-instance"
customAction = signAction
}
// Add more customizations as needed for other action types

try await super.connect(
websocketAction: customAction as! DuoNetworkAction,
params: params
)
}
}

Copyright © 2026 Silence Laboratories