tcp-socket
Advanced tools
Comparing version 0.3.11 to 0.3.12
{ | ||
"name": "tcp-socket", | ||
"version": "0.3.11", | ||
"version": "0.3.12", | ||
"main": "src/tcp-socket", | ||
@@ -5,0 +5,0 @@ "description": "This shim brings the W3C Raw Socket API to node.js and Chromium. Its purpose is to enable apps to use the same api in Firefox OS, Chrome OS, and on the server.", |
@@ -405,2 +405,3 @@ // Copyright (c) 2014 Whiteout Networks | ||
var _socket; | ||
var _hostname; | ||
@@ -547,2 +548,13 @@ /** | ||
}; | ||
TCPSocket.getHostname = function(callback) { | ||
if(_hostname){ | ||
return callback(null, _hostname); | ||
} | ||
_socket.emit('hostname', function(hostname) { | ||
_hostname = hostname; | ||
return callback(null, _hostname); | ||
}); | ||
}; | ||
} // end of wsShim | ||
@@ -549,0 +561,0 @@ |
@@ -55,3 +55,11 @@ define(function(require) { | ||
}); | ||
it('should return proxy hostname', function(done) { | ||
TcpSocket.getHostname(function(err, hostname) { | ||
expect(err).to.not.exist; | ||
expect(hostname).to.exist; | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); |
@@ -26,2 +26,3 @@ 'use strict'; | ||
stubIo.emit.withArgs('open').yields(42); | ||
stubIo.emit.withArgs('hostname').yields('hostname.io'); | ||
@@ -87,3 +88,13 @@ socket = TcpSocket.open('127.0.0.1', 9000, { | ||
}); | ||
describe('getHostname', function() { | ||
it('should return hostname', function(done) { | ||
TcpSocket.getHostname(function(err, hostname) { | ||
expect(err).to.not.exist; | ||
expect(hostname).to.equal('hostname.io'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
@@ -8,2 +8,3 @@ 'use strict'; | ||
var log = require('npmlog'); | ||
var os = require('os'); | ||
@@ -132,2 +133,6 @@ log.level = config.log.level; | ||
socket.on('hostname', function(fn) { | ||
fn(os.hostname()); | ||
}); | ||
socket.on('disconnect', function() { | ||
@@ -134,0 +139,0 @@ log.info('io', 'Closed connection [%s]', socket.conn.id); |
100252
2014