Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

phonegap-soundwave

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

phonegap-soundwave - npm Package Compare versions

Comparing version 0.1.0 to 0.2.0

lib/middleware.js

63

lib/index.js

@@ -5,3 +5,4 @@ /*!

var Static = require('node-static'),
var middleware = require('./middleware'),
http = require('http'),
events = require('events'),

@@ -11,4 +12,34 @@ emitter = new events.EventEmitter();

/**
* Serve the App.
* Request Listener or Middleware.
*
* Returns a `Function` that can be provided to `http.Server` or
* can act as `connect` middleware.
*
* Example:
*
* var soundwave = require('phonegap-soundwave');
*
* // use as middleware
* app.use(soundwave());
*
* // use as request listener
* http.createServer(soundwave()).listen(3000);
*/
module.exports = middleware;
/**
* Listen for connections.
*
* A convenience method to start a node `http.Server` instance.
*/
module.exports.listen = function() {
var server = http.createServer(middleware());
return server.listen.apply(server, arguments);
};
/**
* Serve a PhoneGap app.
*
* Creates a local server to serve up the project. The intended

@@ -27,5 +58,4 @@ * receiver is the PhoneGap App but any browser can consume the

module.exports.serve = function(options, callback) {
var self = this,
file = new Static.Server('./www');
var self = this;
// require options

@@ -37,12 +67,6 @@ if (!options) throw new Error('requires option parameter');

callback = callback || function() {};
// create the server
var server = require('http').createServer(function (request, response) {
// server the static file
file.serve(request, response, function(e, response) {
if (e) response = e; // e.status = 404
module.exports.emit('log', response.status, request.url);
});
});
// start the server
var server = module.exports.listen(options.port);
// bind error

@@ -54,4 +78,10 @@ server.on('error', function(e) {

// bind request
server.on('request', function(req, res) {
module.exports.emit('log', res.statusCode, req.url);
});
// bind complete
server.on('listening', function() {
module.exports.emit('log', 'listening on 127.0.0.1:' + options.port);
callback(null, {

@@ -62,5 +92,2 @@ address: '127.0.0.1',

});
// start the server
server.listen(options.port);
};

@@ -88,2 +115,2 @@

module.exports.on('error', function(e){});
module.exports.on('error', function(e){});
{
"name": "phonegap-soundwave",
"description": "Stream a PhoneGap app to any device.",
"version": "0.1.0",
"description": "Connect middleware to stream a PhoneGap app.",
"version": "0.2.0",
"homepage": "https://github.com/phonegap/node-phonegap-soundwave",

@@ -22,6 +22,9 @@ "repository": {

"dependencies": {
"connect": "2.12.0",
"node-static": "0.7.0"
},
"devDependencies": {
"jasmine-node": "1.8.0"
"chdir": "0.0.0",
"jasmine-node": "1.8.0",
"supertest": "0.8.3"
},

@@ -28,0 +31,0 @@ "optionalDependencies": {

@@ -1,2 +0,36 @@

node-phonegap-soundwave
=======================
# phonegap-soundwave
> Connect middleware to stream a PhoneGap app.
## Examples
### Standalone
var soundwave = require('phonegap-soundwave');
soundwave.listen(3000);
### Express
var soundwave = require('phonegap-soundwave'),
express = require('express'),
app = express();
app.use(soundwave());
app.listen(3000);
### Connect
var soundwave = require('phonegap-soundwave'),
connect = require('connect'),
app = connect();
app.use(soundwave());
app.listen(3000);
### HTTP
var soundwave = require('phonegap-soundwave'),
http = require('http');
var server = http.createServer(soundwave());
server.listen(3000);

@@ -6,11 +6,47 @@ /*!

var soundwave = require('../lib'),
middleware = require('../lib/middleware'),
http = require('http'),
events = require('events'),
Static = require('node-static'),
serverSpy,
serveSpy,
request,
options;
/*!
* Specification: soundwave
*/
describe('soundwave', function() {
it('should be the middleware generator function', function() {
expect(soundwave).toEqual(middleware);
});
});
/*!
* Specification: soundwave.listen(port, [options])
*/
describe('soundwave.listen(port, [options])', function() {
beforeEach(function() {
spyOn(http, 'createServer').andCallFake(function() {
serverSpy = new events.EventEmitter();
serverSpy.listen = jasmine.createSpy().andReturn(serverSpy);
return serverSpy;
});
});
it('should create server using the middleware', function() {
soundwave.listen(3000);
expect(http.createServer).toHaveBeenCalledWith(jasmine.any(Function));
});
it('should pass arguments into Server.listen', function() {
soundwave.listen(1, 2, 3);
expect(serverSpy.listen).toHaveBeenCalledWith(1, 2, 3);
});
it('should return the server instance', function() {
expect(soundwave.listen(3000)).toEqual(serverSpy);
});
});
/*!
* Specification: soundwave.serve(options, [callback])

@@ -22,16 +58,6 @@ */

options = {};
// mock the http.createServer
spyOn(http, 'createServer').andCallFake(function(callback) {
request = new events.EventEmitter();
request.url = '/some/path';
spyOn(soundwave, 'listen').andCallFake(function() {
serverSpy = new events.EventEmitter();
serverSpy.listen = jasmine.createSpy();
callback(request, { status: 200 }); // bind routes
return serverSpy;
});
// mock node-static
serveSpy = jasmine.createSpy('file.serve');
spyOn(Static, 'Server').andReturn({
serve: serveSpy
});
});

@@ -59,11 +85,11 @@

it('should try to serve the project', function() {
it('should try to create the server', function() {
soundwave.serve(options);
expect(http.createServer).toHaveBeenCalled();
expect(soundwave.listen).toHaveBeenCalled();
});
describe('when successfully started server', function() {
describe('when successfully created server', function() {
it('should listen on the default port (3000)', function() {
soundwave.serve(options);
expect(serverSpy.listen).toHaveBeenCalledWith(3000);
expect(soundwave.listen).toHaveBeenCalledWith(3000);
});

@@ -74,3 +100,3 @@

soundwave.serve(options);
expect(serverSpy.listen).toHaveBeenCalledWith(1337);
expect(soundwave.listen).toHaveBeenCalledWith(1337);
});

@@ -90,17 +116,10 @@

describe('on request', function() {
it('should serve a response', function() {
soundwave.serve(options, function(e) {});
request.emit('end');
expect(serveSpy).toHaveBeenCalled();
});
it('should emit a "log" event', function(done) {
serveSpy.andCallFake(function(request, response, callback) {
callback(null, { status: 200 });
});
soundwave.on('log', function(request, response) {
soundwave.on('log', function(statusCode, url) {
expect(statusCode).toEqual(200);
expect(url).toEqual('/a/file');
done();
});
soundwave.serve(options);
request.emit('end');
serverSpy.emit('request', { url: '/a/file' }, { statusCode: 200 });
});

@@ -110,3 +129,3 @@ });

describe('when failed to start server', function() {
describe('when failed to create server', function() {
it('should trigger callback with an error', function(done) {

@@ -113,0 +132,0 @@ soundwave.serve(options, function(e) {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc