Giter VIP home page Giter VIP logo

substream's People

Contributors

3rd-eden avatar aslakhellesoy avatar greenkeeper[bot] avatar lpinca avatar thapar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

substream's Issues

'connection' event similar to mux-demux?

Is it possible, with this library, to catch the creation of a substream on the server or client side, without knowing the name of that stream beforehand? For example, this can be done with mux-demux, in combination with SockJS/Shoe.

Substreams cannot write from server to client if using binary parser

Easy to replicate with a slight modification to the example code:

primus = new Primus(server, {
  transformer: 'engine.io',
  parser: 'binary', // <- added to example
});

primus.use('substream', require('../'));

// stuff...

var foo = spark.substream('foo');
foo.on('data', function(data) {
  console.log('foo received:', data, ++count, spark.id);

  // Not received on the client, no errors on server, just quietly eats data
  foo.write('Curse your sudden but inevitable betrayal');
});

Support different parser type than parent spark

I found this module hoping that it would help me send multiple different types of data over a single Primus spark, i.e. send JSON encoded data over the spark, and create a substream to send binary data.

I don't think substream allows for me to select a different parser type per individual substream β€” though I may be missing something β€” and I think it would make Primus as a whole a far more useful tool.

separate en/de-coder for substreams

can I use different parsers for separate substeams (and main stream)? If yes, how do I do that?

I have Parser object instantiated on the server side with default JSON parser.

Can I simply use a new substream for binary data?

An in-range update of ws is breaking the build 🚨

The devDependency ws was updated from 7.0.0 to 7.0.1.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

ws is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ❌ continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

Commits

The new version differs by 9 commits.

  • 38d3bf2 [dist] 7.0.1
  • a0af764 [test] Use the correct value for the Content-Length header
  • b086179 [fix] Allow to disable sending the SNI extension (#1587)
  • e9e8ba5 [pkg] Update eslint-config-prettier to version 5.0.0 (#1588)
  • 36ef757 [doc] Add missing dependency in code snippet (#1581)
  • 911bb6f [minor] Fix typo in JSDoc comment (#1565)
  • 8050d5f [lint] Enable quotes rule
  • 995c527 [test] Enable --throw-deprecation
  • fbc077b [test] Do not use the deprecated outgoingMessage._headers property

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

On Data Event Raised by all connected sockets?

This might be a misunderstanding from my part, but I am seeing something that I didn't expect.

When I have multiple sockets open using a specific substream name, the 'data' event is raised by all connected sparks.

This is my server code.

var Primus = require('primus');
var http = require('http');
var server = http.createServer();
var primus = new Primus(server, { transformer: 'engine.io' });
var messageCount = 0;

primus.use('substream', require('substream'));
primus.on('connection', function (spark) {
  var foo = spark.substream('foo');
  foo.on('data', function (data) {
    console.log('foo received:', data, ++messageCount, spark.id);
  });
});

server.listen(8888);

This is my html.

<html>
  <head>
    <script src="http://localhost:8888/primus/primus.js"></script>
  </head>
<body></body>
<script type="text/javascript">
  var primus = new Primus('http://localhost:8888/');
  var foo = primus.substream('foo');
  foo.write('Hello Server');
</script>
</html>

When I load this page in my browser I see the first log in my terminal. (2 lines printed)

foo received: Hello Server 1 --F8_bZYwr1M2Zn8AAAA
foo received: Hello Server 2 3Hq4WEgPvV9xzDrwAAAB

Which is strange as there are 2 connections initially.
Then if I load the page in another tab I see (3 lines printed)

foo received: Hello Server 1 --F8_bZYwr1M2Zn8AAAA
foo received: Hello Server 2 3Hq4WEgPvV9xzDrwAAAB
foo received: Hello Server 3 --F8_bZYwr1M2Zn8AAAA
foo received: Hello Server 4 3Hq4WEgPvV9xzDrwAAAB
foo received: Hello Server 5 481alrq5N2ZiQ1acAAAC

Finally opening it in a third tab I see. (4 lines printed)

foo received: Hello Server 1 --F8_bZYwr1M2Zn8AAAA
foo received: Hello Server 2 3Hq4WEgPvV9xzDrwAAAB
foo received: Hello Server 3 --F8_bZYwr1M2Zn8AAAA
foo received: Hello Server 4 3Hq4WEgPvV9xzDrwAAAB
foo received: Hello Server 5 481alrq5N2ZiQ1acAAAC
foo received: Hello Server 6 --F8_bZYwr1M2Zn8AAAA
foo received: Hello Server 7 3Hq4WEgPvV9xzDrwAAAB
foo received: Hello Server 8 481alrq5N2ZiQ1acAAAC
foo received: Hello Server 9 kFJWh69Z3NVG-vHEAAAD

To clarify, I was expecting the behaviour to be the same as if I was just using Primus plainly.

Server code:

var Primus = require('primus');
var http = require('http');

var server = http.createServer();
var primus = new Primus(server, { transformer: 'engine.io' });
var messageCount = 0;

primus.on('connection', function (spark) {

  spark.on('data', function (data) {
    console.log('spark received:', data, ++messageCount, spark.id);
  });
});

server.listen(8888);

HTML:

<html>
  <head>
    <script src="http://localhost:8888/primus/primus.js"></script>
  </head>
<body></body>
<script type="text/javascript">
  var primus = new Primus('http://localhost:8888/');
  primus.write('Hello Server');
</script>
</html>

Page 1 connected: (1 line printed)

spark received: Hello Server 1 cbK6fVNVsJBOqEhdAAAF

Page 2 connected: (1 line printed)

spark received: Hello Server 1 cbK6fVNVsJBOqEhdAAAF
spark received: Hello Server 2 tdM0a0Ze-GvBR2WpAAAG

Page 3 connected: (1 line printed)

spark received: Hello Server 1 cbK6fVNVsJBOqEhdAAAF
spark received: Hello Server 2 tdM0a0Ze-GvBR2WpAAAG
spark received: Hello Server 3 gOXoShlr8WPFurAdAAAH

Is this expected behaviour?

Is it possible to authorize on substream level?

Firstly thanks for nice work.

Is it possible to authorize on substream level?

I would like to create two namespaces: public and private.

Public should be accessible without any authorization and private should be allowed to access only for authorized users only.

From primus docs I see authorize is on primus top level.

primus.authorize(...);

And substreams are initiated on connection (after authorization)

  primus.on('connection', function(spark) {
    var public = spark.substream('public');
    var private = spark.substream('private');

    // my goal is to do authorization for private substream only
   private.authorize(...); // not sure if this is possible
 }

An in-range update of ws is breaking the build 🚨

The devDependency ws was updated from 6.1.0 to 6.1.1.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

ws is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ❌ continuous-integration/travis-ci/push: The Travis CI build failed (Details).

Release Notes for 6.1.1

Bug fixes

  • Queued messages, when permessage-deflate is enabled, are now discarded if the
    socket closes prematurely (#1464, #1471).
Commits

The new version differs by 15 commits.

  • 029de0c [dist] 6.1.1
  • b213bee [pkg] Update list of published files
  • 95bf991 [pkg] Update dev dependencies
  • f26fac8 [minor] Ignore callbacks when clearing the send queue (#1471)
  • 5914206 [doc] Fix nits
  • 3fa0e03 [doc] Suggest implementation of heartbeat on the client (#1469)
  • 7d51fb9 [fix] Do not waste time compressing when socket is closed (#1464)
  • 1ebff19 [ci] Test on node 11
  • 7e061bc [pkg] Update nyc to version 13.1.0
  • bc0f8ab [pkg] Update eslint to version 5.8.0
  • 45f817b chore(package): update eslint-plugin-node to version 8.0.0 (#1466)
  • cddbcf6 [test] Remove unused variables
  • 0da3fdb [minor] Do not use the legacy URL API
  • d2317b1 [benchmark] Add Unix domain sockets to bench (#1456)
  • 9022a0d [doc] Remove clientMaxWindowBits option from README example (#1454)

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

client pipe?

The client library is missing a "pipe" function. Is this a planned future addition?

`error` event support

Is there a reason why substreams do not support passing error events from server to client?

`npm test` fails

> NODE_ENV=testing ./node_modules/.bin/mocha $(find test -name '*.test.js')



  multi-stream
    βœ“ is compatible as a server-side plugin 
    βœ“ is compatible as a client-side plugin 
    communication
      1) can communicate over a substream
      2) proxies the close events
      3) also receives data on the client side
      4) doesnt confuse multiple streams
      5) only emits the events once


  2 passing (170ms)
  5 failing

  1) multi-stream communication can communicate over a substream:
     ReferenceError: substream is not defined
      at Primus.client (primus.js:1326:19)
      at Primus.initalise [as initialise] (primus.js:606:24)
      at new Primus (primus.js:305:10)
      at Context.<anonymous> (/Users/ahellesoy/github/cucumber-ltd/substream/test/substream.test.js:55:20)
      at Test.Runnable.run (/Users/ahellesoy/github/cucumber-ltd/substream/node_modules/mocha/lib/runnable.js:194:15)
      at Runner.runTest (/Users/ahellesoy/github/cucumber-ltd/substream/node_modules/mocha/lib/runner.js:358:10)
      at /Users/ahellesoy/github/cucumber-ltd/substream/node_modules/mocha/lib/runner.js:404:12
      at next (/Users/ahellesoy/github/cucumber-ltd/substream/node_modules/mocha/lib/runner.js:284:14)
      at /Users/ahellesoy/github/cucumber-ltd/substream/node_modules/mocha/lib/runner.js:293:7
      at next (/Users/ahellesoy/github/cucumber-ltd/substream/node_modules/mocha/lib/runner.js:237:23)

  2) multi-stream communication proxies the close events:
     ReferenceError: substream is not defined
      at Primus.client (primus.js:1326:19)
      at Primus.initalise [as initialise] (primus.js:606:24)
      at new Primus (primus.js:305:10)
      at Context.<anonymous> (/Users/ahellesoy/github/cucumber-ltd/substream/test/substream.test.js:84:20)
      at Test.Runnable.run (/Users/ahellesoy/github/cucumber-ltd/substream/node_modules/mocha/lib/runnable.js:194:15)
      at Runner.runTest (/Users/ahellesoy/github/cucumber-ltd/substream/node_modules/mocha/lib/runner.js:358:10)
      at /Users/ahellesoy/github/cucumber-ltd/substream/node_modules/mocha/lib/runner.js:404:12
      at next (/Users/ahellesoy/github/cucumber-ltd/substream/node_modules/mocha/lib/runner.js:284:14)
      at /Users/ahellesoy/github/cucumber-ltd/substream/node_modules/mocha/lib/runner.js:293:7
      at next (/Users/ahellesoy/github/cucumber-ltd/substream/node_modules/mocha/lib/runner.js:237:23)

  3) multi-stream communication also receives data on the client side:
     ReferenceError: substream is not defined
      at Primus.client (primus.js:1326:19)
      at Primus.initalise [as initialise] (primus.js:606:24)
      at new Primus (primus.js:305:10)
      at Context.<anonymous> (/Users/ahellesoy/github/cucumber-ltd/substream/test/substream.test.js:109:20)
      at Test.Runnable.run (/Users/ahellesoy/github/cucumber-ltd/substream/node_modules/mocha/lib/runnable.js:194:15)
      at Runner.runTest (/Users/ahellesoy/github/cucumber-ltd/substream/node_modules/mocha/lib/runner.js:358:10)
      at /Users/ahellesoy/github/cucumber-ltd/substream/node_modules/mocha/lib/runner.js:404:12
      at next (/Users/ahellesoy/github/cucumber-ltd/substream/node_modules/mocha/lib/runner.js:284:14)
      at /Users/ahellesoy/github/cucumber-ltd/substream/node_modules/mocha/lib/runner.js:293:7
      at next (/Users/ahellesoy/github/cucumber-ltd/substream/node_modules/mocha/lib/runner.js:237:23)

  4) multi-stream communication doesnt confuse multiple streams:
     ReferenceError: substream is not defined
      at Primus.client (primus.js:1326:19)
      at Primus.initalise [as initialise] (primus.js:606:24)
      at new Primus (primus.js:305:10)
      at Context.<anonymous> (/Users/ahellesoy/github/cucumber-ltd/substream/test/substream.test.js:142:20)
      at Test.Runnable.run (/Users/ahellesoy/github/cucumber-ltd/substream/node_modules/mocha/lib/runnable.js:194:15)
      at Runner.runTest (/Users/ahellesoy/github/cucumber-ltd/substream/node_modules/mocha/lib/runner.js:358:10)
      at /Users/ahellesoy/github/cucumber-ltd/substream/node_modules/mocha/lib/runner.js:404:12
      at next (/Users/ahellesoy/github/cucumber-ltd/substream/node_modules/mocha/lib/runner.js:284:14)
      at /Users/ahellesoy/github/cucumber-ltd/substream/node_modules/mocha/lib/runner.js:293:7
      at next (/Users/ahellesoy/github/cucumber-ltd/substream/node_modules/mocha/lib/runner.js:237:23)

  5) multi-stream communication only emits the events once:
     ReferenceError: substream is not defined
      at Primus.client (primus.js:1326:19)
      at Primus.initalise [as initialise] (primus.js:606:24)
      at new Primus (primus.js:305:10)
      at /Users/ahellesoy/github/cucumber-ltd/substream/test/substream.test.js:187:22
      at Array.forEach (native)
      at Context.<anonymous> (/Users/ahellesoy/github/cucumber-ltd/substream/test/substream.test.js:186:14)
      at Test.Runnable.run (/Users/ahellesoy/github/cucumber-ltd/substream/node_modules/mocha/lib/runnable.js:194:15)
      at Runner.runTest (/Users/ahellesoy/github/cucumber-ltd/substream/node_modules/mocha/lib/runner.js:358:10)
      at /Users/ahellesoy/github/cucumber-ltd/substream/node_modules/mocha/lib/runner.js:404:12
      at next (/Users/ahellesoy/github/cucumber-ltd/substream/node_modules/mocha/lib/runner.js:284:14)



npm ERR! Test failed.  See above for more details.
npm ERR! not ok code 0

Perhaps primus changed since last time Travis ran the tests?

Compatibility with primus-callbacks

Hi there,

wondering if it's possible to make primus-callbacks work on a substream? It currently works on main stream and I believe it's only about writing implementation for primus-callbacks writeAndWait method.

  /**
   * Write a new message to the streams and wait for response
   *
   * @param {Mixed} msg The data that needs to be written.
   * @param {Func} done nodejs style callback (err, response)
   * @returns {Boolean}
   * @api public
   */
SubStream.prototype.writeAndWait = function write(msg, done) {
  // TODO: implementation here
};

I'll try to implement it myself, but I'm bit lost in how transform works. What does this code actually do?

  /**
   * Write a new message to the streams.
   *
   * @param {Mixed} msg The data that needs to be written.
   * @returns {Boolean}
   * @api public
   */
  SubStream.prototype.write = function write(msg) {
    if (!this.stream) return false;

    this.stream.transforms(this.primus, this, 'outgoing', msg);
    return true;
  };

and when this get invoked?


  /**
   * Actually write the message.
   *
   * @param {Mixed} msg The data that needs to be written.
   * @returns {Boolean}
   * @api private
   */
  SubStream.prototype._write = function write(msg) {
    return this.stream._write({
      substream: this.name,
      args: msg
    });
  };

Thanks

Uncaught TypeError: primus.substream is not a function

getting the following error:

Uncaught TypeError: primus.substream is not a function

at line 2 below:

   primus.on( 'open', function(){
      var i = primus.substream( 'i' );      
      i.write( 'Dahi Dahi' );   
    });       

I have saved a new library with substream plugin on server side

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.