npm i --save @wuilmerj24/signalr
- 版本: 1.0.6
- GitHub: https://github.com/wuilmerj24/nativescript-plugins
- NPM: https://npmjs.net.cn/package/%40wuilmerj24%2Fsignalr
- 下载量
- 昨日: 0
- 上周: 7
- 上个月: 30
@wuilmerj24/signalr
npm install @wuilmerj24/signalr
API
方法 | 参数 | 返回 |
---|---|---|
create | OptionsConnect | Promise |
disconnect | void |
|
conectionId | string |
|
on | eventName:string ,callback: (...payload: any[]) |
void |
off | eventName:string |
void |
emit | eventName:string ,callback: (...payload: any[]) |
void |
isConnected | EStateConn |
接口
export interface OptionsConnect {
url: string;
accessToken?: string;
shouldSkipNegotiate?: boolean;
headers?: Array<IHeaders>;
handshakeResponseTimeout?: number;
keepAliveInterval?: number;
serverTimeout?: number;
transport?: TypeTransport;
reconnect?: boolean;
}
枚举
export enum TypeTransport {
ALL = 'ALL',
WEBSOCKETS = 'WEBSOCKETS',
LONG_POLLING = 'LONG_POLLING',
}
export enum EStateConn {
CONNECTED = 'CONNECTED',
CONNECTING = 'CONNECTING',
DISCONNECTED = 'DISCONNECTED',
}
示例
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);
})
.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);
});
}
许可
Apache License Version 2.0