Skip to content

Commit

Permalink
serverless: add signed streams
Browse files Browse the repository at this point in the history
  • Loading branch information
palkan committed Apr 16, 2024
1 parent 6d093fe commit be2ac68
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion docs/guides/serverless.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,31 @@ const token = await identifier.generateToken({ userId });

### Signed streams

_🛠️ Coming soon_. Check out the [signed streams documentation](../anycable-go/signed_streams.md)_.
SDK provides functionality to generate [signed stream names](/anycable-go/signed_streams). For that, you can create a _signer_ instance with the corresponding secret:

```js
import { signer } from "@anycable/serverless-js";

const streamsSecret = process.env.ANYCABLE_STREAMS_SECRET;

const sign = signer(secret);

const signedStreamName = sign("room/13");
```

Then, you can use the generated stream name with your client (using [AnyCable JS client SDK](https://github.com/anycable/anycable-client)):

```js
import { createCable } from "@anycable/web";

const cable = createCable(WEBSOCKET_URL);
const stream = await fetchStreamForRoom("13");

const channel = cable.streamFromSigned(stream);
channel.on("message", (msg) => {
// handle notification
})
```

### Broadcasting

Expand Down

0 comments on commit be2ac68

Please sign in to comment.