In the above example we automatically create a HTTP server which will listenon port 8080, a primus instance with the websockets transformer and startlistening for incoming connections. The supplied function in thePrimus.createServer method is optional. You can just listen for incomingconnections your self using the returned Primus instance. If you want to listen toa HTTPS or SPDY server, which is recommended, you can directly pass the SPDY andHTTPS certs/keys/pfx files in the options object:
As you can see, it will use the /primus pathname by default. Primus needs toown the whole path/namespace in order to function properly as it will forwardall other requests directly in to the transformers so they can work their magic.If you already have a static folder with the name primus you can change thepathname to something different and still make this work. But you would ofcourse need to update the src attribute of the script tag to set the correctlocation. It's always available at:
If you want to manually control the reconnection you can call primus.end()to close the connection and primus.open() to establish a new one. Be sureto use primus.open() correctly, see below for details.
When you want to close the connection you can call the primus.end() method.After this the connection should be considered dead and a new connection needsto be made using Primus.connect(url) or primus = new Primus(url) if you wantto talk with the server again.
This method literally destroys the primus instance. Internally it calls theprimus.end() method but it also frees some potentially heavy objects likethe underlying socket, the timers, the message transformers, etc. It alsoremoves all the event listeners but before doing that it emits a final destroyevent. Keep in mind that once this method is executed, you can no longer useprimus.open() on the same primus instance.
When you've created your primus instance you can access the Socketproperty on it. This Socket is automatically configured to connect to thecorrect pathname, using the same transformer and parser that you'vespecified when you created your primus instance.
You might need to connect from a different node process where you don't haveaccess to your primus instance and the compatible Socket instance. Forthese cases there a special createSocket method where you can specify thetransformer, parser, plugin that you are using on your server to createanother compatible socket.
When you are using plugins with Primus make sure you add them before youreference the primus.Socket or it will compile a client without your plugins.If you're using the Primus.createSocket api you can directly supply theplugins as part of the options as it supports plugin object:
The constructor returned by primus.Socket or Primus.createSocket has thesame signature of the constructor used to connect from the browser. Thismeans that you can use all the options mentioned in the previoussection:
In rare cases you might need to destroy the Primus instance you've created. Youcan use the primus.destroy() or primus.end() method for this. This methodaccepts an Object which allows you to configure the destruction process:
The heartbeat message that we send over the connection isprimus::ping::. Upon receipt of this message, the client will sendback a primus::pong:: message with the same itreceived from the server.This allows to calculate the latency between messages by simply gettingthe and comparing it with the local time.
The primus.use method is how you add middleware layers to your system. Allmiddleware layers need to be named. This allows you to also enable, disable andremove middleware layers. The supplied function can either be a pre-configuredfunction that is ready to answer request/response or an unconfiguredmiddleware. An unconfigured middleware is a function with less then 2 arguments.We execute this function automatically with Primus as context of the functionand optionally, the options that got provided:
This method allows you to remove configured middleware. This worksfor the middleware layers that you added but also the middleware layers that weadd by default. If you want to use a different way to serve the primus.jsfile you can simply:
Require.js is supported to a certain degree. The primus.js core file should becompatible with require.js but it could be that the transformer of your choosingisn't compatible with require.js. For example engine.io uses component whichintroduces it's own require function that causes issues. In addition to that,there are plugins which might use these modules that break require.js. Thegeneral advice for this is to drop require.js in favour of plain script loadingor use of browserify where possible. If you feel strong about require.js we acceptpull requests that improve this behaviour or helps us save guard against theseissues.
Primus uses some internal protocol messages in order to keep the connection openand stable between a client and a server. If you are planning on implementingPrimus in another language you must handle the following primus::* prefixedmessages:
I noticed:
1) primus in official repos (I was using git so far) causes a timeout from about 40 mirrors until it finds one where the download works. I hope that's no bad sign of some sort?
2) bumblebeed update created new bumblebee.conf.pacnew and xorg.conf.nvidia.pacnew
3) off-topic: When I clicked 'logout' in XFCE's applications menu, usually I get a box where I can pick whether I wanna logout/restart/shutdown etc, but this time it just straightly logged me out (makes sense I guess).
4) after rebooting my system I saw I think two systemd error messages pop up for a split second, that usually did not occur.
5) Xorg.8.log had the line "[633217.731] (WW) NVIDIA: This server has an unsupported input driver ABI version (have 19.1, need < 19.0). The driver will continue to load, but may behave strangely.", is this responsible maybe? Version conflict between X and nvidia?
I tried:
I restarted after the pacman -Syu update.
I tried primusrun-git from AUR and primusrun from but both exit with the error message.
I tried the new conf files (copied the pacnew files to the normal filenames) but they don't work either.
So I removed all of the *-bumblebee packages and tried to install the regular packages. I noticed that even with multilib repo enabled there is no longer a "lib32-nvidia-utils". To clarify, were you guys able to get bumblebee working with lib32-primus-git with the * packages? I am at work atm but I will try to get more details in a bit.
I recently installed Ubuntu 14.04 and then installed bumblebee following the instructions on Ubuntu Bumblebee wiki(where they said that primusrun is better than optirun for version=> 13.10) But when I rebooted and tried to run primusrun with any applications (except google-chrome and firefox) the following error came(and comes):
df19127ead