Permalink
Browse files

First commit

  • Loading branch information...
1 parent a19cc1a commit 5ce8537b7c42232f18a8fb9a38db4ec9e3fc6129 Vladimir Semenyuk committed Nov 16, 2012
Showing with 517,339 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +206 −0 chat/app/chatManager.js
  3. +230 −0 chat/app/messageManager.js
  4. +79 −0 chat/app/redisConnectionManager.js
  5. +110 −0 chat/app/userManager.js
  6. +32 −0 chat/app/utils.js
  7. +95 −0 chat/chat.js
  8. +35 −0 chat/config.js
  9. +21 −0 chat/index.js
  10. +9 −0 chat/node_modules/hash_ring/.lock-wscript
  11. +7 −0 chat/node_modules/hash_ring/Makefile
  12. +43 −0 chat/node_modules/hash_ring/README.md
  13. BIN chat/node_modules/hash_ring/build/.wafpickle-7
  14. BIN chat/node_modules/hash_ring/build/Release/hash_ring.node
  15. BIN chat/node_modules/hash_ring/build/Release/src/hash_ring_1.o
  16. BIN chat/node_modules/hash_ring/build/Release/src/md5_1.o
  17. BIN chat/node_modules/hash_ring/build/Release/src/module_1.o
  18. +49 −0 chat/node_modules/hash_ring/build/c4che/Release.cache.py
  19. +2 −0 chat/node_modules/hash_ring/build/c4che/build.config.py
  20. +44 −0 chat/node_modules/hash_ring/build/config.log
  21. +1 −0 chat/node_modules/hash_ring/index.js
  22. +46 −0 chat/node_modules/hash_ring/package.json
  23. +142 −0 chat/node_modules/hash_ring/src/hash_ring.cc
  24. +43 −0 chat/node_modules/hash_ring/src/hash_ring.h
  25. +381 −0 chat/node_modules/hash_ring/src/md5.cc
  26. +101 −0 chat/node_modules/hash_ring/src/md5.h
  27. +8 −0 chat/node_modules/hash_ring/src/module.cc
  28. +55 −0 chat/node_modules/hash_ring/test/test_distribution.js
  29. +17 −0 chat/node_modules/hash_ring/test/test_leak.js
  30. +21 −0 chat/node_modules/hash_ring/wscript
  31. +79,174 −0 chat/node_modules/mongodb/.coverage_data/0/rcover_25163e6a55918dcd173169fce774c5db
  32. +79,464 −0 chat/node_modules/mongodb/.coverage_data/1/rcover_4e6a938eeb7a2140d74cc6592a1df80f
  33. +78,941 −0 chat/node_modules/mongodb/.coverage_data/2/rcover_c0fa5143fae18cedd03472cd9e36e716
  34. +78,225 −0 chat/node_modules/mongodb/.coverage_data/3/rcover_1eb81841e8beb3826888bc35f55ca43e
  35. +77,274 −0 chat/node_modules/mongodb/.coverage_data/4/rcover_4819e1c485c8c45ca909a74290d71f15
  36. +78,160 −0 chat/node_modules/mongodb/.coverage_data/5/rcover_d0f874bef13944e2ec9f363f43a76255
  37. +5 −0 chat/node_modules/mongodb/.travis.yml
  38. +23 −0 chat/node_modules/mongodb/CONTRIBUTING.md
  39. +64 −0 chat/node_modules/mongodb/Makefile
  40. +438 −0 chat/node_modules/mongodb/Readme.md
  41. +1 −0 chat/node_modules/mongodb/index.js
  42. +40 −0 chat/node_modules/mongodb/install.js
  43. +340 −0 chat/node_modules/mongodb/lib/mongodb/admin.js
  44. +1,636 −0 chat/node_modules/mongodb/lib/mongodb/collection.js
  45. +29 −0 chat/node_modules/mongodb/lib/mongodb/commands/base_command.js
  46. +214 −0 chat/node_modules/mongodb/lib/mongodb/commands/db_command.js
  47. +114 −0 chat/node_modules/mongodb/lib/mongodb/commands/delete_command.js
  48. +83 −0 chat/node_modules/mongodb/lib/mongodb/commands/get_more_command.js
  49. +147 −0 chat/node_modules/mongodb/lib/mongodb/commands/insert_command.js
  50. +98 −0 chat/node_modules/mongodb/lib/mongodb/commands/kill_cursor_command.js
  51. +261 −0 chat/node_modules/mongodb/lib/mongodb/commands/query_command.js
  52. +174 −0 chat/node_modules/mongodb/lib/mongodb/commands/update_command.js
  53. +440 −0 chat/node_modules/mongodb/lib/mongodb/connection/connection.js
  54. +243 −0 chat/node_modules/mongodb/lib/mongodb/connection/connection_pool.js
  55. +23 −0 chat/node_modules/mongodb/lib/mongodb/connection/connection_utils.js
  56. +316 −0 chat/node_modules/mongodb/lib/mongodb/connection/mongos.js
  57. +66 −0 chat/node_modules/mongodb/lib/mongodb/connection/read_preference.js
  58. +1,110 −0 chat/node_modules/mongodb/lib/mongodb/connection/repl_set.js
  59. +848 −0 chat/node_modules/mongodb/lib/mongodb/connection/server.js
  60. +188 −0 chat/node_modules/mongodb/lib/mongodb/connection/strategies/ping_strategy.js
  61. +78 −0 chat/node_modules/mongodb/lib/mongodb/connection/strategies/statistics_strategy.js
  62. +818 −0 chat/node_modules/mongodb/lib/mongodb/cursor.js
  63. +147 −0 chat/node_modules/mongodb/lib/mongodb/cursorstream.js
  64. +2,126 −0 chat/node_modules/mongodb/lib/mongodb/db.js
  65. +213 −0 chat/node_modules/mongodb/lib/mongodb/gridfs/chunk.js
  66. +98 −0 chat/node_modules/mongodb/lib/mongodb/gridfs/grid.js
  67. +1,467 −0 chat/node_modules/mongodb/lib/mongodb/gridfs/gridstore.js
  68. +174 −0 chat/node_modules/mongodb/lib/mongodb/gridfs/readstream.js
  69. +157 −0 chat/node_modules/mongodb/lib/mongodb/index.js
  70. +140 −0 chat/node_modules/mongodb/lib/mongodb/responses/mongo_reply.js
  71. +74 −0 chat/node_modules/mongodb/lib/mongodb/utils.js
  72. +5 −0 chat/node_modules/mongodb/node_modules/bson/.travis.yml
  73. +16 −0 chat/node_modules/mongodb/node_modules/bson/Makefile
  74. +1 −0 chat/node_modules/mongodb/node_modules/bson/README.md
  75. +130 −0 chat/node_modules/mongodb/node_modules/bson/benchmarks/benchmarks.js
  76. +17 −0 chat/node_modules/mongodb/node_modules/bson/binding.gyp
  77. +334 −0 chat/node_modules/mongodb/node_modules/bson/build/Makefile
  78. +1 −0 chat/node_modules/mongodb/node_modules/bson/build/Release/.deps/Release/bson.node.d
  79. +1 −0 chat/node_modules/mongodb/node_modules/bson/build/Release/.deps/Release/obj.target/bson.node.d
  80. +37 −0 chat/node_modules/mongodb/node_modules/bson/build/Release/.deps/Release/obj.target/bson/ext/bson.o.d
  81. BIN chat/node_modules/mongodb/node_modules/bson/build/Release/bson.node
  82. 0 chat/node_modules/mongodb/node_modules/bson/build/Release/linker.lock
  83. BIN chat/node_modules/mongodb/node_modules/bson/build/Release/obj.target/bson.node
  84. BIN chat/node_modules/mongodb/node_modules/bson/build/Release/obj.target/bson/ext/bson.o
  85. +6 −0 chat/node_modules/mongodb/node_modules/bson/build/binding.Makefile
  86. +110 −0 chat/node_modules/mongodb/node_modules/bson/build/bson.target.mk
  87. +104 −0 chat/node_modules/mongodb/node_modules/bson/build/config.gypi
  88. +28 −0 chat/node_modules/mongodb/node_modules/bson/ext/Makefile
  89. +1,016 −0 chat/node_modules/mongodb/node_modules/bson/ext/bson.cc
  90. +273 −0 chat/node_modules/mongodb/node_modules/bson/ext/bson.h
  91. +30 −0 chat/node_modules/mongodb/node_modules/bson/ext/index.js
  92. BIN chat/node_modules/mongodb/node_modules/bson/ext/win32/ia32/bson.node
  93. BIN chat/node_modules/mongodb/node_modules/bson/ext/win32/x64/bson.node
  94. +39 −0 chat/node_modules/mongodb/node_modules/bson/ext/wscript
  95. +56 −0 chat/node_modules/mongodb/node_modules/bson/install.js
  96. +332 −0 chat/node_modules/mongodb/node_modules/bson/lib/bson/binary.js
  97. +385 −0 chat/node_modules/mongodb/node_modules/bson/lib/bson/binary_parser.js
  98. +1,495 −0 chat/node_modules/mongodb/node_modules/bson/lib/bson/bson.js
  99. +25 −0 chat/node_modules/mongodb/node_modules/bson/lib/bson/code.js
  100. +31 −0 chat/node_modules/mongodb/node_modules/bson/lib/bson/db_ref.js
  101. +33 −0 chat/node_modules/mongodb/node_modules/bson/lib/bson/double.js
  102. +121 −0 chat/node_modules/mongodb/node_modules/bson/lib/bson/float_parser.js
  103. +74 −0 chat/node_modules/mongodb/node_modules/bson/lib/bson/index.js
  104. +854 −0 chat/node_modules/mongodb/node_modules/bson/lib/bson/long.js
  105. +13 −0 chat/node_modules/mongodb/node_modules/bson/lib/bson/max_key.js
  106. +13 −0 chat/node_modules/mongodb/node_modules/bson/lib/bson/min_key.js
  107. +253 −0 chat/node_modules/mongodb/node_modules/bson/lib/bson/objectid.js
  108. +48 −0 chat/node_modules/mongodb/node_modules/bson/lib/bson/symbol.js
  109. +853 −0 chat/node_modules/mongodb/node_modules/bson/lib/bson/timestamp.js
  110. +53 −0 chat/node_modules/mongodb/node_modules/bson/package.json
  111. +260 −0 chat/node_modules/mongodb/node_modules/bson/test/browser/bson_test.js
  112. +2,034 −0 chat/node_modules/mongodb/node_modules/bson/test/browser/nodeunit.js
  113. +13 −0 chat/node_modules/mongodb/node_modules/bson/test/browser/suite2.js
  114. +7 −0 chat/node_modules/mongodb/node_modules/bson/test/browser/suite3.js
  115. +30 −0 chat/node_modules/mongodb/node_modules/bson/test/browser/test.html
  116. +240 −0 chat/node_modules/mongodb/node_modules/bson/test/node/bson_array_test.js
  117. +482 −0 chat/node_modules/mongodb/node_modules/bson/test/node/bson_parser_comparision_test.js
  118. +1,671 −0 chat/node_modules/mongodb/node_modules/bson/test/node/bson_test.js
  119. +392 −0 chat/node_modules/mongodb/node_modules/bson/test/node/bson_typed_array_test.js
  120. BIN chat/node_modules/mongodb/node_modules/bson/test/node/data/test_gs_weird_bug.png
  121. +315 −0 chat/node_modules/mongodb/node_modules/bson/test/node/test_full_bson.js
  122. +109 −0 chat/node_modules/mongodb/node_modules/bson/test/node/to_bson_test.js
  123. +80 −0 chat/node_modules/mongodb/node_modules/bson/test/node/tools/utils.js
  124. +21 −0 chat/node_modules/mongodb/node_modules/bson/tools/gleak.js
  125. +20 −0 chat/node_modules/mongodb/node_modules/bson/tools/jasmine-1.1.0/MIT.LICENSE
  126. +190 −0 chat/node_modules/mongodb/node_modules/bson/tools/jasmine-1.1.0/jasmine-html.js
  127. +166 −0 chat/node_modules/mongodb/node_modules/bson/tools/jasmine-1.1.0/jasmine.css
  128. +2,476 −0 chat/node_modules/mongodb/node_modules/bson/tools/jasmine-1.1.0/jasmine.js
  129. BIN chat/node_modules/mongodb/node_modules/bson/tools/jasmine-1.1.0/jasmine_favicon.png
  130. +217 −0 chat/node_modules/mongodb/package.json
  131. +1 −0 chat/node_modules/policyfile/.npmignore
  132. +19 −0 chat/node_modules/policyfile/LICENSE
  133. +7 −0 chat/node_modules/policyfile/Makefile
  134. +98 −0 chat/node_modules/policyfile/README.md
  135. +396 −0 chat/node_modules/policyfile/doc/index.html
  136. +8 −0 chat/node_modules/policyfile/examples/basic.fallback.js
  137. +5 −0 chat/node_modules/policyfile/examples/basic.js
  138. +1 −0 chat/node_modules/policyfile/index.js
  139. +296 −0 chat/node_modules/policyfile/lib/server.js
  140. +42 −0 chat/node_modules/policyfile/package.json
  141. +21 −0 chat/node_modules/policyfile/tests/ssl/ssl.crt
  142. +27 −0 chat/node_modules/policyfile/tests/ssl/ssl.private.key
  143. +231 −0 chat/node_modules/policyfile/tests/unit.test.js
  144. +1 −0 chat/node_modules/redis/.npmignore
  145. +691 −0 chat/node_modules/redis/README.md
  146. +53 −0 chat/node_modules/redis/after.txt
  147. +54 −0 chat/node_modules/redis/after2.txt
  148. +54 −0 chat/node_modules/redis/before.txt
  149. +89 −0 chat/node_modules/redis/benches/buffer_bench.js
  150. +38 −0 chat/node_modules/redis/benches/hiredis_parser.js
  151. +14 −0 chat/node_modules/redis/benches/re_sub_test.js
  152. +29 −0 chat/node_modules/redis/benches/reconnect_test.js
  153. +16 −0 chat/node_modules/redis/benches/stress/codec.js
  154. +38 −0 chat/node_modules/redis/benches/stress/pubsub/pub.js
  155. +10 −0 chat/node_modules/redis/benches/stress/pubsub/run
  156. +23 −0 chat/node_modules/redis/benches/stress/pubsub/server.js
  157. +49 −0 chat/node_modules/redis/benches/stress/rpushblpop/pub.js
  158. +6 −0 chat/node_modules/redis/benches/stress/rpushblpop/run
  159. +30 −0 chat/node_modules/redis/benches/stress/rpushblpop/server.js
  160. +13 −0 chat/node_modules/redis/benches/stress/speed/00
  161. +13 −0 chat/node_modules/redis/benches/stress/speed/plot
  162. BIN chat/node_modules/redis/benches/stress/speed/size-rate.png
  163. +84 −0 chat/node_modules/redis/benches/stress/speed/speed.js
  164. +18 −0 chat/node_modules/redis/benches/sub_quit_test.js
  165. +233 −0 chat/node_modules/redis/changelog.md
  166. +87 −0 chat/node_modules/redis/diff_multi_bench_output.js
  167. +5 −0 chat/node_modules/redis/examples/auth.js
  168. +33 −0 chat/node_modules/redis/examples/backpressure_drain.js
  169. +9 −0 chat/node_modules/redis/examples/eval.js
  170. +24 −0 chat/node_modules/redis/examples/extend.js
  171. +32 −0 chat/node_modules/redis/examples/file.js
  172. +5 −0 chat/node_modules/redis/examples/mget.js
  173. +10 −0 chat/node_modules/redis/examples/monitor.js
  174. +46 −0 chat/node_modules/redis/examples/multi.js
  175. +29 −0 chat/node_modules/redis/examples/multi2.js
  176. +33 −0 chat/node_modules/redis/examples/psubscribe.js
  177. +41 −0 chat/node_modules/redis/examples/pub_sub.js
  178. +24 −0 chat/node_modules/redis/examples/simple.js
  179. +17 −0 chat/node_modules/redis/examples/sort.js
  180. +15 −0 chat/node_modules/redis/examples/subqueries.js
  181. +19 −0 chat/node_modules/redis/examples/subquery.js
  182. +29 −0 chat/node_modules/redis/examples/unix_socket.js
  183. +31 −0 chat/node_modules/redis/examples/web_server.js
  184. +39 −0 chat/node_modules/redis/generate_commands.js
  185. +1,113 −0 chat/node_modules/redis/index.js
  186. +147 −0 chat/node_modules/redis/lib/commands.js
  187. +46 −0 chat/node_modules/redis/lib/parser/hiredis.js
  188. +284 −0 chat/node_modules/redis/lib/parser/javascript.js
  189. +59 −0 chat/node_modules/redis/lib/queue.js
  190. +12 −0 chat/node_modules/redis/lib/to_array.js
  191. +11 −0 chat/node_modules/redis/lib/util.js
  192. +11 −0 chat/node_modules/redis/mem.js
  193. +222 −0 chat/node_modules/redis/multi_bench.js
  194. +33 −0 chat/node_modules/redis/package.json
  195. +1,625 −0 chat/node_modules/redis/test.js
  196. +3 −0 chat/node_modules/underscore/.npmignore
  197. +1 −0 chat/node_modules/underscore/CNAME
  198. +9 −0 chat/node_modules/underscore/CONTRIBUTING.md
  199. +22 −0 chat/node_modules/underscore/LICENSE
  200. +19 −0 chat/node_modules/underscore/README.md
  201. BIN chat/node_modules/underscore/favicon.ico
  202. +2,367 −0 chat/node_modules/underscore/index.html
  203. +1 −0 chat/node_modules/underscore/index.js
  204. +28 −0 chat/node_modules/underscore/package.json
  205. BIN chat/node_modules/underscore/raw/underscore.psd
  206. +5 −0 chat/node_modules/underscore/underscore-min.js
  207. +1,200 −0 chat/node_modules/underscore/underscore.js
  208. +71 −0 chat/node_modules/websocket/CHANGELOG.md
  209. +177 −0 chat/node_modules/websocket/LICENSE
  210. +11 −0 chat/node_modules/websocket/Makefile
  211. +240 −0 chat/node_modules/websocket/README.md
  212. +14 −0 chat/node_modules/websocket/binding.gyp
  213. +339 −0 chat/node_modules/websocket/build/Makefile
  214. +1 −0 chat/node_modules/websocket/build/Release/.deps/Release/obj.target/validation.node.d
  215. +34 −0 chat/node_modules/websocket/build/Release/.deps/Release/obj.target/validation/src/validation.o.d
  216. +1 −0 chat/node_modules/websocket/build/Release/.deps/Release/obj.target/xor.node.d
  217. +29 −0 chat/node_modules/websocket/build/Release/.deps/Release/obj.target/xor/src/xor.o.d
  218. +1 −0 chat/node_modules/websocket/build/Release/.deps/Release/validation.node.d
  219. +1 −0 chat/node_modules/websocket/build/Release/.deps/Release/xor.node.d
  220. 0 chat/node_modules/websocket/build/Release/linker.lock
  221. BIN chat/node_modules/websocket/build/Release/obj.target/validation.node
  222. BIN chat/node_modules/websocket/build/Release/obj.target/validation/src/validation.o
  223. BIN chat/node_modules/websocket/build/Release/obj.target/xor.node
  224. BIN chat/node_modules/websocket/build/Release/obj.target/xor/src/xor.o
  225. BIN chat/node_modules/websocket/build/Release/validation.node
  226. BIN chat/node_modules/websocket/build/Release/xor.node
  227. +6 −0 chat/node_modules/websocket/build/binding.Makefile
  228. +104 −0 chat/node_modules/websocket/build/config.gypi
  229. +113 −0 chat/node_modules/websocket/build/validation.target.mk
  230. +113 −0 chat/node_modules/websocket/build/xor.target.mk
  231. +1 −0 chat/node_modules/websocket/index.js
  232. +28 −0 chat/node_modules/websocket/install.js
  233. +23 −0 chat/node_modules/websocket/lib/Constants.js
  234. +12 −0 chat/node_modules/websocket/lib/Validation.fallback.js
  235. +18 −0 chat/node_modules/websocket/lib/Validation.js
  236. +325 −0 chat/node_modules/websocket/lib/WebSocketClient.js
  237. +707 −0 chat/node_modules/websocket/lib/WebSocketConnection.js
  238. +282 −0 chat/node_modules/websocket/lib/WebSocketFrame.js
  239. +428 −0 chat/node_modules/websocket/lib/WebSocketRequest.js
  240. +154 −0 chat/node_modules/websocket/lib/WebSocketRouter.js
  241. +52 −0 chat/node_modules/websocket/lib/WebSocketRouterRequest.js
  242. +206 −0 chat/node_modules/websocket/lib/WebSocketServer.js
  243. +7 −0 chat/node_modules/websocket/lib/utils.js
  244. +10 −0 chat/node_modules/websocket/lib/websocket.js
  245. +13 −0 chat/node_modules/websocket/lib/xor.fallback.js
  246. +18 −0 chat/node_modules/websocket/lib/xor.js
  247. +40 −0 chat/node_modules/websocket/package.json
  248. +144 −0 chat/node_modules/websocket/src/validation.cc
  249. +86 −0 chat/node_modules/websocket/src/xor.cpp
  250. +192 −0 chat/node_modules/websocket/vendor/FastBufferList.js
  251. +18 −0 chat/node_modules/websocket/vendor/node-ctype/LICENSE
  252. +1,126 −0 chat/node_modules/websocket/vendor/node-ctype/ctio-faster.js
  253. +17 −0 chat/package.json
  254. +235 −0 demo/css/style.css
  255. +83 −0 demo/index.html
  256. +405 −0 demo/js/chat.js
  257. +81 −0 demo/js/utils-date.js
View
@@ -0,0 +1 @@
+*/.idea
View
@@ -0,0 +1,206 @@
+/****************************************************
+ *
+ * Copyright 2012 DENIVIP Media. All Rights Reserved.
+ *
+ *****************************************************
+ *
+ * Created by - Vladimir Semenyuk vladimir@denivip.ru
+ * Version 1.0.0
+ *
+ *****************************************************/
+
+var config = require('./../config').Config,
+ messageManager = require('./messageManager').MessageManager,
+ userManager = require('./userManager').UserManager,
+ _ = require('underscore');
+
+var STATE_READ_ONLY = 1,
+ STATE_READY = 2;
+
+var ChatManager = {
+ connections: {}, // contains user connection objects grouped by channels
+
+ /**
+ * Session initialization, User authorization
+ *
+ * @param connection {object}
+ * @param data {object} - User data
+ */
+ initSession: function(connection, data) {
+ var self = this;
+
+ connection.userId = data.userId;
+ connection.channelId = 'ch:'+data.channelId;
+ connection.nickName = data.nickName;
+
+ // Subscribing to channel
+ messageManager.listenChannel(connection.channelId, this.onMessage, self, function() {
+
+ });
+
+ this.subscribe(connection);
+ },
+
+ /**
+ * Close user session
+ *
+ * @param connection {object}
+ */
+ closeSession: function(connection) {
+ //
+ if (connection.state == STATE_READ_ONLY) {
+ return;
+ }
+
+ userManager.removeUser(connection);
+
+ // Sending new user count to all current users
+ this.sendUsersCount(connection);
+
+
+ if (connection.channelId && this.connections[connection.channelId] && this.connections[connection.channelId][connection.id]) {
+ // Now we are preparing system message about the user exited
+ var systemMsg = {
+ "type": 'system',
+ "data": {
+ "nick": connection.nickName,
+ "message": 'is away'
+ }
+ };
+
+ // and send this message to redis channel
+ this.addMessage(connection,systemMsg);
+
+ delete this.connections[connection.channelId][connection.id];
+ connection.close();
+ connection = {};
+ }
+ },
+
+ /**
+ * User subscription
+ *
+ * @param connection {object}
+ */
+ subscribe: function(connection) {
+ // if this chat instance doesn't know about some redis channel - we are making it know
+ if (!this.connections[connection.channelId]) {
+ this.connections[connection.channelId] = {};
+ }
+
+ // add new connection to this chat
+ this.connections[connection.channelId][connection.id] = connection;
+
+ // checking for user limits in a room
+ if (_.size(this.connections[connection.channelId]) > config.common.maxClientsPerChannel) {
+ connection.state = STATE_READ_ONLY;
+
+ this.sendState(connection);
+
+ return;
+ }
+
+ connection.state = STATE_READY;
+
+ // Now we are preparing system message about the user entered
+ var systemMsg = {
+ "type": 'system',
+ "data": {
+ "nick": connection.nickName,
+ "message": 'entered chat'
+ }
+ };
+
+ // send this message to redis channel
+ this.addMessage(connection,systemMsg);
+
+ userManager.addUser(connection);
+
+ // and send state message to newcomer
+ this.sendState(connection);
+ },
+
+ /**
+ * Getting and sending users list
+ *
+ * @param connection {object}
+ */
+ sendUsersList: function(connection) {
+ userManager.getUsersList(connection, this.sendMessage, this);
+ },
+
+ /**
+ * Getting and sending users count
+ *
+ * @param connection {object}
+ */
+ sendUsersCount: function(connection) {
+ userManager.getCount(connection, this.addMessage, this);
+ },
+
+ /**
+ * Send state message to user
+ *
+ * @param connection {object}
+ */
+ sendState: function(connection) {
+ this.sendMessage(connection, {
+ type: 'state',
+ value: {
+ state: connection.state,
+ room: connection.channelId.slice(3, connection.channelId.length)
+ }
+ });
+ },
+
+ /**
+ * Adding message to channel
+ *
+ * @param connection {object}
+ * @param message {object} in format {"type": string, "data": object}
+ */
+ addMessage: function(connection, message) {
+ // users in read only mode can't send messages
+ if ((connection.state == STATE_READY) || (connection.state == 'closed')) {
+ messageManager.addMessage(connection, message.data, message.type);
+ }
+ },
+
+ /**
+ * Chat onMessage callback
+ *
+ * @param channel {string} channel id
+ * @param message {object}
+ */
+ onMessage:function (channel, message) {
+ //
+ var ch = this.connections[channel];
+
+ // send message to all users in current channel in this chat instance
+ for (var con in ch) {
+ this.sendMessage(ch[con], message);
+ }
+
+ },
+
+ /**
+ * Send message to user
+ *
+ * @param connection {object}
+ * @param message {object}
+ */
+ sendMessage: function(connection, message) {
+ messageManager.sendMessage(connection, message);
+ },
+
+ /**
+ * Send message history
+ *
+ * @param connection {object}
+ */
+ sendHistory: function(connection) {
+ messageManager.sendHistory(connection, this.sendMessage, this);
+ }
+}
+
+exports.ChatManager = ChatManager;
Oops, something went wrong.

0 comments on commit 5ce8537

Please sign in to comment.