npm i --save @wuilmerj24/signalr
- Version: 1.0.8
- GitHub: https://github.com/wuilmerj24/nativescript-plugins
- NPM: https://www.npmjs.com/package/%40wuilmerj24%2Fsignalr
- Downloads:
- Last Day: 0
- Last Week: 0
- Last Month: 0
@wuilmerj24/signalr
npm install @wuilmerj24/signalr
Api
Method | Params | Return |
---|---|---|
create | OptionsConnect | Promise |
disconnect | void |
|
conectionId | string |
|
on | eventName:sting ,callback: (...payload: any[]) |
void |
off | eventName:sting |
void |
onClose | Fired close connection | |
emit | eventName:sting ,callback: (...payload: any[]) |
void |
isConnected | EStateConn |
Interfaces
export interface OptionsConnect {
url: string;
accessToken?: string;
shouldSkipNegotiate?: boolean;
headers?: Array<IHeaders>;
handshakeResponseTimeout?: number;
keepAliveInterval?: number;
serverTimeout?: number;
transport?: TypeTransport;
reconnect?: boolean;
}
Enums
export enum TypeTransport {
ALL = 'ALL',
WEBSOCKETS = 'WEBSOCKETS',
LONG_POLLING = 'LONG_POLLING',
}
export enum EStateConn {
CONNECTED = 'CONNECTED',
CONNECTING = 'CONNECTING',
DISCONNECTED = 'DISCONNECTED',
}
examples
const signalr: Signalr = new Signalr();
export async function connect() {
await signalr
.create({
url: 'url',
shouldSkipNegotiate: false,
headers: [{ name: 'Content-Type', value: 'application/json' }],
transport: TypeTransport.WEBSOCKETS,
reconnect: true,
})
.then((res) => {
console.log('finish ', res);
signalr.onClose(() => {
console.log();
});
})
.catch((err) => {
console.log('error ', err);
});
}
export async function desconectar() {
await signalr.disconnect();
}
export async function getStaateConn() {
alert(signalr.isConnected);
console.log("id",signalr.conectionId());
}
export async function invoke() {
signalr.emit('evento', null);
}
export async function ons() {
signalr.on('evento', (data) => {
console.log(data);
});
}
License
Apache License Version 2.0