@quangdao/vue-signalr
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

Vue SignalR Plugin

NPM Install

SignalR plugin for Vue 3.

Quick Start

For more detailed instructions, check out the wiki at https://github.com/quangdaon/vue-signalr/wiki.

Installation

This package is available on npm via:

npm install --save @quangdao/vue-signalr

To install in Vue 3:

import { createApp } from 'vue';
import { VueSignalR } from '@quangdao/vue-signalr';
import App from './App.vue';

createApp(App)
  .use(VueSignalR, { url: 'http://localhost:5000/signalr' })
  .mount('#app');

Usage

This plugin provides a composable function to inject the SignalR service. The service exposes a few methods from the SignalR connection to support your app.

import { inject } from 'vue';
import { useSignalR } from '@quangdao/vue-signalr';

interface MyObject {
  prop: string;
}

// Optional Tokens
// Learn More: https://github.com/quangdaon/vue-signalr/wiki/03.-Usage#tokens
const SendMessage: HubCommandToken<MyObject> = 'SendMessage';
const MessageReceived: HubEventToken<MyObject> = 'MessageReceived';

export default {
  setup() {
    // Inject the service
    const signalr = useSignalR();

    // Listen to the "MessageReceived" event
    signalr.on(MessageReceived, () => doSomething());

    // Send a "SendMessage" payload to the hub
    signalr.send(SendMessage, { prop: 'Hello world!' });

    // Invoke "SendMessage" and wait for a response
    signalr.invoke(SendMessage, { prop: 'Hello world!' })
      .then(() => doSomething())
  }
};

Readme

Keywords

Package Sidebar

Install

npm i @quangdao/vue-signalr

Weekly Downloads

36

Version

1.0.1

License

MIT

Unpacked Size

231 kB

Total Files

56

Last publish

Collaborators

  • quangdao