Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/alex8088/node-signalr
A signalR client for node.js which support ASP.net but not ASP.net Core.
https://github.com/alex8088/node-signalr
nodejs signalr websocket
Last synced: about 1 month ago
JSON representation
A signalR client for node.js which support ASP.net but not ASP.net Core.
- Host: GitHub
- URL: https://github.com/alex8088/node-signalr
- Owner: alex8088
- License: mit
- Created: 2019-06-21T11:28:05.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2023-07-20T17:41:40.000Z (about 1 year ago)
- Last Synced: 2024-07-19T05:44:18.566Z (about 2 months ago)
- Topics: nodejs, signalr, websocket
- Language: TypeScript
- Homepage:
- Size: 78.1 KB
- Stars: 20
- Watchers: 2
- Forks: 13
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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
```bash
$ npm i node-signalr
```## Usage
### Create a SignalR Client Instance
```ts
import signalr from 'node-signalr'const client = new signalr.Client('http://localhost:8080/signalr', ['testHub'])
```### Configuring Client
```js
// 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
```ts
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
```js
client.connection.hub.on('testHub', 'getMessage', (message) => {
console.log('receive:', message)
})
```- Call the hub method and get return values asynchronously
```ts
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
```ts
const message = { user: '', message: '' }client.connection.hub.invoke('testHub', 'send', message)
```### Start Client
```ts
client.start()
```### End Client
```ts
client.end()
```## Powered By
- [ws](https://github.com/websockets/ws)
## License
[MIT](./LICENSE)