Permalink
Browse files

Reformat source to npm.im/standard format

  • Loading branch information...
1 parent a5254d1 commit 0c8378912e00c3c2798d4cb896e8697b0f9ddb79 jden committed Nov 21, 2015
Showing with 988 additions and 891 deletions.
  1. +9 −9 api/api.js
  2. +25 −28 api/apis/radar.js
  3. +22 −25 api/lib/client.js
  4. +15 −16 api/lib/router.js
  5. +11 −12 client/client.js
  6. +1 −1 configuration.js
  7. +24 −25 configurator.js
  8. +5 −5 core/index.js
  9. +3 −3 core/lib/resources/message_list/index.js
  10. +25 −24 core/lib/resources/presence/index.js
  11. +28 −26 core/lib/resources/presence/presence_manager.js
  12. +14 −13 core/lib/resources/presence/presence_store.js
  13. +29 −29 core/lib/resources/presence/sentry.js
  14. +4 −5 core/lib/resources/resource.js
  15. +3 −3 core/lib/resources/status/index.js
  16. +11 −11 core/lib/resources/stream/index.js
  17. +3 −3 core/lib/type.js
  18. +3 −3 core/stamper.js
  19. +6 −6 middleware/legacy_auth_manager.js
  20. +5 −4 middleware/quota_limiter.js
  21. +9 −9 middleware/quota_manager.js
  22. +5 −4 middleware/runner.js
  23. +7 −2 package.json
  24. +2 −0 readme.md
  25. +5 −6 sample/server.js
  26. +21 −21 sample/views.js
  27. +5 −5 server.js
  28. +32 −33 server/server.js
  29. +5 −9 tests/client.auth.test.js
  30. +6 −5 tests/client.connect.test.js
  31. +28 −30 tests/client.message.test.js
  32. +22 −22 tests/client.presence.remote.test.js
  33. +17 −19 tests/client.presence.sentry.test.js
  34. +31 −32 tests/client.presence.test.js
  35. +11 −9 tests/client.rate_limit.test.js
  36. +17 −19 tests/client.reconnect.test.js
  37. +21 −19 tests/client.status.test.js
  38. +22 −20 tests/client.stream.test.js
  39. +26 −23 tests/client.test.js
  40. +16 −17 tests/common.js
  41. +14 −16 tests/configurator.test.js
  42. +61 −55 tests/lib/assert_helper.js
  43. +2 −2 tests/lib/formatter.js
  44. +22 −24 tests/lib/radar.js
  45. +13 −9 tests/message_list.unit.test.js
  46. +29 −26 tests/presence.remote.test.js
  47. +107 −34 tests/presence.unit.test.js
  48. +10 −9 tests/quota_limiter.test.js
  49. +35 −34 tests/quota_manager.test.js
  50. +40 −29 tests/radar_api.test.js
  51. +26 −24 tests/sentry.unit.test.js
  52. +27 −27 tests/server.auth.unit.test.js
  53. +14 −14 tests/server.middleware.unit.test.js
  54. +15 −18 tests/server.unit.test.js
  55. +6 −5 tests/stamper.test.js
  56. +13 −10 tests/status.unit.test.js
View
@@ -1,11 +1,11 @@
-var hostname = require('os').hostname(),
- Router = require('./lib/router.js'),
- RadarApi = require('./apis/radar.js')
+var hostname = require('os').hostname()
+var Router = require('./lib/router.js')
+var RadarApi = require('./apis/radar.js')
var api = new Router()
function homepage (req, res) {
- res.setHeader('Content-Type', 'text/plain'); // IE will otherwise try to save the response instead of just showing it.
+ res.setHeader('Content-Type', 'text/plain') // IE will otherwise try to save the response instead of just showing it
res.end(JSON.stringify({ pong: 'Radar running at ' + hostname }))
}
@@ -16,10 +16,10 @@ api.get(/^\/engine.io\/ping.*$/, homepage)
// Radar API
-api.post(new RegExp('^/radar/status'), RadarApi.setStatus)
-api.get(new RegExp('^/radar/status'), RadarApi.getStatus)
-api.post(new RegExp('^/radar/message'), RadarApi.setMessage)
-api.get(new RegExp('^/radar/message'), RadarApi.getMessage)
-api.get(new RegExp('^/radar/presence(.*)'), RadarApi.getPresence)
+api.post(/^\/radar\/status/, RadarApi.setStatus)
+api.get(/^\/radar\/status/, RadarApi.getStatus)
+api.post(/^\/radar\/message/, RadarApi.setMessage)
+api.get(/^\/radar\/message/, RadarApi.getMessage)
+api.get(/^\/radar\/presence(.*)/, RadarApi.getPresence)
module.exports = api
View
@@ -1,10 +1,10 @@
-var url = require('url'),
- Status = require('../../core').Status,
- MessageList = require('../../core').MessageList,
- Presence = require('../../core').Presence,
- PresenceManager = require('../../core').PresenceManager,
- Type = require('../../core').Type,
- hostname = require('os').hostname()
+var url = require('url')
+var Status = require('../../core').Status
+var MessageList = require('../../core').MessageList
+var Presence = require('../../core').Presence
+var PresenceManager = require('../../core').PresenceManager
+var Type = require('../../core').Type
+var hostname = require('os').hostname()
function jsonResponse (response, object) {
response.setHeader('Content-type', 'application/json')
@@ -15,10 +15,10 @@ function jsonResponse (response, object) {
function parseData (response, data, ResourceType) {
var parameters = data
- if (typeof data == 'string') {
+ if (typeof data === 'string') {
try {
parameters = JSON.parse(data)
- } catch(e) {
+ } catch (e) {
parameters = false
}
}
@@ -27,9 +27,9 @@ function parseData (response, data, ResourceType) {
return jsonResponse(response, {})
}
- var resourceTo = ResourceType.prototype.type + ':/' + parameters.accountName + '/' + parameters.scope,
- options = Type.getByExpression(resourceTo),
- resource = new ResourceType(resourceTo, {}, options)
+ var resourceTo = ResourceType.prototype.type + ':/' + parameters.accountName + '/' + parameters.scope
+ var options = Type.getByExpression(resourceTo)
+ var resource = new ResourceType(resourceTo, {}, options)
resource.accountName = parameters.accountName
resource.scope = parameters.scope
@@ -56,7 +56,7 @@ function setStatus (req, res, re, data) {
op: 'set',
to: status.to,
key: status.key,
- value: status.value,
+ value: status.value
}, status.options.policy || {}, function () {
jsonResponse(res, {})
})
@@ -65,8 +65,8 @@ function setStatus (req, res, re, data) {
// curl -k "https://localhost/radar/status?accountName=test&scope=ticket/1"
function getStatus (req, res) {
- var parts = url.parse(req.url, true),
- status = parseData(res, parts.query, Status)
+ var parts = url.parse(req.url, true)
+ var status = parseData(res, parts.query, Status)
if (status) {
status._get('status:/' + status.accountName + '/' + status.scope, function (replies) {
@@ -95,8 +95,8 @@ function setMessage (req, res, re, data) {
}
function getMessage (req, res) {
- var parts = url.parse(req.url, true),
- message = parseData(res, parts.query, MessageList)
+ var parts = url.parse(req.url, true)
+ var message = parseData(res, parts.query, MessageList)
if (message) {
message._sync(message.to, message.options.policy || {}, function (replies) {
@@ -114,30 +114,27 @@ function getMessage (req, res) {
// - Response for single scope: { userId: { "clients": { clientId1: {}, clientId2: {} }, userType: } }
// - Response for multiple scopes: { scope1: ... above ..., scope2: ... above ... }
function getPresence (req, res) {
- var parts = url.parse(req.url, true),
- q = parts.query
- if (!q || !q.accountName) { return res.end(); }
- if (!(q.scope || q.scopes)) { return res.end(); }
- var versionNumber = parseInt(q.version)
+ var parts = url.parse(req.url, true)
+ var q = parts.query
+ if (!q || !q.accountName) { return res.end() }
+ if (!(q.scope || q.scopes)) { return res.end() }
+ var versionNumber = parseInt(q.version, 10)
// Sadly, the responses are different when dealing with multiple scopes so can't just put these in a control flow
if (q.scope) {
var monitor = new PresenceManager('presence:/' + q.accountName + '/' + q.scope, {}, Presence.sentry)
monitor.fullRead(function (online) {
res.setHeader('Content-type', 'application/json')
res.setHeader('Cache-Control', 'no-cache')
res.setHeader('X-Radar-Host', hostname)
-
-
-
if (versionNumber === 2) {
res.end(JSON.stringify(monitor.getClientsOnline()) + '\n')
} else {
res.end(JSON.stringify(online) + '\n')
}
})
} else {
- var scopes = q.scopes.split(','),
- result = {}; // key: scope - value: replies
+ var scopes = q.scopes.split(',')
+ var result = {} // key: scope - value: replies
scopes.forEach(function (scope) {
var monitor = new PresenceManager('presence:/' + q.accountName + '/' + scope, {}, Presence.sentry)
monitor.fullRead(function (online) {
@@ -146,7 +143,7 @@ function getPresence (req, res) {
} else {
result[scope] = online
}
- if (Object.keys(result).length == scopes.length) {
+ if (Object.keys(result).length === scopes.length) {
res.setHeader('Content-type', 'application/json')
res.setHeader('Cache-Control', 'no-cache')
res.setHeader('X-Radar-Host', hostname)
View
@@ -1,8 +1,8 @@
-var https = require('https'),
- http = require('http'),
- qs = require('querystring'),
- urlmodule = require('url'),
- logging = require('minilog')('client')
+var https = require('https')
+var http = require('http')
+var qs = require('querystring')
+var urlmodule = require('url')
+var logging = require('minilog')('client')
function Scope (defaults) {
// Clone Client.def. We don't want to change the defaults when we modify options further.
@@ -51,7 +51,7 @@ Client.prototype.header = function (key, value) {
}
Client.prototype.data = function (data) {
- if (this.options.method == 'GET') {
+ if (this.options.method === 'GET') {
// Append to QS
logging.debug('GET append', data)
this.options.path += '?' + qs.stringify(data)
@@ -71,11 +71,11 @@ Client.prototype.end = function (callback) {
}
Client.prototype._end = function (callback) {
- var self = this,
- options = this.options,
- secure = this.options.secure,
- resData = '',
- protocol = (secure ? https : http)
+ var self = this
+ var options = this.options
+ var secure = this.options.secure
+ var resData = ''
+ var protocol = (secure ? https : http)
if (this.beforeRequest) {
this.beforeRequest(this)
@@ -86,10 +86,9 @@ Client.prototype._end = function (callback) {
'request. Options: ', options)
var proxy = protocol.request(options, function (response) {
- response.on('data', function (chunk) { resData += chunk; })
+ response.on('data', function (chunk) { resData += chunk })
response.on('end', function () {
- var err,
- isRedirect = Math.floor(response.statusCode / 100) == 3 && response.headers && response.headers.location
+ var isRedirect = Math.floor(response.statusCode / 100) === 3 && response.headers && response.headers.location
logging.debug('Response for the request "' + options.method + ' ' + options.host + options.path + '" has been ended.')
@@ -102,7 +101,7 @@ Client.prototype._end = function (callback) {
response.headers['content-type'].toLowerCase().indexOf('application/json') > -1) {
try {
resData = JSON.parse(resData)
- } catch(jsonParseError) {
+ } catch (jsonParseError) {
return self._error(jsonParseError, resData, callback)
}
}
@@ -124,9 +123,9 @@ Client.prototype._end = function (callback) {
callback(undefined, resData)
}
})
- }).on('error', function (err) { self._error(err, callback); })
+ }).on('error', function (err) { self._error(err, callback) })
- if (options.data && options.method != 'GET') {
+ if (options.data && options.method !== 'GET') {
proxy.write(options.data)
}
@@ -142,18 +141,16 @@ Client.prototype._error = function (error, resData, callback) {
}
}
-Client.prototype._redirect = function (response) {
- var parts
-
+Client.prototype._redirect = function (response, callback) {
if (!/^https?:/.test(response.headers.location)) {
- response.headers.location = urlmodule.resolve(options.url, response.headers.location)
+ response.headers.location = urlmodule.resolve(this.options.url, response.headers.location)
}
// Parse location to check for port
- parts = urlmodule.parse(response.headers.location)
- if (parts.protocol == 'http:') {
- options.secure = false
- options.port = parts.port || 80
+ var parts = urlmodule.parse(response.headers.location)
+ if (parts.protocol === 'http:') {
+ this.options.secure = false
+ this.options.port = parts.port || 80
}
this.options.url = parts.href
View
@@ -1,5 +1,5 @@
-var url = require('url'),
- logging = require('minilog')('radar:api-router')
+var url = require('url')
+var logging = require('minilog')('radar:api-router')
function Router () {
this.urlMap = []
@@ -9,13 +9,13 @@ function Router () {
Router.prototype.route = function (req, res) {
logging.info('Routing request "' + req.method + ' ' + req.url + '"')
- var pathname = url.parse(req.url).pathname.replace(/^\/?node/, ''),
- len = this.urlMap.length,
- i = -1,
- urlHandler
+ var pathname = url.parse(req.url).pathname.replace(/^\/?node/, '')
+ var len = this.urlMap.length
+ var i = -1
+ var urlHandler
- while(++i <= len){
- if (this.urlMap[i] && this.urlMap[i].method == req.method && this.urlMap[i].re.test(pathname)) {
+ while (++i <= len) {
+ if (this.urlMap[i] && this.urlMap[i].method === req.method && this.urlMap[i].re.test(pathname)) {
urlHandler = this.urlMap[i]
break
}
@@ -25,7 +25,7 @@ Router.prototype.route = function (req, res) {
return false
}
- if (req.method == 'POST') {
+ if (req.method === 'POST') {
var data = ''
req.on('data', function (chunk) {
@@ -34,14 +34,13 @@ Router.prototype.route = function (req, res) {
req.on('end', function () {
logging.debug('Post data sent to ' + req.url + ' ended.')
- urlHandler.callback.apply(undefined, [req, res, urlHandler.re.exec(pathname), data ])
+ urlHandler.callback.apply(undefined, [req, res, urlHandler.re.exec(pathname), data])
})
} else {
- urlHandler.callback.apply(undefined, [req, res, urlHandler.re.exec(pathname) ])
+ urlHandler.callback.apply(undefined, [req, res, urlHandler.re.exec(pathname)])
}
return true
-
}
Router.prototype.get = function (regexp, callback) {
@@ -53,9 +52,10 @@ Router.prototype.post = function (regexp, callback) {
}
Router.prototype.attach = function (httpServer) {
- var self = this,
- // Cache and clean up listeners
- oldListeners = httpServer.listeners('request')
+ var self = this
+
+ // Cache and clean up listeners
+ var oldListeners = httpServer.listeners('request')
httpServer.removeAllListeners('request')
// Add request handler
@@ -67,7 +67,6 @@ Router.prototype.attach = function (httpServer) {
}
}
})
-
}
module.exports = Router
View
@@ -1,5 +1,4 @@
-var _ = require('underscore'),
- log = require('minilog')('radar:client')
+var log = require('minilog')('radar:client')
function Client (name, id, accountName, version) {
this.createdAt = Date.now()
@@ -63,7 +62,7 @@ Client.prototype.storeData = function (messageIn) {
break
}
- // FIXME: For now log everything Later, enable sample logging.
+ // FIXME: For now log everything Later, enable sample logging
if (processedOp) {
this._logState()
}
@@ -82,8 +81,8 @@ Client.prototype.readData = function (cb) {
}
Client.prototype._logState = function () {
- var subCount = Object.keys(this.subscriptions).length,
- presCount = Object.keys(this.presences).length
+ var subCount = Object.keys(this.subscriptions).length
+ var presCount = Object.keys(this.presences).length
log.info('#storeData', {
client_id: this.id,
@@ -93,9 +92,9 @@ Client.prototype._logState = function () {
}
Client.prototype._storeDataSubscriptions = function (messageIn) {
- var message = _cloneForStorage(messageIn),
- to = message.to,
- existingSubscription
+ var message = _cloneForStorage(messageIn)
+ var to = message.to
+ var existingSubscription
// Persist the message data, according to type
switch (message.op) {
@@ -119,12 +118,12 @@ Client.prototype._storeDataSubscriptions = function (messageIn) {
}
Client.prototype._storeDataPresences = function (messageIn) {
- var message = _cloneForStorage(messageIn),
- to = message.to,
- existingPresence
+ var message = _cloneForStorage(messageIn)
+ var to = message.to
+ var existingPresence
// Persist the message data, according to type
- if (message.op === 'set' && to.substr(0, 'presence:/'.length) == 'presence:/') {
+ if (message.op === 'set' && to.substr(0, 'presence:/'.length) === 'presence:/') {
existingPresence = this.presences[to]
// Should go offline
View
@@ -43,5 +43,5 @@ module.exports = {
// use_connection: 'legacy',
// Radar config: Port for radar to run on.
- port: 8000,
+ port: 8000
}
Oops, something went wrong.

0 comments on commit 0c83789

Please sign in to comment.