Security News
ESLint is Now Language-Agnostic: Linting JSON, Markdown, and Beyond
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
@types/sockjs
Advanced tools
TypeScript definitions for sockjs
The @types/sockjs npm package provides TypeScript type definitions for SockJS, a JavaScript library that provides a WebSocket-like object. SockJS gives you a coherent, cross-browser, Javascript API which creates a low latency, full duplex, cross-domain communication channel between the browser and the web server, with WebSockets or without. This package does not contain the functionality of SockJS itself but includes the type definitions to enable better development experience in TypeScript environments.
Type Definitions for Server Initialization
This code sample demonstrates how to initialize a SockJS server with TypeScript, using the type definitions provided by @types/sockjs. It sets up a simple echo service on the server.
import * as http from 'http';
import * as sockjs from 'sockjs';
const echo = sockjs.createServer({ sockjs_url: 'http://cdn.jsdelivr.net/sockjs/1.0.1/sockjs.min.js' });
econst server = http.createServer();
echo.installHandlers(server, {prefix:'/echo'});
server.listen(9999, '0.0.0.0');
Type Definitions for Client Connection
This code sample shows how to connect to a SockJS server from the client side using TypeScript. It demonstrates handling the open, message, and close events of the SockJS connection.
import * as SockJS from 'sockjs-client';
let sock = new SockJS('http://mydomain.com/my_prefix');
sock.onopen = function() {
console.log('open');
sock.send('test');
};
sock.onmessage = function(e) {
console.log('message', e.data);
};
sock.onclose = function() {
console.log('close');
};
Provides TypeScript definitions for the 'ws' package, a WebSocket client and server implementation. Unlike @types/sockjs, which is designed to work across different environments including those that do not support WebSockets, @types/ws is specifically for environments where WebSocket support is available.
Offers TypeScript definitions for Socket.IO, a real-time bidirectional event-based communication library. While @types/sockjs focuses on providing a consistent API across different browser and server implementations, @types/socket.io is more about enabling real-time capabilities in applications with a focus on event handling.
npm install --save @types/sockjs
This package contains type definitions for sockjs (https://github.com/sockjs/sockjs-node).
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/sockjs.
// Type definitions for sockjs 0.3
// Project: https://github.com/sockjs/sockjs-node
// Definitions by: Phil McCloghry-Laing <https://github.com/pmccloghrylaing>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="node" />
import http = require('http');
export interface ServerOptions {
sockjs_url?: string | undefined;
prefix?: string | undefined;
response_limit?: number | undefined;
websocket?: boolean | undefined;
jsessionid?: any;
log?(severity: string, message: string): void;
heartbeat_delay?: number | undefined;
disconnect_delay?: number | undefined;
}
export function createServer(options?: ServerOptions): Server;
export interface Server extends NodeJS.EventEmitter {
installHandlers(server: http.Server, options?: ServerOptions): any;
on(event: 'connection', listener: (conn: Connection) => any): this;
on(event: string, listener: Function): this;
}
export interface Connection extends NodeJS.ReadWriteStream {
remoteAddress: string;
remotePort: number;
address: {
[key: string]: {
address: string;
port: number;
};
};
headers: {
[key: string]: string;
};
url: string;
pathname: string;
prefix: string;
protocol: string;
readyState: number;
id: string;
close(code?: string, reason?: string): boolean;
destroy(): void;
on(event: 'data', listener: (message: string) => any): this;
on(event: 'close', listener: () => void): this;
on(event: string, listener: Function): this;
}
These definitions were written by Phil McCloghry-Laing.
FAQs
TypeScript definitions for sockjs
The npm package @types/sockjs receives a total of 6,746,934 weekly downloads. As such, @types/sockjs popularity was classified as popular.
We found that @types/sockjs demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
Security News
Members Hub is conducting large-scale campaigns to artificially boost Discord server metrics, undermining community trust and platform integrity.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.