Socket
Socket
Sign inDemoInstall

@types/sockjs

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@types/sockjs

TypeScript definitions for sockjs


Version published
Weekly downloads
7.1M
decreased by-21.41%
Maintainers
1
Weekly downloads
 
Created

What is @types/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.

What are @types/sockjs's main functionalities?

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');
};

Other packages similar to @types/sockjs

FAQs

Package last updated on 06 Jul 2021

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc