Introduction
Getting Started
Learn how to install and set up SOCKJS in your project
1Installation
Install SOCKJS using npm or yarn:
bash
npm install sockjs-client
# or
yarn add sockjs-client2CDN Installation
You can also include SOCKJS directly via CDN:
html
<script src="https://cdn.jsdelivr.net/npm/sockjs-client@1/dist/sockjs.min.js"></script>3Basic Usage
javascript
import SockJS from 'sockjs-client';
const sock = new SockJS('https://your-server.com/sockjs');
sock.onopen = function() {
console.log('Connection opened');
sock.send('Hello!');
};
sock.onmessage = function(e) {
console.log('Message received:', e.data);
};
sock.onclose = function() {
console.log('Connection closed');
};4Browser Support
SOCKJS supports all modern browsers including:
5Configuration Options
javascript
const sock = new SockJS(url, null, {
server: 'server-id',
transports: ['websocket'],
sessionId: 8,
timeout: 5000
});