3.0.0-alpha.1 • Published 1 year ago

node-signalr v3.0.0-alpha.1

Weekly downloads
38
License
MIT
Repository
github
Last release
1 year ago

node-signalr

A signalR client for node.js which support ASP.net but not ASP.net Core. For ASP.net Core signalR support use the offical client from Microsoft.

Install

$ npm i node-signalr

Usage

Create a SignalR Client Instance

import signalr from 'node-signalr'

const client = new signalr.Client('http://localhost:8080/signalr', ['testHub'])

Configuring Client

// custom headers
client.headers['Token'] = 'Tds2dsJk'

// set timeout for sending message
client.callTimeout = 10000 // 10's, default 5000

// set delay time for reconecting
client.reconnectDelayTime = 2000 // 2's, default 5000

// set timeout for connect
client.requestTimeout = 2000 // 2's, default 5000

Binding Client Events

client.on('connected', () => {
  console.log('SignalR client connected.')
})
client.on('reconnecting', (retryCount) => {
  console.log(`SignalR client reconnecting(${retryCount}).`)
})
client.on('disconnected', (reason) => {
  console.log(`SignalR client disconnected(${reason}).`)
})
client.on('error', (error) => {
  console.log(`SignalR client connect error: ${error.code}.`)
})

Binding Hub Method

  • Bind callback for receive message
client.connection.hub.on('testHub', 'getMessage', (message) => {
  console.log('receive:', message)
})
  • Call the hub method and get return values asynchronously
const message = { user: '', message: '' }

client.connection.hub
  .call('testHub', 'send', message)
  .then((result) => {
    console.log('success:', result)
  })
  .catch((error) => {
    console.log('error:', error)
  })
  • Invoke the hub method without return values
const message = { user: '', message: '' }

client.connection.hub.invoke('testHub', 'send', message)

Start Client

client.start()

End Client

client.end()

Powered By

License

MIT

3.0.0-alpha.1

1 year ago

3.0.0-alpha.0

1 year ago

2.0.6

3 years ago

2.0.5

4 years ago

2.0.4

4 years ago

2.0.3

4 years ago

2.0.2

4 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.0.12

5 years ago

1.0.11

5 years ago

1.0.10

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago