PageRenderTime 40ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/config/sockets.js

https://gitlab.com/mba811/twenty
JavaScript | 188 lines | 6 code | 23 blank | 159 comment | 0 complexity | b20b9911a43a0995625cacc61535b2e7 MD5 | raw file
  1. /**
  2. * WebSocket Server Settings
  3. * (sails.config.sockets)
  4. *
  5. * These settings provide transparent access to the options for Sails'
  6. * encapsulated WebSocket server, as well as some additional Sails-specific
  7. * configuration layered on top.
  8. *
  9. * For more information on sockets configuration, including advanced config options, see:
  10. * http://sailsjs.org/#/documentation/reference/sails.config/sails.config.sockets.html
  11. */
  12. module.exports.sockets = {
  13. /***************************************************************************
  14. * *
  15. * This custom onConnect function will be run each time AFTER a new socket *
  16. * connects (To control whether a socket is allowed to connect, check out *
  17. * `authorization` config.) Keep in mind that Sails' RESTful simulation for *
  18. * sockets mixes in socket.io events for your routes and blueprints *
  19. * automatically. *
  20. * *
  21. ***************************************************************************/
  22. onConnect: function(session, socket) {
  23. // By default, do nothing.
  24. },
  25. /***************************************************************************
  26. * *
  27. * This custom onDisconnect function will be run each time a socket *
  28. * disconnects *
  29. * *
  30. ***************************************************************************/
  31. onDisconnect: function(session, socket) {
  32. // By default: do nothing.
  33. },
  34. /***************************************************************************
  35. * *
  36. * `transports` *
  37. * *
  38. * A array of allowed transport methods which the clients will try to use. *
  39. * The flashsocket transport is disabled by default You can enable *
  40. * flashsockets by adding 'flashsocket' to this list: *
  41. * *
  42. ***************************************************************************/
  43. // transports: [
  44. // 'websocket',
  45. // 'htmlfile',
  46. // 'xhr-polling',
  47. // 'jsonp-polling'
  48. // ],
  49. /***************************************************************************
  50. * *
  51. * Use this option to set the datastore socket.io will use to manage *
  52. * rooms/sockets/subscriptions: default: memory *
  53. * *
  54. ***************************************************************************/
  55. // adapter: 'memory',
  56. /***************************************************************************
  57. * *
  58. * Node.js (and consequently Sails.js) apps scale horizontally. It's a *
  59. * powerful, efficient approach, but it involves a tiny bit of planning. At *
  60. * scale, you'll want to be able to copy your app onto multiple Sails.js *
  61. * servers and throw them behind a load balancer. *
  62. * *
  63. * One of the big challenges of scaling an application is that these sorts *
  64. * of clustered deployments cannot share memory, since they are on *
  65. * physically different machines. On top of that, there is no guarantee *
  66. * that a user will "stick" with the same server between requests (whether *
  67. * HTTP or sockets), since the load balancer will route each request to the *
  68. * Sails server with the most available resources. However that means that *
  69. * all room/pubsub/socket processing and shared memory has to be offloaded *
  70. * to a shared, remote messaging queue (usually Redis) *
  71. * *
  72. * Luckily, Socket.io (and consequently Sails.js) apps support Redis for *
  73. * sockets by default. To enable a remote redis pubsub server, uncomment *
  74. * the config below. *
  75. * *
  76. * Worth mentioning is that, if `adapter` config is `redis`, but host/port *
  77. * is left unset, Sails will try to connect to redis running on localhost *
  78. * via port 6379 *
  79. * *
  80. ***************************************************************************/
  81. // adapter: 'redis',
  82. // host: '127.0.0.1',
  83. // port: 6379,
  84. // db: 'sails',
  85. // pass: '<redis auth password>'
  86. /***************************************************************************
  87. * *
  88. * `authorization` *
  89. * *
  90. * Global authorization for Socket.IO access, this is called when the *
  91. * initial handshake is performed with the server. *
  92. * *
  93. * By default (`authorization: false`), when a socket tries to connect, *
  94. * Sails allows it, every time. If no valid cookie was sent, a temporary *
  95. * session will be created for the connecting socket. *
  96. * *
  97. * If `authorization: true`, before allowing a connection, Sails verifies *
  98. * that a valid cookie was sent with the upgrade request. If the cookie *
  99. * doesn't match any known user session, a new user session is created for *
  100. * it. (In most cases, the user would already have a cookie since they *
  101. * loaded the socket.io client and the initial HTML page.) *
  102. * *
  103. * However, in the case of cross-domain requests, it is possible to receive *
  104. * a connection upgrade request WITHOUT A COOKIE (for certain transports) *
  105. * In this case, there is no way to keep track of the requesting user *
  106. * between requests, since there is no identifying information to link *
  107. * him/her with a session. The sails.io.js client solves this by connecting *
  108. * to a CORS endpoint first to get a 3rd party cookie (fortunately this *
  109. * works, even in Safari), then opening the connection. *
  110. * *
  111. * You can also pass along a ?cookie query parameter to the upgrade url, *
  112. * which Sails will use in the absense of a proper cookie e.g. (when *
  113. * connection from the client): *
  114. * io.connect('http://localhost:1337?cookie=smokeybear') *
  115. * *
  116. * (Un)fortunately, the user's cookie is (should!) not accessible in *
  117. * client-side js. Using HTTP-only cookies is crucial for your app's *
  118. * security. Primarily because of this situation, as well as a handful of *
  119. * other advanced use cases, Sails allows you to override the authorization *
  120. * behavior with your own custom logic by specifying a function, e.g: *
  121. * *
  122. * authorization: function authSocketConnectionAttempt(reqObj, cb) { *
  123. * *
  124. * // Any data saved in `handshake` is available in subsequent *
  125. * requests from this as `req.socket.handshake.*` *
  126. * *
  127. * // to allow the connection, call `cb(null, true)` *
  128. * // to prevent the connection, call `cb(null, false)` *
  129. * // to report an error, call `cb(err)` *
  130. * } *
  131. * *
  132. ***************************************************************************/
  133. // authorization: false,
  134. /***************************************************************************
  135. * *
  136. * Whether to run code which supports legacy usage for connected sockets *
  137. * running the v0.9 version of the socket client SDK (i.e. sails.io.js). *
  138. * Disabled in newly generated projects, but enabled as an implicit default *
  139. * (i.e. legacy usage/v0.9 clients be supported if this property is set to *
  140. * true, but also if it is removed from this configuration file or set to *
  141. * `undefined`) *
  142. * *
  143. ***************************************************************************/
  144. // 'backwardsCompatibilityFor0.9SocketClients': false,
  145. /***************************************************************************
  146. * *
  147. * Whether to expose a 'get /__getcookie' route with CORS support that sets *
  148. * a cookie (this is used by the sails.io.js socket client to get access to *
  149. * a 3rd party cookie and to enable sessions). *
  150. * *
  151. * Warning: Currently in this scenario, CORS settings apply to interpreted *
  152. * requests sent via a socket.io connection that used this cookie to *
  153. * connect, even for non-browser clients! (e.g. iOS apps, toasters, node.js *
  154. * unit tests) *
  155. * *
  156. ***************************************************************************/
  157. // grant3rdPartyCookie: true,
  158. /***************************************************************************
  159. * *
  160. * Match string representing the origins that are allowed to connect to the *
  161. * Socket.IO server *
  162. * *
  163. ***************************************************************************/
  164. // origins: '*:*',
  165. };