Skip to content

Instantly share code, notes, and snippets.

@MossP
MossP / webSocket.js
Created May 14, 2019 00:28 — forked from woraperth/webSocket.js
JavaScript Singleton to connect to WebSocket (originally for React project)
// Thank you Ranatchai Chernbamrung for sample socketIO singleton pattern
// This code is originally for my React project, but should work with any ES6 project that support `import` statement
// How it works
// 1. Create webSocket.js to establish the connection and retrieve the connection
// 2. In main file, import webSocket.js to establish the connection
// 3. In other component files, import webSocket.js to retrieve the connection
// webSocket.js
let client