This tutorial will demo how you can use jsc8 stream with Cloudflare edge worker.
git clone https://github.com/Macrometacorp/tutorial-jsc8-stream-ws-on-cfw cd tutorial-jsc8-stream-ws-on-cfw npm install update `account_id` in wrangler.toml wrangler preview wrangler publish //CF Publish
- Creating jsC8 client
const jsc8Client = new jsc8({
url: "https://gdn1.paas.macrometa.io/",
apiKey: "xxxx",
agent: fetch.bind(this), // Need additional "agent" parameter with value "fetch.bind(this)"
})
- Creating Stream reader
const stream = jsc8Client.stream(streamName, true)
const consumerOTP = await stream.getOtp()
client = await stream.consumer(
"SampleStream-my-subscription",
"gdn1.paas.macrometa.io",
{ otp: consumerOTP },
"cloudflare", // When creating a stream reader, pass "cloudflare" as the last parameter in order to create Cloudflare websocket connection
)
- Creating Stream Producer
const stream = jsc8Client.stream(streamName, true)
const consumerOTP = await stream.getOtp()
client = await stream.producer(
"gdn1.paas.macrometa.io",,
{ otp: consumerOTP },
"cloudflare" // When creating a stream producer, pass "cloudflare" as the last parameter in order to create Cloudflare websocket connection
)