Last active
January 24, 2024 00:06
-
-
Save tfkhdyt/00cbcf8b458269e86471bc604b5eaf50 to your computer and use it in GitHub Desktop.
Node.js websocket example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const WebSocket = require("ws"); | |
const ws = new WebSocket("wss://xapi.netovas.app/auth/inspect/ws"); | |
ws.on("error", console.error); | |
ws.on("open", () => { | |
ws.send( | |
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3MDY2MjE0MjAsImlkIjoxNzAzMDY5NDU4NTcyLCJyb2xlIjoicGFydG5lciJ9.m3h_XqTI-aGZPS4obnoKVfivDXy0cnVIQnoqQlqZNVA", | |
); | |
}); | |
ws.on("message", (data) => { | |
const jsonData = JSON.parse(data); | |
console.log("Message from server:", jsonData); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Library
ws
ini hanya dapat digunakan di server. Untuk di client/browser bisa menggunakan Web API:https://developer.mozilla.org/en-US/docs/Web/API/WebSocket#examples