npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@azure/web-pubsub-socket.io

v1.1.0

Published

Enable Socket.IO server support Azure Web PubSub Service

Downloads

2,456

Readme

Introduction

This package is the extension library to the Socket.IO Server SDK. Using this library together with the Web PubSub For Socket.IO Service enables the Azure service to manage clients at scale and keep Socket.IO's programming experience.

Web PubSub For Socket.IO works as a broker between clients and the Socket.IO server. It handles connection management and broadcasting messages at scale and provide scalability and reliability experience. With this library, you don't need to introduce and manage an extra Adapter to support multi-server environment.

Get Started

The following steps show you how to create a Web PubSub for Socket.IO resource and use this library to enable your Socket.IO server to work together with the service. For more details step of how to get started with Web PubSub for Socket.IO, please refer to Get started with Web PubSub for Socket.IO.

Create a Web PubSub for Socket.IO resource

Use following button to create a Web PubSub for Socket.IO resource in Azure.

Deploy to Azure

Initialize a Node project and install required packages

mkdir quickstart
cd quickstart
npm init
npm install @azure/web-pubsub-socket.io socket.io-client

Write server code

Create a server.js file and add following code to create a Socket.IO server and integrate with Web PubSub for Socket.IO.

/*server.js*/
const { Server } = require("socket.io");
const { useAzureSocketIO } = require("@azure/web-pubsub-socket.io");

let io = new Server(3000);

// Use the following line to integrate with Web PubSub for Socket.IO
useAzureSocketIO(io, {
    hub: "Hub", // The hub name can be any valid string.
    connectionString: process.argv[2]
});

io.on("connection", (socket) => {
    // Sends a message to the client
    socket.emit("hello", "world");

    // Receives a message from the client
    socket.on("howdy", (arg) => {
        console.log(arg);   // Prints "stranger"
    })
});

Write client code

Create a client.js file and add following code to connect the client with Web PubSub for Socket.IO.

/*client.js*/
const io = require("socket.io-client");

const socket = io("<web-pubsub-socketio-endpoint>", {
    path: "/clients/socketio/hubs/Hub",
});

// Receives a message from the server
socket.on("hello", (arg) => {
    console.log(arg);
});

// Sends a message to the server
socket.emit("howdy", "stranger")

When you use Web PubSub for Socket.IO, <web-pubsub-socketio-endpoint> and path are required for the client to connect to the service. The <web-pubsub-socketio-endpoint> and path can be found in Azure portal.

  1. Go to the key blade of Web PubSub for Socket.IO

  2. Type in your hub name and copy the Client Endpoint and Client Path

    Get client path

Run the app

  1. Run the server app:

    node server.js "<connection-string>"

    The <connection-string> is the connection string that contains the endpoint and keys to access your Web PubSub for Socket.IO resource. You can also find the connection string in Azure portal

    Get connection string

  2. Run the client app in another terminal:

    node client.js

Debug

  1. Determine which packages' logs you want to see.

  2. Set environmental variable DEBUG in your shell according to your wanted packages. Here is a PowerShell examples:

# Show log from this package
$Env:DEBUG='wps-sio-ext*'

# Show log from this package + Engine.IO
$Env:DEBUG='wps-sio-ext*,engine*'

# Show log from this package + Engine.IO + Socket.IO
$Env:DEBUG='wps-sio-ext*,engine*,socket.io:*'

# Show logs from all packages
$Env:DEBUG='*'

Building library from source

The @azure/web-pubsub-socket.io library depends on server-proxies library, so you need to build server-proxies first.

Build server-proxies:

cd ../server-proxies
yarn install
yarn build

Build @azure/web-pubsub-socket.io

# navigate into webpubsub-socketio-extension folder
yarn install
yarn run build

Unit Test

  1. Rename .env.test.example to .env.test. And update the WebPubSubConnectionString inside:
WebPubSubConnectionString="<web-pubsub-connection-string>"
WebPubSubHub="eio_hub"
SocketIoPort=3000
  1. Run command
yarn test:unit

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.

When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.