0.0.7 • Published 11 months ago
websocketwithheartbeat v0.0.7
webSocketWithHeartbeat
Description
webSocketWithHeartbeat
is a simple project to demonstrate a WebSocket connection with a heartbeat mechanism.
Installation
npm install --save websocketwithheartbeat
Usage
import WebSocketWithHeartbeat from 'webSocketWithHeartbeat'
const socket = new WebSocketWithHeartbeat('https://example.com')
// if you need to create multiple instances, use getInstance()
const socket = WebSocketWithHeartbeat.getInstance('https://example.com')
socket.onopen = () => {
console.log('WebSocket connection established')
}
socket.onmessage = (event: MessageEvent) => {
const data = event.data
console.log('WebSocket message received:', data)
}
socket.onclose = () => {
console.log('WebSocket connection closed')
}
socket.onerror = (error: Event) => {
console.error('WebSocket error:', error)
}
socket.send('Hello, WebSocket!')