Package Exports
- msrp-node-lib
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (msrp-node-lib) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
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');
});
msrpServer.on('socketEnd', function() {
console.log('MSRP socket ended');
});