Comments (7)
Good point. Maybe we should have objectMode exposed by a .obj()
method like we do in through2 instead?
var ws = websocketStream.obj() // object mode stream
var ws = websocketStream() // binary stream
from websocket-stream.
IMO object mode is a better default, how about just supporting {objectMode: false}
from websocket-stream.
I think .obj()
would be nice for consistency with through2
/ from2
despite object mode being the objectively better default.
from websocket-stream.
I'm in for objectMode: false
, it's definitely safer to assume objectMode: true
: websocket does its own fragmentation and the like.
@yoshuawuyts The only case when this is bad is when sending big buffers (files!) or with a streaming binary protocol (like MQTT).
from websocket-stream.
yea since websockets dont have backpressure its kind of a hack to put a stream interface on top of websockets anyway so I don't think strictly adhering to node core stream semantics is a high priority
from websocket-stream.
Hey :-)
Is objectMode
supported now?
I only found this issue that touches the topic. It is not listed in the readme, but it mentions:
Options can be passed in as the third or second argument -
WebSocket(address, [protocols], [options])
I'm trying to send objects in electron from a render procees to the main process.
I tried to supply options { objectMode: true }
but when i send data
// renderer
var ws = require('websocket-stream')('http://127.0.0.1',{ objectMode: true })
ws.write({ foo: 'bar' })
ws.end()
i receive
// main
var wss = websocket.createServer({ server: httpServer }, handler)
function handler (client) {
client.on('data', function (data) {
console.log(data) // <Buffer 5b 6f 62 6a 65 63 74 20 4f 62 6a 65 63 74 5d>
console.log(data.toString) // "[object Object]"
})
}
Should i alwasy call JSON.stringify(data)
before the client sends and then JSON.parse(data)
on the server? I'm not planning to send anything that is not an object, so it would be very convenient if objectMode would somehow work.
from websocket-stream.
The streams works in objectMode
, but it can only move buffers or strings. You do not have to check the length of the transmitted packet etc before decoding. Object encoding/decoding is left to you to do.
from websocket-stream.
Related Issues (20)
- no such file or directory, open 'stream' HOT 2
- Add an example of express-js HOT 2
- Not able to run test-server.js
- realtimecats.com doesn't work HOT 2
- [Question] Impact of Latency on websocket streams HOT 5
- [Question] How to measure bandwidth? HOT 3
- Error event emits without error object HOT 29
- The stream loses data HOT 4
- Flow control HOT 9
- Add TypeScript definitions? HOT 2
- Loses objectMode part of logic. Don't work cork/uncork HOT 11
- v5.2.0 is breaking ... can't say exactly what HOT 11
- Error event judgement in file 'stream.js'
- websocket-stream's TypeScript produces errors - ws package TypeScript updated. HOT 2
- Typescript createServer typing not correct HOT 1
- Typescript definition is broken if @types/express-ws is in the same package.json HOT 1
- Security vulnerability GHSA-6fc8-4gx4-v693 on ws ^3.2.0 dependency HOT 2
- Possibly deprecate in favor of ws::createWebSocketStream
- Frequent service clientError Error: invalid status code: 12592
- Security Vulnerability: CVE-2024-37890- Security Level: HIGH
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from websocket-stream.