Skip to content

Commit

Permalink
docs: finish peer section
Browse files Browse the repository at this point in the history
  • Loading branch information
PhearZero committed Aug 12, 2024
1 parent fce5046 commit 5a0e110
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 36 deletions.
8 changes: 0 additions & 8 deletions docs/astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,10 @@ export default defineConfig({
{
label: "Peer Offer",
link: "/clients/android/offer",
badge: {
text: "WIP",
variant: "caution"
},
},
{
label: "Peer Answer",
link: "/clients/android/answer",
badge: {
text: "WIP",
variant: "caution"
},
},
{
label: "Provider Service",
Expand Down
22 changes: 16 additions & 6 deletions docs/src/content/docs/clients/android/answer.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,28 @@ val origin = "https://my-liquid-service.com" // Specify the origin of the servic
val client = SignalClient(origin, context, httpClient) // Create the Client

// Display the QR Code
val qrCode = signalClient.qrCode(requestId, BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher_round))
val qrCode = client.qrCode(requestId, BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher_round))

// Wait for peer to scan the QR Code
val dc = signalClient.peer(requestId, "offer" )
val dc = client.peer(requestId, "offer" )

// Handle the data channel messages and state changes
signalClient.handleDataChannel(dc!!, {
```

## Data Channel[WIP]

We are working on a more robust way to handle data channel messages. For now, you can use the following:

```kotlin
// Example.kt

// Handle Peer Messages
client.handleDataChannel(dc, {
Log.d(TAG, "onMessage($it)")
},{
}, {
Log.d(TAG, "onStateChange($it)")
})


// Send Message to Peer
signalClient.peerClient.send("Hello World!")
client.send("Hello World!")
```
29 changes: 25 additions & 4 deletions docs/src/content/docs/clients/android/offer.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,35 @@ import {Aside} from "@astrojs/starlight/components";
See the [Authentication](./authentication) and [Registration](./registration) guides for more information.
</Aside>

[Peer-to-Peer]() connections can only be done using the `SignalClient`.
[Peer-to-Peer](/guides/concepts/#peer-to-peer) connections can only be done using the `SignalClient`.
Wallets are responsible for creating offers to connect.

### Who is this for?

- **Android Wallets** that want to communicate with other clients

## Signaling

```kotlin
val requestID = 12345 // Scanned from a QR Code or Deep Link
val origin = "https://my-liquid-service.com" // Origin of the service
// Example.kt
import foundation.algorand.auth.connect.SignalClient

val requestID = "UUID-STRING-FROM-QR-CODE" // Scanned from a QR Code or Deep Link
val origin = "https://<ORIGIN-OF-SERVICE-FROM-QR-CODE>" // Origin of the service
val client = SignalClient(origin, context, httpClient)
val dc = signalClient?.peer(requestId, "answer" )
val dc = client.peer(requestId, "answer" )
```

## Data Channel[WIP]

We are working on a more robust way to handle data channel messages. For now, you can use the following:

```kotlin
// Example.kt

client.handleDataChannel(dc, {
Log.d(TAG, "onMessage($it)")
}, {
Log.d(TAG, "onStateChange($it)")
})
```
26 changes: 19 additions & 7 deletions docs/src/content/docs/clients/browser/answer.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,26 @@ const requestId = SignalClient.generateRequestId();
## Signaling

```typescript
// Wait for a remote offer for the current request id
client
.peer(requestId, 'offer')
.then((dataChannel: RTCDataChannel)=>{
// Handle the data channel
dataChannel.onmessage = (event: MessageEvent) => {
console.log(event.data)
}
})
const blob = await client.qrCode()
.then(handleDataChannel)

// Display QR Code
const blob = await client.qrCode()
```

## Data Channel[WIP]

We are working on a more robust way to handle data channel messages. For now, you can use the following:

```typescript

function handleDataChannel(dc: RTCDataChannel){
dc.onmessage = (event: MessageEvent) => {
console.log(event.data)
}
dc.send('Hello world!')
}
```

23 changes: 14 additions & 9 deletions docs/src/content/docs/clients/browser/offer.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {Aside} from "@astrojs/starlight/components";
See the [Authentication](/docs/clients/browser/authentication) and [Registration]() guides for more information.
</Aside>

[Peer-to-Peer]() connections can only be done using the `SignalClient`.
[Peer-to-Peer](/guides/concepts/#peer-to-peer) connections can only be done using the `SignalClient`.
Wallets are responsible for creating offers to connect.

### Who is this for?
Expand All @@ -22,27 +22,32 @@ Wallets are responsible for creating offers to connect.

```typescript
import { SignalClient } from "@algorandfoundation/liquid-client";
const client = new SignalClient("<ORIGIN OF SERVICE>")
const client = new SignalClient("<ORIGIN-FROM-QR-CODE>")

// Receive the RequestID from the Peer willing to Answer this offer
const requestId = 12345
const requestId = "<UUID-FROM-QR-CODE>"

// Register or create a new credential,
// ensure the requestId is included in the call
// ...

// Create the Peer Connection and await the remote client's answer
client.peer(
const dc = await client.peer(
// Request ID from the Peer,
// usually displayed as a Deep Link or QR Code
requestId,
// Type of remote client
'answer'
).then((dataChannel: RTCDataChannel) => {
// Handle the data channel
dataChannel.onmessage = (event: MessageEvent) => {
)
```

## Data Channel[WIP]

We are working on a more robust way to handle data channel messages. For now, you can use the following:

```typescript
dc.onmessage = (event: MessageEvent) => {
console.log(event.data)
}
dataChannel.send('Hello world!')
})
dc.send('Hello world!')
```
2 changes: 1 addition & 1 deletion docs/src/content/docs/guides/Peer to Peer/answer.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ This is usually a dApp that wants to peer with a wallet client with an Offer.
The Answer client is responsible for presenting the QRCode to the Offer client.

<LinkCard
href="/guides/Peer%20to%20Peer/exchange"
href="/guides/peer-to-peer/exchange"
title="Exchange Sessions"
description="A detailed guide on how Offer and Answer clients exchange messages."
/>
Expand Down
2 changes: 1 addition & 1 deletion docs/src/content/docs/guides/Peer to Peer/offer.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ and is used to create a P2P connection with an **Answer** client.
This is usually a wallet that wants to peer with a dApp client that can produce an Answer.

<LinkCard
href="/guides/Peer%20to%20Peer/exchange"
href="/guides/peer-to-peer/exchange"
title="Exchange Sessions"
description="A detailed guide on how Offer and Answer clients exchange messages."
/>
Expand Down

0 comments on commit 5a0e110

Please sign in to comment.