Primus-client
This is a prebuilt primus client-side library with default options. It does not come pre-minified as that is out of the scope of this project.
Link to the full library
https://www.npmjs.com/package/primus
Example client-side code
// can be used with feathers (optional);// can be used with feathers (optional);;; const protocol = `ws:`; const connectionString = `//`; const socket = connectionString protocol; // can be used with feathers (optional)const app = ; // can be used with feathers (optional)app; // you can add token for auth or other query paramssocket; { if !args2 ; socket;} const data = test: true; // provides an optional callback to the request if you match the server response type and id like:// spark.write({// type: 1,// data: [null, msg],// id,// });; // listen to custom server response messages like:// spark.write({// type: 0,// data: ['someResponseType', msg],// });socket;
The following options are built-in (can NOT be changed):
Name | Description | Default |
---|---|---|
authorization | Authorization handler | null |
pathname | The URL namespace that Primus can own | /primus |
parser | Message encoder for all communication | JSON |
transformer | The transformer we should use internally | websockets |
plugin | The plugins that should be applied | {} |
pingInterval | Interval at which heartbeats are sent | 30000 |
global | Set a custom client class / global name | Primus |
compression | Use permessage-deflate / HTTP compression | false |
maxLength | Maximum allowed packet size, in bytes | 10485760 |
transport | Transformer specific configuration | {} |
idGenerator | Custom spark id generator function | undefined |
origins | cors List of origins | * |
methods | cors List of accepted HTTP methods | GET,HEAD,PUT,POST,DELETE,OPTIONS |
credentials | cors Allow sending of credentials | true |
maxAge | cors Cache duration of CORS preflight | 30 days |
headers | cors Allowed headers | false |
exposed | cors Headers exposed to the client | false |