JSPM

msw-phoenix.channel-binding

0.1.2
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 75
  • Score
    100M100P100Q74718F
  • License MIT

Package Exports

  • msw-phoenix.channel-binding
  • msw-phoenix.channel-binding/build/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (msw-phoenix.channel-binding) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

msw-phoenix.channel-binding

Motivation

This package is intended as a wrapper over the WebSocketInterceptor from @mswjs/interceptors. It provides automatic encoding and decoding of messages, letting you work with the phoenix.channel clients and servers as you are used to.

import { WebSocketInterceptor } from '@mswjs/interceptor'
import { toPhoenixChannel } from 'msw-phoenix.channel-binding'

const interceptor = new WebSocketInterceptor()

interceptor.on('connection', (connection) => {
  client.on('message', (event) => {
    // Phoenix channels implements their custom messaging protocol.
    // This means that the "raw" event data you get will be
    // encoded: e.g. "[null,"49","phoenix","heartbeat",{}]".
    console.log(event.data)
  })

  const phoenix = toPhoenixChannel(connection)

  phoenix.client.channel("room:lobby", (channel) => {
            channel.on(
                "greeting",
                (_event ,{ payload }: PhoenixChannelMessage<{ text: string }>) => {
          console.log(payload.text) // "Hello, John!"
                },
            );
        });
})

You can also use this package with Mock Service Worker directly.