Переглянути джерело

Merge branch 'beta' of https://git.cocorobo.cn/CocoRoboLabs/CocoRoboDesktop into beta

lsc 1 рік тому
батько
коміт
39d7b2ac00
7 змінених файлів з 1195 додано та 57 видалено
  1. 27 0
      .gitignore
  2. 57 6
      js/Office/Poll.js
  3. 29 30
      node/message.js
  4. 1027 1
      node/package-lock.json
  5. 3 1
      node/package.json
  6. 26 8
      node/test.html
  7. 26 11
      node/test.js

+ 27 - 0
.gitignore

@@ -0,0 +1,27 @@
+# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
+
+# dependencies
+/node_modules
+/.pnp
+.pnp.js
+*node_modules
+
+# testing
+/coverage
+
+# production
+/build
+
+# misc
+.DS_Store
+.env.local
+.env.development.local
+.env.test.local
+.env.production.local
+
+npm-debug.log*
+yarn-debug.log*
+yarn-error.log*
+
+package-lock.json
+yarn.lock

+ 57 - 6
js/Office/Poll.js

@@ -6,23 +6,74 @@ Namespace.register("U.MD.O.P");
 */
 U.MD.O.P.connect = function () {
     if (US.userInfo.userid) {       //判断用户是否登录
-        U.A.Request(US.SCOKET, ["login", JSON.stringify({     //发送登录请求
+        U.MD.O.P.polling(["login", JSON.stringify({     //发送登录请求
             pageId: US.pageId,
             userId: US.userInfo.userid,
             userName: US.userInfo.UserName,
             type: US.systemId
-        })], U.MD.O.P.pollingAsyn);       //回调进   U.MD.O.P.pollingAsyn 函数
+        })]);
+
+        // U.A.Request(US.SCOKET, ["login", JSON.stringify({     //发送登录请求
+        //     pageId: US.pageId,
+        //     userId: US.userInfo.userid,
+        //     userName: US.userInfo.UserName,
+        //     type: US.systemId
+        // })], U.MD.O.P.pollingAsyn);       //回调进   U.MD.O.P.pollingAsyn 函数
     }
 };
 
 /*
 * 发送请求进入轮训
 */
-U.MD.O.P.polling = function () {
-    U.A.Request(US.SCOKET, ["polling", US.userInfo.userid, US.pageId, US.systemId], U.MD.O.P.pollingAsyn);
-    //发送轮循  回调进  U.MD.O.P.pollingAsyn函数
+U.MD.O.P.polling = function (params) {
+    params = params || ["polling", US.userInfo.userid, US.pageId, US.systemId]
+    var start = 0;
+    var time = null;
+    var xhr = new XMLHttpRequest();
+    var data = "";
+    xhr.open("POST", US.SCOKET, true);
+    xhr.onreadystatechange = function () {
+        //获取数据
+        if (xhr.readyState == 3 && xhr.status == 200) {
+            clearTimeout(time);
+            var len = xhr.responseText.length;
+            data += xhr.responseText.substring(start, len);
+            start = len;
+            time = setTimeout(function () {
+                clearTimeout(time);
+                try {
+                    U.MD.O.P.pollingAsyn({ value: JSON.parse(data) })
+                }
+                catch (e) {
+                }
+                data = "";
+            }, 100);
+        }
+        //结束重连
+        else if (xhr.readyState == 4) {
+            U.MD.O.P.polling();
+        }
+    };
+    //超时重新连接
+    xhr.onerror = function (err) {
+        console.log(err);
+        U.MD.O.P.polling();
+    };
+    try {
+        //发送请求
+        xhr.send(U.A.Request.toAjaxFormat(params));
+    }
+    catch (e) {
+        U.MD.O.P.polling();
+    }
+
+    // U.A.Request(US.SCOKET, ["polling", US.userInfo.userid, US.pageId, US.systemId], U.MD.O.P.pollingAsyn);
+    //     //发送轮循  回调进  U.MD.O.P.pollingAsyn函数
+    // }
 }
 
+
+
 /* 
 * 处理从后台返回的数据
 *
@@ -224,5 +275,5 @@ U.MD.O.P.pollingAsyn = function (r) {
             }
         }
     }
-    U.MD.O.P.polling(); //进入轮循
+    //U.MD.O.P.polling(); //进入轮循
 }

+ 29 - 30
node/message.js

@@ -189,7 +189,7 @@ us.server = us.http.createServer(function (requset, response) {
                 _param = param.splice(1);
             //执行回调函数
             switch (_funname) {
-                //执行登录函数                                                                                                             
+                //执行登录函数
                 case 'login':
                     _userinfo = JSON.parse(_param[0]); //登录用户的信息
                     us.login(response, _userinfo.userId, _userinfo.pageId, _userinfo.userName, _userinfo.type);
@@ -197,38 +197,38 @@ us.server = us.http.createServer(function (requset, response) {
                 case 'logout':
                     us.logout(response, _param[0], _param[1]);
                     break;
-                //执行轮询函数                                                                                                              
+                //执行轮询函数
                 case 'polling':
                     us.polling(response, _param[0], _param[1], _param[2], _param[3]);
                     break;
-                //获取文档信息                                                                                                               
+                //获取文档信息
                 case 'getWord':
                     us.getWord(response, _param[0], _param[1], _param[2]);
                     break;
-                //获取Excel信息                                   
+                //获取Excel信息
                 case 'getExcel':
                     us.getExcel(response, _param[0], _param[1], _param[2]);
                     break;
-                //获取导航文件信息                                   
+                //获取导航文件信息
                 case 'getNav':
                     us.getNav(response, _param[0], _param[1], _param[2]);
                     break;
-                //获取思维网格信息                                                                                                               
+                //获取思维网格信息
                 case 'getMindNetwork':
                     us.getMindNetwork(response, _param[0], _param[1], _param[2]);
                     break;
-                //获取未来课堂信息                                                                                                               
+                //获取未来课堂信息
                 case 'getcscl':
                     us.getcscl(response, _param[0], _param[1], _param[2]);
                     break;
-                //获取文档信息                                                                                                               
+                //获取文档信息
                 case 'getRealTimeClass':
                     us.getRealTimeClass(response, _param[0], _param[1], _param[2]);
                     break;
                 case 'getNavPageContent':
                     us.getNavPageContent(response, _param[0], _param[1]);
                     break;
-                //执行发送函数                                                                                                           
+                //执行发送函数
                 case 'send':
                     us.send(response, _param[0]);
                     break;
@@ -241,20 +241,20 @@ us.server = us.http.createServer(function (requset, response) {
                 case 'newExcelSave':
                     us.newExcelSave(response, _param[0], _param[1], _param[2], _param[3], _param[4]);
                     break;
-                //新建导航文件保存                                   
+                //新建导航文件保存
                 case 'newNavSave':
                     //, _param[5], _param[6], _param[7]
                     us.newNavSave(response, _param[0], _param[1], _param[2], _param[3], _param[4], _param[5], _param[6]);
                     break;
-                //加入文档编辑                                                                                                              
+                //加入文档编辑
                 case 'addWord':
                     //us.addWord(response, _param[0]);
                     break;
-                //加入Excel表格编辑                                              
+                //加入Excel表格编辑
                 case 'addExcel':
                     us.addExcel(response, _param[0]);
                     break;
-                //加入导航文件                                   
+                //加入导航文件
                 case 'addNav':
                     break;
                 case 'copyPageContent':
@@ -534,6 +534,10 @@ us.offLine = function (response, userid, pageid) {
 * @param {string} pageid 页面ID(用户登录唯一识别ID)
 **/
 us.polling = function (response, userid, pageid, type) {
+    console.log("aaaaaaaaaaaaaaaaaaaa")
+    console.log(userid)
+    console.log(pageid)
+    console.log(type)
     //判断轮询的用户是否在连接池中
     if (us.connect[userid]) {
         var _userarray = us.connect[userid], //用户连接池,获取制定用户连接的数量,
@@ -544,9 +548,10 @@ us.polling = function (response, userid, pageid, type) {
             _userarray[pageid].response = response;
             //    console.log(pageid);
             if (_messagearray && _messagearray.message.length > 0) {
-                response.end(JSON.stringify(_messagearray.message));
+                response.write(JSON.stringify(_messagearray.message));
                 _messagearray.message = [];
-            } else {
+            }
+            else {
                 us.offLineMessage[pageid] = us.userOffLineMessage(type); //初始化用户离线消息记录
             }
             return;
@@ -554,7 +559,8 @@ us.polling = function (response, userid, pageid, type) {
         //如果用户连接不存在
         _userarray[pageid] = us.userConnect(pageid, response); //那么直接添加用户连接 添加到用户连接数组里
         us.offLineMessage[pageid] = us.userOffLineMessage(type); //初始化用户离线消息记录
-    } else {
+    }
+    else {
         var _userconect = us.userConnect(pageid, response); //创建用户连接对象
         us.connect[userid] = {}; //添加用户连接对象
         us.connect[userid][pageid] = _userconect;
@@ -599,11 +605,9 @@ us.send = function (response, messageinfo) {
                 //调用群发函数
                 _messagearr[0] && us.broadcast(_messagelist, _messagearr[0].messageInfo.pageId, 'mindNetwork');
                 break;
-            //未来课堂交互                                                                                      
+            //未来课堂交互
             case "us.cscl":
-                // console.log("================aaaaa===================");
-                // console.log(_messageobj[i]);
-                _messagearr = _messageobj[i]; //获取word消息
+                _messagearr = _messageobj[i]; //获取未来消息
                 //得到word所有的用户
                 for (j = 0; j < _messagearr.length; j++) {
                     _messagearr[j].messageInfo.type = _messagearr[j].type;
@@ -620,12 +624,10 @@ us.send = function (response, messageinfo) {
                     us.cscl[_messagearr[j].receiveId] && us.cscl[_messagearr[j].receiveId].history.push(_message);
                     us.updatecscl(_message.messageInfo, _messagearr[j].receiveId, _messagearr[j].type);
                 }
-                console.log(_messagelist)
-                // console.log(_messagearr)
                 //调用群发函数
                 _messagearr[0] && us.broadcast(_messagelist, _messagearr[0].pageId, 'cscl');
                 break;
-            //同步课堂                                                                                      
+            //同步课堂
             case "us.realTimeClass":
                 //console.log("us.realTimeClass");
                 _messagearr = _messageobj[i]; //获取word消息
@@ -1444,23 +1446,20 @@ us.broadcast = function (messageinfo, pageid, type) {
         _recievedpageid, //接收用户的页面唯一识别ID
         _issend, // 是否发送
         _userconnect = us.connect; //用户连接池
+    console.log("=================a=============");
+    console.log(messageinfo);
     for (i in messageinfo) {
         _messageinfo = messageinfo[i]; //记录消息消息
         _users = us[type][i] ? us[type][i].user : {}; //记录用户集合
-        // console.log("=================a=============");
-        // console.log(_users);
         for (j in _users) { //循环处理每个用户处理 给每个用户集合下的用户发送消息
             _pageids = _users[j]; //记录当前用户在每个端登录的页面唯一识别ID
-            // console.log("=================g=============");
-            // console.log(_pageids);
             for (o = 0; o < _pageids.length; o++) { //循环发送给当前用户在每个端登录的用户
                 _recievedpageid = _pageids[o]; //记录接受者页面唯一识别ID  用于区分是否是发送用户
                 if (_recievedpageid != pageid) { //如果接受用户不等于发送用户则发送消息
                     try {
-                        // console.log("=================b=============");
-                        // console.log(_userconnect[j]);
                         if (_userconnect[j] && _userconnect[j][_recievedpageid]) {
-                            _issend = _userconnect[j][_recievedpageid].response.end(JSON.stringify(_messageinfo)); //发送消息
+                            console.log(_recievedpageid);
+                            _issend = _userconnect[j][_recievedpageid].response.write(JSON.stringify(_messageinfo)); //发送消息
                             if (!_issend) { //如果用户下线了,那么发送消息就会失败
                                 us.offLineMessage[_recievedpageid].message.push(_messageinfo); //将消息加入用户离线消息中
                             }

Різницю між файлами не показано, бо вона завелика
+ 1027 - 1
node/package-lock.json


+ 3 - 1
node/package.json

@@ -1,6 +1,8 @@
 {
   "dependencies": {
     "cheerio": "^1.0.0-rc.10",
-    "mysql": "^2.18.1"
+    "express": "^4.18.2",
+    "mysql": "^2.18.1",
+    "path": "^0.12.7"
   }
 }

+ 26 - 8
node/test.html

@@ -4,15 +4,33 @@
 <head>
 
     <script>
-
-        var xhr = new XMLHttpRequest();
-        xhr.open("GET", "http://127.0.0.1:1473", true);
-        xhr.setRequestHeader("Connection", "keep-alive");
-        xhr.onreadystatechange = function () {
-            if (xhr.readyState == e && xhr.status == 200) {
-                //var data = JSON.parse(xhr.responseText);
-                console.log(data);
+        function poll() {
+            var start = 0;
+            var time = null;
+            var xhr = new XMLHttpRequest();
+            var data = "";
+            xhr.open("POST", "http://127.0.0.1:1473", true);
+            xhr.onreadystatechange = function () {
+                if (xhr.readyState == 3 && xhr.status == 200) {
+                    clearTimeout(time);
+                    var len = xhr.responseText.length;
+                    data += xhr.responseText.substring(start, len);
+                    start = len;
+                    console.log(data)
+                    time = setTimeout(function () {
+                        clearTimeout(time);
+                        data = "";
+                    }, 100);
+                }
+            }
+            xhr.onerror = function (err) {
+                console.log(err);
             }
+            xhr.send();
+        }
+        window.onload = function () {
+            poll()
+
         }
     </script>
 </head>

+ 26 - 11
node/test.js

@@ -1,27 +1,41 @@
 us = {};
-us.qs = require("querystring"); //引用文件解析包
+// us.qs = require("querystring"); //引用文件解析包
+// us.http = require("http"); //引用http server服务
+
+// 引入Express模块
+const express = require('express');
+const path = require('path');
 us.http = require("http"); //引用http server服务
+// 创建Express应用
+const app = express();
 
+// 设置静态文件目录
+app.use(express.static(path.join(__dirname, '/')));
 
 
-/**
-* 创建服务
-*
-* @param  {object} requset 请求对象
-* @param  {object} response 响应对象
-**/
-us.server = us.http.createServer(function (requset, response) {
+us.server = us.http.createServer(function (req, res) {
+    // 定义路由
+    // app.all('/', (req, res) => {
     //设置跨域
-    response.writeHead(200, {
+    res.writeHead(200, {
         "Content-Type": "application/json",
         'Access-Control-Allow-Origin': '*',
         "Connection": "keep-alive",
         'Access-Control-Allow-Headers': 'Origin, No-Cache, X-Requested-With, If-Modified-Since, Pragma, Last-Modified, Cache-Control, Expires, Content-Type, X-E4M-With'
     });
-    var data = { "name": "John", "age": 30 };
-    res.write(JSON.stringify(data));
+    var data = [{ "name": "John", "age": 30 }];
+    for (var i = 0; i < 100; i++) {
+        data.push(data[0]);
+    }
+    setInterval(function () {
+        res.write(JSON.stringify(data));
+    }, 2000);
 });
 
+// 启动服务器
+app.listen(3000, () => {
+    console.log('Server is running on port 3000');
+});
 
 /**
 * 监听1473端口的处理
@@ -31,3 +45,4 @@ us.server.listen('1473', '', function () {
     //在控制台输出监听提示
     console.log("开始监听" + us.server.address().port + "......");
 });
+

Деякі файли не було показано, через те що забагато файлів було змінено