websocket-front
Advanced tools
Comparing version 1.0.5 to 1.0.6
@@ -21,3 +21,7 @@ interface EventParams { | ||
} | ||
declare class Socket { | ||
interface SocketInterface { | ||
send: (message: string | ArrayBufferLike | Blob | ArrayBufferView) => void; | ||
close: () => void; | ||
} | ||
declare class Socket implements SocketInterface { | ||
url: string; | ||
@@ -48,2 +52,2 @@ opts: SocketOpts; | ||
export { SocketOptions, Socket as default }; | ||
export { SocketInterface, SocketOptions, Socket as default }; |
{ | ||
"name": "websocket-front", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"description": "WebSocket client for browser with reconnect and heartbeat", | ||
"main": "./dist/index.esm.js", | ||
"types": "./dist/index.d.ts", | ||
"types": "dist/index.d.ts", | ||
"scripts": { | ||
@@ -18,3 +18,6 @@ "test": "echo \"Error: no test specified\" && exit 1", | ||
"native", | ||
"websocket" | ||
"websocket", | ||
"web、front", | ||
"js", | ||
"前端" | ||
], | ||
@@ -21,0 +24,0 @@ "author": "yanquanmei", |
@@ -32,2 +32,11 @@ # websocket-front | ||
import Socket from 'websocket-front'; | ||
const receiveMessage = (message: Event) => { | ||
console.log('接收到的消息:', message) | ||
} | ||
const errorCallback = (error: Event) => { | ||
console.log('错误信息', error) | ||
} | ||
const closeCallback = (event: Event) => { | ||
console.log('关闭了', event) | ||
} | ||
const socket = new Socket('ws://127.0.0.1:3001', { | ||
@@ -39,3 +48,3 @@ // 重连 | ||
// 心跳检测 | ||
isHeartbeat: true | ||
isHeartbeat: true, | ||
pingMsg: JSON.stringify({ | ||
@@ -52,11 +61,2 @@ messageType: "0", | ||
}) | ||
const receiveMessage = (message: Event) => { | ||
console.log('接收到的消息:', message) | ||
} | ||
const errorCallback = (error: Event) => { | ||
console.log('错误信息', event) | ||
} | ||
const closeCallback = (event: Event) => { | ||
console.log('关闭了') | ||
} | ||
``` | ||
@@ -63,0 +63,0 @@ |
@@ -18,3 +18,2 @@ interface EventParams { | ||
pongTimeout: number; // 多长时间没有收到返回的心跳就重启 | ||
// 页面unload时关闭 | ||
protocols?: string[]; | ||
@@ -34,3 +33,8 @@ } | ||
class Socket { | ||
export interface SocketInterface { | ||
send: (message: string | ArrayBufferLike | Blob | ArrayBufferView) => void; | ||
close: () => void; | ||
} | ||
class Socket implements SocketInterface { | ||
url: string; | ||
@@ -37,0 +41,0 @@ opts: SocketOpts; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
24720
10
278