Explorar o código

update signalRconnect and headers

chenmy %!s(int64=3) %!d(string=hai) anos
pai
achega
4b3eb6327b

+ 2 - 2
HiTeachCC/ClientApp/src/api/index.js

@@ -38,11 +38,11 @@ export default {
   //IM相关
     //根据用户信息创建教室
     createapi: function (data) {
-        return post('https://api2.teammodel.cn/channel/create',data)
+        return post('https://api2-rc.teammodel.cn/channel/create',data)
     },
     //加入教室
     joinclass: function (data) {
-        return post('https://api2.teammodel.cn/channel/join',data)
+        return post('https://api2-rc.teammodel.cn/channel/join',data)
     },
     //发送消息
     tomessage: function (url,data) {

+ 6 - 3
HiTeachCC/ClientApp/src/filter/http.js

@@ -31,10 +31,13 @@ axios.interceptors.request.use(
                 config.headers['Content-Type'] = 'application/json'
             }
         } else if (config.url.indexOf('messages') != -1) {
-            var UserID = localStorage.getItem('loginBack')
+            console.log('进入发送消息头部')
+            var UserID = JSON.parse(localStorage.getItem('user'))
             config.headers = {
-                "X-Auth-UserID": UserID.teamModelId,
-                'X-Auth-Channel': localStorage.getItem('newClassnum'),
+                "Content-Type": "application/json",
+                "X-Auth-UserID": UserID.sub,
+                "X-Auth-Channel": localStorage.getItem('classNum'),
+                
             }
         } else {
             if (localStorage.getItem('TMDtoken')) {

+ 2 - 3
HiTeachCC/ClientApp/src/plugin/PublicRenderer.js

@@ -1,13 +1,12 @@
 import html2canvas from 'html2canvas';
 import echarts from 'echarts'
-import { Item } from 'paper';
+/*import { Item } from 'paper';*/
 import totaljson from '../assets/test/test.json'
 /**
  * 声明Y轴比例
  */
 //var scalingY = (window.innerHeight / totaljson.size.height).toFixed(2)
 var scalingY = 1
-console.log(scalingY, '缩放的Y轴')
 /**
  * 绘制矩形
  * @param layer 图层
@@ -877,7 +876,7 @@ function drawMath(stage, layer, group, item, url, hierarchy) {
         createMath.style.width = item.style.position.cx
         createMath.style.height = item.style.position.cy
         createMath.style.position = 'relative'
-        createMath.style.top = 999 + 'px'
+        createMath.style.top = 0 + 'px'
         createMath.style.fontSize = item.pitchFamily + 'px'
         //createMath.style.background ='#CC00FF'
         let svg = window.MathJax.tex2svg(mathtext)

+ 4 - 6
HiTeachCC/ClientApp/src/plugin/signalr.js

@@ -13,10 +13,10 @@ function signalRInfo(url,token){
         .withUrl(url,options)
         .configureLogging(signalR.LogLevel.Information)
         .build();
-         connection.on('onMessage', onMessage);
+        connection.on('onMessage', onMessage);
         connection.on('onConnected', onConnected);
-         connection.on('onDisconnected', onDisconnected);
-         connection.on('connectionSlow', onConnectionSlow);
+        connection.on('onDisconnected', onDisconnected);
+        connection.on('connectionSlow', onConnectionSlow);
         connection.onclose(() => {
             console.log('close connection')
             connection.start()
@@ -64,15 +64,13 @@ function sendMessage(sender, to, groupname, messageText,url) {
     }, getAxiosConfig()).then(resp => resp.data);
   }
 function onMessage(message) {
-    console.log(message,'收到消息!!!!')
+    console.log(message, '收到消息!!!!')
     message.id = counter++; // vue transitions need an id
     message.Timestamp = Math.floor(Date.now())
-    //console.log(message)
     data.messages.unshift(message);
     //hostMessageHandler(message)
   };
   function onConnected(message) {
-    console.log(message,'收到的内容')
     data.myConnectionId = message.ConnectionId;
     //  message.id = counter++; // vue transitions need an id
     //  data.messages.unshift(message);

+ 181 - 10
HiTeachCC/ClientApp/src/views/Board.vue

@@ -175,6 +175,7 @@
     </div>
 </template>
 <script>
+    import Vue from 'vue'
     import screenfull from 'screenfull'
     import Pdf from '@/views/pdf.vue'
     import html2canvas from 'html2canvas'
@@ -194,7 +195,7 @@
     import jwt_decode from "jwt-decode";
     // import E from "@/plugin/wangEditor.js"
     import moreoage from '../assets/99page/htex.json'
-    import { signalRInfo, sendMessage, onConnected, data } from "../plugin/signalr.js"
+    import { signalRInfo, sendMessage, onConnected, ImData } from "../plugin/signalr.js"
     const width = window.innerWidth
     const height = window.innerHeight
     let vm = {}
@@ -339,7 +340,12 @@
                     'channel_num': '',
                     'channel_rest_api': '',
                     'channel_url':''
-                }
+                },
+                IMcounter: 0,
+                //座位号
+                seatNum: 0,
+                //加入学生单个信息
+                studentAlone: {}
             }
         },
         methods: {
@@ -1750,7 +1756,7 @@
                     }
                 ).then(res => {
                     console.log(res,'申请教室成功')
-                    localStorage.getItem('classNum', res.channel_num)
+                    localStorage.setItem('classNum',res.channel_num)
                     this.classNum = res.channel_num
                     this.$api.joinclass(
                         {
@@ -1761,19 +1767,184 @@
                         }
                     ).then(res => {
                         this.imConnect = res
-                        console.log(res, this.imConnect,'加入教室成功')
-                        this.imConnectinfo(res.access_token,res.channel_url)
+                        console.log(res,'加入教室成功')
+                        this.imConnectinfo(this,res.access_token,res.channel_url)
                     }).catch(res => {
+                        console.log(res,'失败原因')
                         this.$Message.error('加入教室失败,请尝试重连!')
                     })
                 }).catch(res => {
+                    console.log(res)
                     this.$Message.error('通讯连接失败,请尝试重连!')
                 })
             },
             /*IM连接*/
-            imConnectinfo(acToken,url) {
-                signalRInfo(url, acToken);
-                this.$Message.success('通讯连接成功!')
+            imConnectinfo(that,acToken,urls) {
+                /* signalRInfo(url, acToken);*/
+                this.ConnectSignalR(that,urls, acToken)
+                //this.$Message.success('通讯连接成功!')
+            },
+            /*开始连接IM*/
+            ConnectSignalR(that,url, token) {
+                console.log(url, '连接地址')
+                console.log(token)
+                console.log(that)
+                const options = {
+                    accessTokenFactory: () => token
+                };
+                const connection = new signalR.HubConnectionBuilder()
+                    .withUrl(url, options)
+                    .configureLogging(signalR.LogLevel.Information)
+                    .build();
+                connection.on('onMessage', onMessage);
+                connection.on('onConnected', onConnected);
+                connection.on('onDisconnected', onDisconnected);
+                //connection.on('connectionSlow', onConnectionSlow);
+                connection.onclose(() => {
+                    console.log('close connection')
+                    connection.start()
+                        .then(() => console.log('re-connection!'))
+                        .catch(setTimeout(() => connection.start(), 5000));
+                }
+                );
+                console.log('connecting...');
+                connection.start()
+                    .then(() => console.log('connected!'))
+                    .catch(console.log('Start connect fail!!'));
+                function onConnected(message) {
+                    //data.myConnectionId = message.ConnectionId;
+                    message.id = this.IMcounter++; // vue transitions need an id
+                    //  data.messages.unshift(message);
+                }
+                function onMessage(message) {
+                    console.log(message, '收到消息!!!!')
+                    console.log(message.To[0],'111111111111')
+                    message.id = that.IMcounter++; // vue transitions need an id
+                    message.Timestamp = Math.floor(Date.now())
+                    var stateinfo = JSON.parse(message.Text)
+                    that.singnalRMessage(stateinfo, '8888', message.ConnectionId)
+                };
+                function onDisconnected(message) {
+                    message.id = this.IMcounter++; // vue transitions need an id
+                }
+            },
+            /*signalR发送消息*/
+            singnalRMessage(message, pincode, connectionId,) {
+                console.log('调用到发送消息方法')
+                var messages = message
+                let user = JSON.parse(localStorage.getItem('user'))
+                let sender = user.sub
+                let receive = []
+                receive.push(messages.sender)
+                let channelapi = this.imConnect.channel_api + '/messages'
+                let classnum = localStorage.getItem('classNum')
+                let time = Math.floor(Date.now())
+                //学生信息
+                var messageText = {}
+                if (messages.action === "Announce.Ask") {
+                    messageText = {
+                        "payload": {
+                            "announceURL": "",
+                            "announce": {
+                                "classState": "InProcess",
+                                "hostConnID": "",
+                                "className": "HiTeachCC",
+                                "memberCount": 0,
+                                "verifyMode": "Dynamic",
+                                "pincode": pincode,
+                                "channel": classnum,
+                                "memberList": [],
+                                "groupList": [],
+                                "apI_Version": 0,
+                                "allowVisitor": true,
+                                "schoolId": "HiTeachCC",
+                                "schoolName": "动态云端课程",
+                                "totalOptions": [
+                                    "A",
+                                    "B",
+                                    "C",
+                                    "D",
+                                    "E",
+                                    "F",
+                                    "G",
+                                    "H",
+                                    "I"
+                                ]
+                            }
+                        },
+                        "action": "Announce.Push",
+                        "clientType": "CC",
+                        "sender": "HiTeachCC-" + sender,
+                        "timestamp": time,
+                        "waitReturn": false
+                    }
+                } else if (messages.action === "MemberBinding") {
+                    this.seatNum = this.seatNum+1
+                    messageText = {
+                        "payload": {
+                            "activityRecordNumber": "198384384636751872",
+                            "id": messages.sender,
+                            "seatID": this.seatNum,
+                            "name": messages.payload.memberName,
+                            "className": "HiTeachCC",
+                            "schoolId": "HiTeachCC",
+                            "schoolName": "动态云端课程",
+                            "hostBlobUrl": "",
+                            "clientBlobUrl": "",
+                            "blobSAS": "",
+                            "errorCode": 0
+                        },
+                        "action": "BindingResult",
+                        "clientType": "CC",
+                        "sender": 'HiTeachCC-' + sender,
+                        "timestamp": time,
+                        "waitReturn": false
+                    }
+                    this.studentAlone = { "id": messages.sender, "accountid": messages.payload.memberID, "studentName": messages.payload.memberName, "sendTime": time, "headImg":''}
+                } else if (messages.action === "State.Get") {
+                    console.log(this.studentAlone,'查看数据')
+                    this.students = this.$store.state.students
+                    let oneStudent = {
+                        sort: this.seatNum,
+                        id: this.studentAlone.id,
+                        accountid: this.studentAlone.accountid,
+                        studentName: this.studentAlone.studentName,
+                        sendTime: this.studentAlone.sendTime,
+                        headImg: this.studentAlone.headImg,
+                        option: '',
+                        done: true,
+                        score: 0,
+                        rank: '',
+                        class: 'studyboxone',
+                        showcardclass: 'brand',
+                        answerclass: 'studyboxone',
+                        answerbrand: 'brand',
+                        statement: '',//发言,
+                        status: 'online'
+                    }
+                    if (oneStudent.headImg === undefined || oneStudent.headImg==='') {
+                        oneStudent.headImg = 'https://img.zcool.cn/community/01786557e4a6fa0000018c1bf080ca.png@1280w_1l_2o_100sh.png'
+                    }
+                    this.students.push(oneStudent)
+                    console.log(this.students,'学生情况')
+                    this.$store.state.students = this.students
+                }
+                if (messages.action !== "State.Get") {
+                    this.$api.tomessage(channelapi,
+                        {
+                            "connectionId": connectionId,
+                            "sender": sender,
+                            "isPrivate": true,
+                            "groupname": null,
+                            "to": receive,
+                            "text": JSON.stringify(messageText),
+                        }
+                    ).then(res => {
+                        console.log(res, '消息发送成功')
+                    }).catch(res => {
+                        console.log(res, '消息发送失败')
+                    })
+                }
             },
             /*白板缩放后 重新获取新的坐标未知*/
             getRelativePointerPosition(node) {
@@ -3057,7 +3228,7 @@
             },
             watchtatalpage() {
                 return this.$store.state.totalpage
-            }
+            },
         },
         watch: {
             watchUrl(e) {
@@ -3122,7 +3293,7 @@
             },
             watchtatalpage(e) {
                 console.log(e,'监听到总页数变化')
-            }
+            },
             ///*监听页数变化*/
             //watchloadingpage(e) {
             //    this.PdfshowLoading()