mm_os 3.3.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (380) hide show
  1. package/LICENSE +21 -201
  2. package/README.md +491 -99
  3. package/README_EN.md +498 -0
  4. package/adapter/adapter.js +431 -0
  5. package/adapter/custom_persistence.js +660 -0
  6. package/adapter/mqtt.js +273 -0
  7. package/adapter/socket.js +113 -0
  8. package/adapter/web.js +67 -0
  9. package/adapter/websocket.js +146 -0
  10. package/com/api/com.json +5 -0
  11. package/{core/com → com}/api/config.tpl.json +8 -8
  12. package/com/api/drive.js +708 -0
  13. package/com/api/index.js +198 -0
  14. package/com/api/oauth.js +200 -0
  15. package/com/api/script.tpl.js +32 -0
  16. package/com/cmd/README.md +11 -0
  17. package/com/cmd/com.json +5 -0
  18. package/com/cmd/config.tpl.json +122 -0
  19. package/com/cmd/drive.js +1548 -0
  20. package/com/cmd/index.js +1066 -0
  21. package/com/cmd/msg.json +48 -0
  22. package/com/cmd/nlp.js +525 -0
  23. package/com/cmd/script.tpl.js +32 -0
  24. package/com/db/com.json +5 -0
  25. package/com/db/drive.js +1999 -0
  26. package/com/db/index.js +242 -0
  27. package/com/event/com.json +5 -0
  28. package/{core/com → com}/event/config.tpl.json +8 -8
  29. package/com/event/drive.js +59 -0
  30. package/com/event/index.js +409 -0
  31. package/com/event/script.tpl.js +23 -0
  32. package/com/mqtt/com.json +5 -0
  33. package/{core/com → com}/mqtt/config.tpl.json +3 -5
  34. package/com/mqtt/drive.js +676 -0
  35. package/com/mqtt/index.js +822 -0
  36. package/com/mqtt/mm_mqtt.js +425 -0
  37. package/com/mqtt/script.tpl.js +723 -0
  38. package/com/nav/com.json +5 -0
  39. package/com/nav/config.tpl.json +84 -0
  40. package/com/nav/drive.js +702 -0
  41. package/com/nav/index.js +231 -0
  42. package/{core/com → com}/nav/tpl/admin_pc/page_config.vue +280 -280
  43. package/{core/com → com}/nav/tpl/admin_pc/page_config_form.vue +194 -194
  44. package/com/nav/tpl/admin_pc/page_form.vue +180 -0
  45. package/com/nav/tpl/admin_pc/page_view.vue +124 -0
  46. package/com/nav/tpl/dev_pc/page_default.vue +247 -0
  47. package/com/nav/tpl/dev_pc/page_type.vue +313 -0
  48. package/com/nav/tpl/home_pc/page_default.vue +234 -0
  49. package/com/nav/tpl/home_pc/page_form.vue +137 -0
  50. package/com/nav/tpl/home_pc/page_list.vue +234 -0
  51. package/com/nav/tpl/home_pc/page_nav.vue +221 -0
  52. package/com/nav/tpl/home_pc/page_type.vue +234 -0
  53. package/com/nav/tpl/home_pc/page_view.vue +125 -0
  54. package/com/nav/tpl/home_phone/page_channel.vue +234 -0
  55. package/com/nav/tpl/home_phone/page_default.vue +234 -0
  56. package/com/nav/tpl/home_phone/page_form.vue +137 -0
  57. package/com/nav/tpl/home_phone/page_nav.vue +237 -0
  58. package/com/nav/tpl/home_phone/page_type.vue +234 -0
  59. package/com/nav/tpl/home_phone/page_view.vue +125 -0
  60. package/com/nav/viewmodel.js +446 -0
  61. package/com/param/com.json +5 -0
  62. package/{core/com → com}/param/config.tpl.json +7 -1
  63. package/com/param/drive.js +502 -0
  64. package/com/param/index.js +155 -0
  65. package/com/param/script.tpl.js +12 -0
  66. package/com/pendant/com.json +5 -0
  67. package/{core/com/component → com/pendant}/config.tpl.json +15 -13
  68. package/com/pendant/drive.js +204 -0
  69. package/com/pendant/index.js +441 -0
  70. package/com/pendant/pendant.html +16 -0
  71. package/com/pendant/script.tpl.js +18 -0
  72. package/com/socket/com.json +5 -0
  73. package/com/socket/config.tpl.json +12 -0
  74. package/com/socket/drive.js +651 -0
  75. package/com/socket/index.js +351 -0
  76. package/com/socket/script.tpl.js +41 -0
  77. package/com/sql/com.json +5 -0
  78. package/{core/com → com}/sql/config.tpl.json +13 -9
  79. package/com/sql/drive.js +1259 -0
  80. package/com/sql/index.js +150 -0
  81. package/com/sql/script.tpl.js +47 -0
  82. package/com/static/com.json +5 -0
  83. package/{core/com → com}/static/config.tpl.json +10 -6
  84. package/com/static/drive.js +194 -0
  85. package/com/static/index.js +226 -0
  86. package/com/static/script.tpl.js +28 -0
  87. package/com/task/com.json +5 -0
  88. package/{core/com → com}/task/config.tpl.json +4 -6
  89. package/com/task/drive.js +405 -0
  90. package/com/task/index.js +148 -0
  91. package/com/task/script.tpl.js +37 -0
  92. package/com/template/com.json +5 -0
  93. package/com/template/config.tpl.json +16 -0
  94. package/com/template/drive.js +80 -0
  95. package/com/template/index.js +141 -0
  96. package/com.js +156 -0
  97. package/common/README.md +2 -0
  98. package/common/handler/msg/handler.json +22 -0
  99. package/common/handler/msg/index.js +23 -0
  100. package/common/handler/player/handler.json +22 -0
  101. package/common/handler/player/index.js +287 -0
  102. package/common/handler/user/handler.json +22 -0
  103. package/common/handler/user/index.js +23 -0
  104. package/common/middleware/web_after/index.js +29 -0
  105. package/common/middleware/web_after/middleware.json +9 -0
  106. package/common/middleware/web_base/index.js +113 -0
  107. package/common/middleware/web_base/middleware.json +19 -0
  108. package/common/middleware/web_before/index.js +33 -0
  109. package/common/middleware/web_before/middleware.json +9 -0
  110. package/common/middleware/web_cors/index.js +87 -0
  111. package/common/middleware/web_cors/middleware.json +24 -0
  112. package/common/middleware/web_error/index.js +119 -0
  113. package/common/middleware/web_error/middleware.json +18 -0
  114. package/common/middleware/web_ip/index.js +15 -0
  115. package/common/middleware/web_ip/middleware.json +14 -0
  116. package/common/middleware/web_logger/index.js +156 -0
  117. package/common/middleware/web_logger/middleware.json +14 -0
  118. package/common/middleware/web_main/index.js +24 -0
  119. package/common/middleware/web_main/middleware.json +9 -0
  120. package/common/middleware/web_static/index.js +73 -0
  121. package/common/middleware/web_static/middleware.json +54 -0
  122. package/common/middleware/web_waf/index.js +385 -0
  123. package/common/middleware/web_waf/middleware.json +13 -0
  124. package/common/model/msg/index.js +88 -0
  125. package/common/model/msg/model.json +401 -0
  126. package/common/model/player/index.js +63 -0
  127. package/common/model/player/model.json +185 -0
  128. package/common/model/user/index.js +11 -0
  129. package/common/model/user/model.json +219 -0
  130. package/core/app/config.tpl.json +67 -0
  131. package/core/app/index.js +632 -0
  132. package/core/app/script.tpl.js +52 -0
  133. package/core/channel/index.js +899 -0
  134. package/core/channel/matcher.js +585 -0
  135. package/core/com/config.tpl.json +16 -0
  136. package/core/com/index.js +74 -0
  137. package/core/com/script.tpl.js +5 -0
  138. package/core/component/component.js +42 -0
  139. package/core/component/config.tpl.json +63 -0
  140. package/core/component/index.js +273 -0
  141. package/core/component/script.tpl.js +19 -0
  142. package/core/controller/config.tpl.json +14 -0
  143. package/core/controller/index.js +373 -0
  144. package/core/controller/script.tpl.js +27 -0
  145. package/core/factory/config.tpl.json +14 -0
  146. package/core/factory/entity.js +275 -0
  147. package/core/factory/index.js +241 -0
  148. package/core/factory/script.tpl.js +16 -0
  149. package/core/game/bat/index.js +137 -0
  150. package/core/game/bat/world.js +622 -0
  151. package/core/game/config.tpl.json +16 -0
  152. package/core/game/entity_admin.js +230 -0
  153. package/core/game/index.js +186 -0
  154. package/core/handler/config.tpl.json +22 -0
  155. package/core/handler/index.js +181 -0
  156. package/core/handler/script.tpl.js +23 -0
  157. package/core/logic/config.tpl.json +14 -0
  158. package/core/logic/index.js +59 -0
  159. package/core/logic/script.tpl.js +19 -0
  160. package/core/middleware/config.tpl.json +16 -0
  161. package/core/middleware/index.js +125 -0
  162. package/core/middleware/script.tpl.js +37 -0
  163. package/core/mod/config.tpl.json +22 -0
  164. package/core/mod/index.js +130 -0
  165. package/core/mod/script.tpl.js +34 -0
  166. package/core/model/config.tpl.json +219 -0
  167. package/core/model/index.js +272 -0
  168. package/core/model/model.js +27 -0
  169. package/core/model/script.tpl.js +20 -0
  170. package/core/notifier/config.tpl.json +14 -0
  171. package/core/notifier/index.js +77 -0
  172. package/core/notifier/script.tpl.js +20 -0
  173. package/core/plugin/config.tpl.json +24 -0
  174. package/core/plugin/index.js +232 -0
  175. package/core/plugin/script.tpl.js +51 -0
  176. package/core/pusher/config.tpl.json +14 -0
  177. package/core/pusher/index.js +161 -0
  178. package/core/pusher/script.tpl.js +20 -0
  179. package/core/room/bat/index.js +170 -0
  180. package/core/room/bat/room.js +524 -0
  181. package/core/room/config.tpl.json +20 -0
  182. package/core/room/index.js +249 -0
  183. package/core/room/room.js +61 -0
  184. package/core/scene/config.tpl.json +14 -0
  185. package/core/scene/index.js +466 -0
  186. package/core/scene/loop.js +1255 -0
  187. package/core/scene/map.js +28 -0
  188. package/core/scene/script.tpl.js +22 -0
  189. package/core/sender/config.tpl.json +14 -0
  190. package/core/sender/index.js +79 -0
  191. package/core/sender/script.tpl.js +20 -0
  192. package/core/service/config.tpl.json +14 -0
  193. package/core/service/index.js +100 -0
  194. package/core/service/script.tpl.js +25 -0
  195. package/core/store/config.tpl.json +26 -0
  196. package/core/store/index.js +1755 -0
  197. package/core/store/script.tpl.js +22 -0
  198. package/core/store/sql.js +1464 -0
  199. package/core/system/config.tpl.json +18 -0
  200. package/core/system/index.js +312 -0
  201. package/core/system/script.tpl.js +77 -0
  202. package/core/view/config.tpl.json +14 -0
  203. package/core/view/index.js +91 -0
  204. package/core/view/script.tpl.js +20 -0
  205. package/core/zone/bat/index.js +725 -0
  206. package/core/zone/config.tpl.json +54 -0
  207. package/core/zone/index.js +614 -0
  208. package/core/zone/script.tpl.js +10 -0
  209. package/core/zone/zone_bat.js +136 -0
  210. package/core//345/237/272/347/261/273/346/250/241/345/235/227/346/270/205/345/215/225.md +24 -0
  211. package/index.js +17 -314
  212. package/os.js +57 -0
  213. package/package.json +60 -58
  214. package/server.js +598 -0
  215. package/README.en.md +0 -36
  216. package/conf.json +0 -3
  217. package/core/base/mqtt/index.js +0 -1107
  218. package/core/base/mqtt/lib.js +0 -40
  219. package/core/base/web/index.js +0 -243
  220. package/core/com/api/com.json +0 -4
  221. package/core/com/api/drive.js +0 -668
  222. package/core/com/api/index.js +0 -108
  223. package/core/com/api/oauth.js +0 -158
  224. package/core/com/api/script.js +0 -32
  225. package/core/com/app/README.md +0 -3
  226. package/core/com/app/com.json +0 -4
  227. package/core/com/app/config.tpl.json +0 -16
  228. package/core/com/app/drive.js +0 -309
  229. package/core/com/app/index.js +0 -211
  230. package/core/com/app/script.js +0 -155
  231. package/core/com/cmd/com.json +0 -4
  232. package/core/com/cmd/config.tpl.json +0 -66
  233. package/core/com/cmd/drive.js +0 -513
  234. package/core/com/cmd/index.js +0 -354
  235. package/core/com/cmd/old/5w2h.js +0 -54
  236. package/core/com/cmd/old/drive.js +0 -423
  237. package/core/com/cmd/script.js +0 -11
  238. package/core/com/component/README.md +0 -3
  239. package/core/com/component/com.json +0 -4
  240. package/core/com/component/component.html +0 -16
  241. package/core/com/component/drive.js +0 -197
  242. package/core/com/component/index.js +0 -312
  243. package/core/com/component/script.js +0 -18
  244. package/core/com/db/com.json +0 -4
  245. package/core/com/db/drive.js +0 -1160
  246. package/core/com/db/index.js +0 -176
  247. package/core/com/event/com.json +0 -4
  248. package/core/com/event/drive.js +0 -133
  249. package/core/com/event/index.js +0 -345
  250. package/core/com/event/script.js +0 -26
  251. package/core/com/eventer/com.js +0 -477
  252. package/core/com/eventer/com.json +0 -4
  253. package/core/com/middleware/com.js +0 -153
  254. package/core/com/middleware/com.json +0 -4
  255. package/core/com/middleware/config.tpl.json +0 -8
  256. package/core/com/middleware/script.js +0 -9
  257. package/core/com/mqtt/com.json +0 -4
  258. package/core/com/mqtt/drive.js +0 -600
  259. package/core/com/mqtt/index.js +0 -572
  260. package/core/com/mqtt/mm_mqtt.js +0 -330
  261. package/core/com/mqtt/script.js +0 -604
  262. package/core/com/msg/com.js +0 -296
  263. package/core/com/msg/com.json +0 -4
  264. package/core/com/nav/com.json +0 -4
  265. package/core/com/nav/config.tpl.json +0 -75
  266. package/core/com/nav/drive.js +0 -549
  267. package/core/com/nav/index.js +0 -182
  268. package/core/com/nav/tpl/admin_pc/page_form.vue +0 -180
  269. package/core/com/nav/tpl/admin_pc/page_view.vue +0 -124
  270. package/core/com/nav/tpl/dev_pc/page_default.vue +0 -247
  271. package/core/com/nav/tpl/dev_pc/page_type.vue +0 -313
  272. package/core/com/nav/tpl/home_pc/page_default.vue +0 -234
  273. package/core/com/nav/tpl/home_pc/page_form.vue +0 -137
  274. package/core/com/nav/tpl/home_pc/page_list.vue +0 -234
  275. package/core/com/nav/tpl/home_pc/page_nav.vue +0 -221
  276. package/core/com/nav/tpl/home_pc/page_type.vue +0 -234
  277. package/core/com/nav/tpl/home_pc/page_view.vue +0 -125
  278. package/core/com/nav/tpl/home_phone/page_channel.vue +0 -234
  279. package/core/com/nav/tpl/home_phone/page_default.vue +0 -234
  280. package/core/com/nav/tpl/home_phone/page_form.vue +0 -137
  281. package/core/com/nav/tpl/home_phone/page_nav.vue +0 -237
  282. package/core/com/nav/tpl/home_phone/page_type.vue +0 -234
  283. package/core/com/nav/tpl/home_phone/page_view.vue +0 -125
  284. package/core/com/nav/viewmodel.js +0 -296
  285. package/core/com/param/drive.js +0 -366
  286. package/core/com/param/index.js +0 -80
  287. package/core/com/param/script.js +0 -12
  288. package/core/com/param/test.js +0 -98
  289. package/core/com/plugin/README.md +0 -3
  290. package/core/com/plugin/com.json +0 -4
  291. package/core/com/plugin/config.tpl.json +0 -26
  292. package/core/com/plugin/drive.js +0 -536
  293. package/core/com/plugin/index.js +0 -259
  294. package/core/com/plugin/script.js +0 -213
  295. package/core/com/rpc/com.json +0 -4
  296. package/core/com/rpc/drive.js +0 -160
  297. package/core/com/rpc/index.js +0 -87
  298. package/core/com/rpc/rpc.js +0 -118
  299. package/core/com/socket/com.json +0 -4
  300. package/core/com/socket/config.tpl.json +0 -14
  301. package/core/com/socket/drive.js +0 -403
  302. package/core/com/socket/index.js +0 -62
  303. package/core/com/socket/script.js +0 -42
  304. package/core/com/sql/drive.js +0 -1087
  305. package/core/com/sql/index.js +0 -83
  306. package/core/com/sql/script.js +0 -48
  307. package/core/com/static/com.json +0 -4
  308. package/core/com/static/drive.js +0 -220
  309. package/core/com/static/index.js +0 -149
  310. package/core/com/static/script.js +0 -28
  311. package/core/com/task/com.json +0 -4
  312. package/core/com/task/drive.js +0 -403
  313. package/core/com/task/index.js +0 -110
  314. package/core/com/task/script.js +0 -37
  315. package/core/com/timer/com.js +0 -217
  316. package/core/com/timer/com.json +0 -4
  317. package/core/com/tpl/com.js +0 -19
  318. package/core/com/tpl/com.json +0 -4
  319. package/lib/actions.js +0 -50
  320. package/lib/base.js +0 -361
  321. package/lib/com.js +0 -29
  322. package/lib/ref.js +0 -121
  323. package/middleware/mqtt_base/index.js +0 -10
  324. package/middleware/mqtt_base/middleware.json +0 -10
  325. package/middleware/performance/index.js +0 -151
  326. package/middleware/performance/middleware.json +0 -16
  327. package/middleware/security_audit/index.js +0 -549
  328. package/middleware/security_audit/middleware.json +0 -48
  329. package/middleware/security_headers/index.js +0 -487
  330. package/middleware/security_headers/middleware.json +0 -45
  331. package/middleware/waf/index.js +0 -348
  332. package/middleware/waf/middleware.json +0 -10
  333. package/middleware/waf_ddos/index.js +0 -520
  334. package/middleware/waf_ddos/middleware.json +0 -38
  335. package/middleware/waf_ip/index.js +0 -379
  336. package/middleware/waf_ip/middleware.json +0 -49
  337. package/middleware/waf_xss/index.js +0 -269
  338. package/middleware/waf_xss/middleware.json +0 -18
  339. package/middleware/web_after/index.js +0 -33
  340. package/middleware/web_after/middleware.json +0 -9
  341. package/middleware/web_base/index.js +0 -90
  342. package/middleware/web_base/middleware.json +0 -9
  343. package/middleware/web_before/index.js +0 -27
  344. package/middleware/web_before/middleware.json +0 -9
  345. package/middleware/web_check/index.js +0 -28
  346. package/middleware/web_check/middleware.json +0 -9
  347. package/middleware/web_main/index.js +0 -28
  348. package/middleware/web_main/middleware.json +0 -9
  349. package/middleware/web_proxy/index.js +0 -37
  350. package/middleware/web_proxy/middleware.json +0 -9
  351. package/middleware/web_render/index.js +0 -87
  352. package/middleware/web_render/middleware.json +0 -9
  353. package/middleware/web_socket/index.js +0 -34
  354. package/middleware/web_socket/middleware.json +0 -9
  355. package/middleware/web_static/index.js +0 -115
  356. package/middleware/web_static/middleware.json +0 -9
  357. /package/{core/com → com}/api/README.md +0 -0
  358. /package/{core/com → com}/db/README.md +0 -0
  359. /package/{core/com → com}/event/README.md +0 -0
  360. /package/{core/com → com}/mqtt/README.md +0 -0
  361. /package/{core/com → com}/nav/README.md +0 -0
  362. /package/{core/com → com}/nav/tpl/admin_pc/page_channel.vue +0 -0
  363. /package/{core/com → com}/nav/tpl/admin_pc/page_default.vue +0 -0
  364. /package/{core/com → com}/nav/tpl/admin_pc/page_lang.vue +0 -0
  365. /package/{core/com → com}/nav/tpl/admin_pc/page_nav.vue +0 -0
  366. /package/{core/com → com}/nav/tpl/admin_pc/page_table.vue +0 -0
  367. /package/{core/com → com}/nav/tpl/admin_pc/page_type.vue +0 -0
  368. /package/{core/com → com}/nav/tpl/dev_pc/page_channel.vue +0 -0
  369. /package/{core/com → com}/nav/tpl/dev_pc/page_config.vue +0 -0
  370. /package/{core/com → com}/nav/tpl/dev_pc/page_form.vue +0 -0
  371. /package/{core/com → com}/nav/tpl/dev_pc/page_nav.vue +0 -0
  372. /package/{core/com → com}/nav/tpl/dev_pc/page_table.vue +0 -0
  373. /package/{core/com → com}/nav/tpl/home_pc/page_channel.vue +0 -0
  374. /package/{core/com → com}/nav/tpl/home_phone/page_list.vue +0 -0
  375. /package/{core/com → com}/param/README.md +0 -0
  376. /package/{core/com/cmd → com/pendant}/README.md +0 -0
  377. /package/{core/com → com}/socket/README.md +0 -0
  378. /package/{core/com → com}/sql/README.md +0 -0
  379. /package/{core/com → com}/static/README.md +0 -0
  380. /package/{core/com → com}/task/README.md +0 -0
@@ -1,118 +0,0 @@
1
- /**
2
- * 实例化一个PRC方法集
3
- * @class
4
- */
5
- function methods(cm) {
6
- return {
7
- /**
8
- * 增加数据
9
- * @param {Object} db 数据库管理器
10
- * @param {Object} query 查询条件,键值对
11
- * @param {Object} body 要添加的数据,键值对
12
- */
13
- async add(db, query, body) {
14
- var q = {
15
- method: 'add'
16
- };
17
- return await cm.sql.run(q, body, db);
18
- },
19
- /**
20
- * 删除数据
21
- * @param {Object} db 数据库管理器
22
- * @param {Object} query 查询条件,键值对
23
- * @param {Object} body 要添加的数据,键值对
24
- */
25
- async del(db, query, body) {
26
- var q = Object.assign(query, {
27
- method: 'del'
28
- });
29
- return await cm.sql.run(q, body, db);
30
- },
31
- /**
32
- * 修改数据
33
- * @param {Object} db 数据库管理器
34
- * @param {Object} query 查询条件,键值对
35
- * @param {Object} body 要添加的数据,键值对
36
- */
37
- async set(db, query, body) {
38
- var q = Object.assign(query, {
39
- method: 'set'
40
- });
41
- return await cm.sql.run(q, body, db);
42
- },
43
- /**
44
- * 查询数据
45
- * @param {Object} db 数据库管理器
46
- * @param {Object} query 查询条件,键值对
47
- * @param {Object} body 要添加的数据,键值对
48
- */
49
- async get(db, query, body) {
50
- var q = Object.assign(query, {
51
- method: 'get'
52
- });
53
- return await cm.sql.run(q, null, db);
54
- },
55
-
56
- /**
57
- * 更新数据
58
- * @param {Object} db 数据库管理器
59
- * @param {Object} query 查询条件,键值对
60
- * @param {Object} body 要添加的数据,键值对
61
- */
62
- async update(db, query, body) {
63
-
64
- },
65
- /**
66
- * 从备份文件中加载数据
67
- * @param {Object} db 数据库管理器
68
- * @param {Object} query 查询条件,键值对
69
- * @param {Object} body 要添加的数据,键值对
70
- */
71
- async load(db, query, body) {
72
- // if (file) {
73
- // var p = file.fullname(cm.dir);
74
- // if (p.hasFile()) {
75
-
76
- // }
77
- // }
78
- },
79
- /**
80
- * 清空数据
81
- * @param {Object} db 数据库管理器
82
- * @param {Object} query 查询条件,键值对
83
- * @param {Object} body 要添加的数据,键值对
84
- */
85
- async clear(db, query, body) {
86
-
87
- },
88
- /**
89
- * 备份数据到文件
90
- * @param {Object} db 数据库管理器
91
- * @param {Object} query 查询条件,键值对
92
- * @param {Object} body 要添加的数据,键值对
93
- */
94
- async save(db, query, body) {
95
-
96
- },
97
- /**
98
- * 上传数据
99
- * @param {Object} db 数据库管理器
100
- * @param {Object} query 查询条件,键值对
101
- * @param {Object} body 要添加的数据,键值对
102
- */
103
- async upload(db, query, body) {
104
-
105
- },
106
- /**
107
- * 下载数据
108
- * @param {Object} db 数据库管理器
109
- * @param {Object} query 查询条件,键值对
110
- * @param {Object} body 要添加的数据,键值对
111
- */
112
- async download(db, query, body) {
113
-
114
- }
115
- }
116
- }
117
-
118
- module.exports = methods;
@@ -1,4 +0,0 @@
1
- {
2
- "name": "web socket管理器",
3
- "script": "./index.js"
4
- }
@@ -1,14 +0,0 @@
1
- {
2
- // websocket请求路由地址
3
- "path": "/ws/{0}",
4
- // 名称
5
- "name": "{0}",
6
- // websocket标题
7
- "title": "示例websocket",
8
- // 描述,用来介绍该websocket程序是做什么用的
9
- "description": "用来测试",
10
- // websocket调用的脚本文件
11
- "func_file": "./index.js",
12
- // 同步消息循环发送的时间间隔
13
- "interval": 1000
14
- }
@@ -1,403 +0,0 @@
1
- const Item = require('mm_machine').Item;
2
-
3
- // 提供一个全局方法容器
4
- if (!$.methods) {
5
- $.methods = {};
6
- }
7
-
8
- /**
9
- * websocket驱动类
10
- * @extends {Item}
11
- * @class
12
- */
13
- class Drive extends Item {
14
- /**
15
- * 构造函数
16
- * @param {String} dir 当前目录
17
- * @constructor
18
- */
19
- constructor(dir) {
20
- super(dir, __dirname);
21
- this.default_file = "./socket.json";
22
-
23
- /* 通用项 */
24
- /**
25
- * 配置参数
26
- */
27
- this.config = {
28
- // 名称, 由中英文和下“_”组成, 用于修改或卸载 例如: demo
29
- "name": "",
30
- // 状态 0未启用,1启用
31
- "state": 1,
32
- // socket 服务名称
33
- "name": "",
34
- // socket 服务标题
35
- "title": "",
36
- // socket 服务介绍
37
- "description": "",
38
- // 调用的脚本
39
- "func_file": "./index.js",
40
- // 同步消息循环发送的时间间隔
41
- "interval": 1000
42
- };
43
-
44
- // 开放给前端调用的函数
45
- this.methods = Object.assign({}, $.methods);
46
-
47
- // 客户端集合
48
- this.clients = {};
49
- }
50
- }
51
-
52
- /**
53
- * 新建脚本
54
- * @param {String} 文件
55
- */
56
- Drive.prototype.new_script = function(file) {
57
- var fl = __dirname + "/script.js";
58
- if (fl.hasFile()) {
59
- var text = fl.loadText();
60
- if (text) {
61
- var l = $.slash;
62
- if (file.indexOf('socket' + l) !== -1) {
63
- var name = file.between('socket' + l, l);
64
- text = text.replaceAll("{0}", name);
65
- }
66
- file.saveText(text);
67
- }
68
- }
69
- };
70
-
71
- /**
72
- * 新建配置
73
- * @param {String} 文件
74
- */
75
- Drive.prototype.new_config = function(file) {
76
- var fl = __dirname + "/config.tpl.json";
77
- if (fl.hasFile()) {
78
- var text = fl.loadText();
79
- if (text) {
80
- var l = $.slash;
81
- if (file.indexOf('socket' + l) !== -1) {
82
- var name = file.between('socket' + l, l);
83
- text = text.replaceAll("{0}", name);
84
- }
85
- file.saveText(text);
86
- }
87
- }
88
- };
89
-
90
- /**
91
- * 获取session ID
92
- * @param {Object} ctx HTTP上下文
93
- * @return {String} 返回用户的uuid
94
- */
95
- Drive.prototype.getToken = async function(ctx) {
96
- var uuid = await ctx.cookies.get("mm:uuid");
97
- if (!uuid) {
98
- var hd = ctx.request.header;
99
- var agent = hd['user-agent'];
100
- if (!agent) {
101
- agent = "mm";
102
- }
103
- var start = agent.md5().substring(0, 32);
104
- var stamp = Date.parse(new Date()) / 1000;
105
- uuid = (ctx.ip + '_' + stamp).aes_encode(start);
106
- }
107
- return uuid;
108
- };
109
-
110
- /**
111
- * 收到消息时处理函数
112
- * @param {String} bodyStr 消息正文字符串
113
- * @param {Object} ctx http上下文
114
- * @param {String} token 临时访问牌
115
- */
116
- Drive.prototype.onmessage = async function(bodyStr, ctx, token) {
117
- var ret = await this.run(bodyStr, ctx, token);
118
- if (ret) {
119
- var ws = ctx.websocket;
120
- if (typeof(ret) === "object") {
121
- ws.send(JSON.stringify(ret));
122
- } else {
123
- ws.send(ret);
124
- }
125
- }
126
- };
127
-
128
- /**
129
- * 状态变更通知
130
- * @param {String} type 通知类型
131
- * @param {String} bodyStr 消息正文字符串
132
- * @param {Object} ctx http上下文
133
- * @param {String} token 临时访问牌
134
- * @return {Boolean} 返回true表示做状态修改, 例如关闭时为true, 会删除该客户端
135
- */
136
- Drive.prototype.noticy = async function(type, bodyStr, ctx, token) {
137
- // $.log.debug('通知:', '关闭了');
138
- return true;
139
- };
140
-
141
- /**
142
- * 关闭连接时处理函数
143
- * @param {String} bodyStr 消息正文字符串
144
- * @param {Object} ctx http上下文
145
- * @param {String} token 临时访问牌
146
- */
147
- Drive.prototype.onclose = async function(bodyStr, ctx, token) {
148
- var del = await this.noticy("close", ctx, token);
149
- if (del) {
150
- var lt = this.clients[token];
151
- var index = lt.indexOf(ctx);
152
- lt.splice(index, 1);
153
- }
154
- };
155
-
156
- /**
157
- * 设置websocket
158
- * @param {Object} ctx http上下文
159
- * @param {String} token 临时访问牌
160
- */
161
- Drive.prototype.set_socket = function(ctx, token) {
162
- var ws = ctx.websocket;
163
-
164
- // 增加消息队列
165
- ws.list_msg = [];
166
-
167
- /**
168
- * 设置发送请求
169
- * @param {String} method 方法名称
170
- * @param {Object} params 请求参数
171
- * @param {Function} func 回调函数
172
- */
173
- var _this = this;
174
- ws.req = async function(method, params, func) {
175
- var key = _this.config.name + '';
176
- var data = {
177
- id: key + new Date().getTime() + Math.random(),
178
- method: method,
179
- params: params
180
- };
181
- this.send(JSON.stringify(data));
182
-
183
- if (func) {
184
- data.func = func;
185
- this.list_msg.push(data);
186
- }
187
- };
188
-
189
- // 设置事件 —— 获取消息时和socket关闭时
190
- ws.on("message", async function(bodyStr) {
191
- _this.onmessage(bodyStr, ctx, token)
192
- });
193
-
194
- ws.on("close", async function(bodyStr) {
195
- _this.onclose(bodyStr, ctx, token)
196
- });
197
- }
198
-
199
-
200
- /**
201
- * 握手成功, 发送首条返回内容
202
- * @param {Object} ctx http 上下文
203
- * @param {String} token 临时访问牌
204
- */
205
- Drive.prototype.success = function(ctx, token) {
206
- var ret = $.ret.bl(true, 'connection succeeded');
207
- // 首次响应加上身份牌
208
- ret.result.token = token;
209
- // ID为0表示连接成功
210
- ret.id = 0;
211
- ctx.websocket.send(JSON.stringify(ret));
212
- };
213
-
214
- /**
215
- * 添加客户端
216
- * @param {Object} ctx 请求上下文
217
- * @param {Function} next 跳过当前, 然后继续执行函数
218
- */
219
- Drive.prototype.add = async function(ctx) {
220
- var token = await this.getToken(ctx);
221
- if (!this.clients[token]) {
222
- this.clients[token] = [];
223
- }
224
- this.set_socket(ctx, token);
225
- this.success(ctx, token);
226
- this.clients[token].push(ctx);
227
- };
228
-
229
- /**
230
- * 发送消息 —— 会发送给所有目标, 如须过滤目标, 则须在渲染时过滤
231
- * @param {String} body 消息正文
232
- * @param {String} token 临时访问牌, 用于指定客户端发消息
233
- */
234
- Drive.prototype.send = async function(body, token) {
235
- if (token) {
236
- var list = this.clients[token];
237
- if (list) {
238
- list.map(async (ctx) => {
239
- ctx.websocket.send(body);
240
- })
241
- }
242
- } else {
243
- var dt = this.clients;
244
- for (let k in dt) {
245
- var list = dt[k];
246
- list.map(async (ctx) => {
247
- ctx.websocket.send(body);
248
- });
249
- }
250
- }
251
- };
252
-
253
- /**
254
- * 发送消息 —— 会发送给所有目标, 如须过滤目标, 则须在渲染时过滤
255
- * @param {String} method 方法名称
256
- * @param {Object} params 请求参数
257
- * @param {Function} func 回调函数 可以为空
258
- * @param {String} token 临时访问牌, 用于指定客户端发消息
259
- */
260
- Drive.prototype.req = async function(method, params, func, token) {
261
- if (token) {
262
- var ctx = this.clients[token];
263
- if (ctx) {
264
- ctx.websocket.req(params, func);
265
- }
266
- } else {
267
- var dt = this.clients;
268
- for (let k in dt) {
269
- ctx.websocket.req(params, func);
270
- }
271
- }
272
- };
273
-
274
- /**
275
- * 执行
276
- * @param {String} bodyStr 正文字符串
277
- * @param {Object} ctx 请求上下文
278
- * @param {String} token 临时访问牌
279
- * @return {Object} 返回执行结果
280
- */
281
- Drive.prototype.run = async function(bodyStr, ctx, token) {
282
- try {
283
- if(Object.prototype.toString.call(bodyStr) == "[object Uint8Array]"){
284
- bodyStr = bodyStr.toString();
285
- }
286
- var ws = ctx.websocket;
287
- var json = bodyStr.toJson();
288
- var req = ctx.request;
289
- var request = Object.assign({}, {
290
- headers: req.headers,
291
- query: req.query,
292
- token: token
293
- });
294
- if (json) {
295
- var {
296
- id,
297
- method
298
- } = json;
299
- if (json.result && id) {
300
- var lt = ws.list_msg;
301
- var len = lt.length;
302
- var has = false;
303
- for (var i = 0; i < len; i++) {
304
- var o = lt[i];
305
- if (id === o.id) {
306
- o.func(json.result);
307
- lt.splice(i, 1);
308
- has = true;
309
- break;
310
- }
311
- }
312
- if (has) {
313
- return;
314
- }
315
- } else if (method) {
316
- if (this.methods[method]) {
317
- var ret;
318
- var result = await this.methods[method](json.params, ws, request);
319
- if (result) {
320
- if (typeof(result) == "object" && !Array.isArray(result)) {
321
- ret = Object.assign({
322
- id
323
- }, result);
324
- } else {
325
- ret = {};
326
- if (id) {
327
- ret.id = id
328
- }
329
- ret.result = result;
330
- }
331
- }
332
- return ret;
333
- }
334
- }
335
- return await this.main(json, ws, request);
336
- }
337
- return await this.main(bodyStr, ws, request);
338
- } catch (err) {
339
- $.log.error("websocket 错误", err);
340
- return $.log.error(10000, "代码错误!原因:" + err.toString());
341
- }
342
- };
343
-
344
- /**
345
- * 非定义函数时执行
346
- * @param {Object} body 请求正文
347
- * @param {Object} params 参数
348
- * @param {Object} ws Websocket服务
349
- * @param {Object} request 请求协议头
350
- * @return {Object} 返回执行结果
351
- */
352
- Drive.prototype.main = async function(body, websocket, request) {
353
- return null;
354
- };
355
-
356
- /**
357
- * 初始化函数, 用于定义开放给前端的函数
358
- */
359
- Drive.prototype.init = async function init() {
360
-
361
- };
362
-
363
- /**
364
- * 加载完成时
365
- */
366
- Drive.prototype.load_after = function() {
367
- var m = this.methods;
368
-
369
- /**
370
- * 获取所有方法
371
- * @param {Object} params 参数
372
- * @param {Object} ws Websocket服务
373
- * @param {Object} request 请求协议头
374
- * @return {Object} 返回执行结果
375
- */
376
- m.get_method = async function(params, ws, request) {
377
- return Object.keys(m);
378
- };
379
- };
380
-
381
- /**
382
- * 获取插件
383
- * @param {String} app 应用名称
384
- * @param {String} name 插件名称
385
- * @returns {Object} 返回获取到的插件
386
- */
387
- Drive.prototype.plugin = function(app, name) {
388
- var plus;
389
- var l = $.slash;
390
- if (!app) {
391
- app = this.filename.between("app" + l, l);
392
- }
393
- if (!name) {
394
- name = this.filename.between("plugin" + l, l);
395
- }
396
- var plugins = $.pool.plugin[app];
397
- if (plugins) {
398
- plus = plugins.get(name);
399
- }
400
- return plus
401
- }
402
-
403
- module.exports = Drive;
@@ -1,62 +0,0 @@
1
- const Index = require('mm_machine').Index;
2
- const Drive = require('./drive');
3
-
4
- /**
5
- * 任务类
6
- * @extends {Index}
7
- * @class
8
- */
9
- class Socket extends Index {
10
- /**
11
- * 构造函数
12
- * @param {Object} scope 作用域
13
- * @param {String} title 标题
14
- * @constructor
15
- */
16
- constructor(scope, title) {
17
- super(scope, __dirname);
18
- this.Drive = Drive;
19
- this.type = "socket";
20
- this.dict = {};
21
- this.title = title;
22
- }
23
- }
24
-
25
- /**
26
- * 处理socket请求
27
- * @param {Object} ctx 请求上下文
28
- * @param {Function} next 跳过当前, 然后继续执行函数
29
- */
30
- Socket.prototype.run = async function(ctx, next) {
31
- await next();
32
- var list = this.list;
33
- const path = ctx.path.toLocaleLowerCase();
34
- for (var i = 0, o; o = list[i++];) {
35
- // console.log("监听websocket路径是否正确", path === o.config.path);
36
- if (path === o.config.path) {
37
- o.add(ctx);
38
- break;
39
- }
40
- }
41
- };
42
-
43
- /**
44
- * 加载插件
45
- * @param {String} path 检索路径
46
- * @param {Boolean} isApp 是否APP
47
- */
48
- Socket.prototype.update_config_all = async function(path) {
49
- if (!path) {
50
- path = "./app/";
51
- }
52
- // 获取所有应用路径
53
- var list_scope = $.dir.getAll(path, "socket");
54
-
55
- // 遍历目录路径
56
- for (var i = 0, f; f = list_scope[i++];) {
57
- var list_file = $.file.getAll(f, "*" + _this.type + ".json");
58
- await this.load_list(list_file);
59
- }
60
- }
61
-
62
- module.exports = Socket;
@@ -1,42 +0,0 @@
1
- /**
2
- * 主函数, 用于处理未定义函数的消息
3
- * @param {Object} params 参数
4
- * @param {Object} ws Websocket服务
5
- * @param {Object} request 请求协议头
6
- * @return {Object} 返回执行结果
7
- */
8
- exports.main = async function(body, ws, request) {
9
- $.log.debug('收到客户端推送数据', body);
10
- };
11
-
12
- /**
13
- * 同步消息, 用于定时给前端推送数据
14
- * @param {Object} ws websocket通讯器
15
- */
16
- exports.sync = async function(ws) {
17
- ws.send([]);
18
- };
19
-
20
- /**
21
- * 初始化函数, 用于定义开放给前端的函数
22
- */
23
- exports.init = async function() {
24
- var m = this.methods;
25
-
26
- /**
27
- * 获取所有方法
28
- * @param {Object} params 参数
29
- * @param {Object} ws Websocket服务
30
- */
31
- m.get_method = function(params, ws) {
32
- return Object.keys(m);
33
- };
34
-
35
- /**
36
- * @param {Object} params 参数
37
- * @param {Object} ws Websocket服务
38
- */
39
- m.test = function(params, ws) {
40
- return "你好"
41
- };
42
- };