🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

msw-phoenix.channel-binding

Package Overview
Dependencies
Maintainers
0
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

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.

0.1.0
latest
npm
Version published
Maintainers
0
Created
Source

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.

Keywords

msw

FAQs

Package last updated on 02 Dec 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts