Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cwysong85/msrp-node-lib
A MSRP implementation in NodeJS
https://github.com/cwysong85/msrp-node-lib
Last synced: 3 days ago
JSON representation
A MSRP implementation in NodeJS
- Host: GitHub
- URL: https://github.com/cwysong85/msrp-node-lib
- Owner: cwysong85
- Created: 2018-04-25T18:39:37.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2024-01-02T19:12:31.000Z (about 1 year ago)
- Last Synced: 2024-04-17T06:39:35.683Z (10 months ago)
- Language: JavaScript
- Size: 149 KB
- Stars: 2
- Watchers: 3
- Forks: 4
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# A MSRP library for NodeJS applications
### Initialization
Create the MSRP library with minimal settings:
```
var msrp = require('msrp-node-lib')({
host: '127.0.0.1',
port: 2855,
traceMsrp: true,
sessionName: 'user-a',
acceptTypes: 'text/plain',
setup: 'active'
});
```You can also pass a custom `logger` to the MSRP library, otherwise the `console` logging methods are used. Here is an example of passing the custom logger to the MSRP library:
```
var winston = require('winston');var msrp = require('msrp-node-lib')(
{
host: '127.0.0.1',
port: 2855,
traceMsrp: true,
sessionName: 'user-a',
acceptTypes: 'text/plain',
setup: 'active'
}, new(winston.Logger)({
levels: {
debug: 0,
info: 1,
warning: 2,
error: 3
}
}));
```Start MSRP server:
```
// create msrp server
var msrpServer = new msrp.Server();// start server
msrpServer.start();
```### Events
Socket connected event and MSRP session events:
```
msrpServer.on('socketConnect', function(session) {
console.log('MSRP socket connected!');// create a session
var msrpSession = msrp.SessionController.createSession();// send a message from this session
msrpSession.sendMessage('Hello world!', function() {
console.log('Message sent!');
});// receive a message for this session
msrpSession.on('message', function(msg) {
console.log('Body: ' + msg.body)
});});
```Other useful socket events:
```
msrpServer.on('socketTimeout', function() {
console.log('MSRP socket timed out');
});msrpServer.on('socketError', function() {
console.log('MSRP socket error');
});msrpServer.on('socketClose', function() {
console.log('MSRP socket closed');
});
```