第73篇一对多之两个学生相互刷新解决(二)重写最后一张白板的刷新及array_udiff_assoc及array_udiff_uassoc

来源:互联网 发布:平板电脑安装windows 编辑:程序博客网 时间:2024/05/17 06:54

关键词:两个学生相互刷新解决,重写最后一张白板的刷新,array_udiff_assoc,array_udiff_uassoc

一、两个学生相互刷新解决

1.1 测试平台--本地服务器运行平台

老师端:https://localhost:9101/demos/index.html?roomid=888&t=600

学生一:

https://localhost:9101/demos/student.html?studentId=1001&userAvatar=http://123.57.206.36:8003/uploadfiles/2016/11/1479740395ZMJkiF.jpg&t=600#888

学生二:                   

https://localhost:9101/demos/student.html?studentId=1002&userAvatar=http://123.57.206.36:8003/uploadfiles/2016/11/1480494624FDjMGetutor.png&t=600#888

学生三:

https://localhost:9101/demos/student.html?studentId=1003&userAvatar=http://123.57.206.36:8003/uploadfiles/2016/11/1480475198N2F0kntutor.png&t=600#888

1.2 两个学生时,相互刷新

基本可以了,就是学生端共享白板往老师端传数据时,同步还不是太及时。

  现在有个思路是:把学生的最后一张传到老师端显示到共享白板上,这样会减少延迟。因为传到学生端的共享白板,之后,还需要学生端的共享白板同步到老师那里,这样,增加了延迟。

1.3 直接传学生最后一张没写完的私有白板到老师端共享白板显示

实现了,如下:

1上来先发个消息给学生端,拉白板:函数getPriWB---index.html

   //拉学生白板-------------------------------------------------------3.1

   function getPriWB(studentVideoId) {

       connection.send({

                          studentVideoIdPri:studentVideoId,

           stopTimer:true

 

                  });

                  $("#PriWB_controlVideoAudioDiv").remove();

    }

注:比着之前,没变化。

2学生端接到消息后,做两件事

事情一:停止其他学生刷私有白板到老师端

   //老师查看学生的私有白板之前,先停止其他学生的私有白板上传刷新----事情一

if(event.data.studentVideoIdPri!==connection.localMediaStreamId &&

event.data.stopTimer){

       if(typeof pushPritoShaWB_timer !== 'undefined'){

           clearInterval(pushPritoShaWB_timer);

       }

       return;

    }

事情二:用计时器,刷指定学生私有白板到老师端

       //传私有白板图片数组给老师端--------------------------事情二

if(event.data.studentVideoIdPri===connection.localMediaStreamId &&

event.data.stopTimer){

       //把学生最后一页私有白板传到共享白板上去

        pushPritoShaWB_timer = setInterval("pushPritoShaWB()",1000);

        return;

}

注:记得,最后有个return,之前不写时,学生间老是相互影响,这个刷新包括过往私有白板和最后一张白板,函数如下:

//拉学生的私有白板到共享白板

function pushPritoShaWB(){

    var imgIdPWBS='555';

    designer.saveImgPrivate('image/png',imgIdPWBS, function(dataURLPWBS, imgIdPWBS) {

        connection.send({

                studentPri: true,

                stuPriDataURLArr:dataURLSPriTShaArr,

                lastPriWB:dataURLPWBS

        });

    });

}

3老师端接到传过来的私有白板数组和最后一张白板时,进行分别显示如下:

  //获取指定学生私有白板图片数组及最后一张白板进行实时展示

   if (event.data.studentPri) {

       //把收到的私有白板数组展示出来,供老师查看

        stuPriUrlIdArray = event.data.stuPriDataURLArr;

       if(isArray(stuPriUrlIdArray) && stuPriUrlIdArray.length){

               $('#picContentStuPri').html("");

                 for (var i = 0; i <stuPriUrlIdArray.length; i++) {

                     if(isArray(stuPriUrlIdArray)){

                                       dataURL_Pri =stuPriUrlIdArray[i];

                                            var j = i+1;

                                            varpageIndexPri = i + 1;

                                            varimgContentPri = ' <span class="img_divStuPritea_base64_selectStuPri"><img id= "arr_base64_imgStuPri' + j + '"src = "'+dataURL_Pri+'" name="thumbnailStuPri" class="tea_base64StuPri"><span class="page_index_divStuPri">' + pageIndexPri +'</span> </span>';

                                            $(imgContentPri).appendTo($("#picWrapStuPriPic.picContentStuPri"));

                                            $(".tea_base64StuPri").off("click");

                                            $(".tea_base64StuPri").on("click",onImgClickPrivate);

                     }

                }

             }

        //最后一张白板展示到共享白板上去

        designer.undo('all');

       designer.addImgByUrl(event.data.lastPriWB,true);

       return;

    }

注:函数designer.addImgByUrl不加参数true,会显示成一张小图片。

 

总结:这样一来,显示更迅速,并且私有白板列表也会实时更新。

1.4 视频下显示学生姓名或电话

二、php

2.1 PHP array_udiff_assoc() 函数

1定义和用法

array_udiff() 函数用于比较两个(或更多个)数组的键名和键值,并返回差集。

注释:该函数使用内建函数比较键名,使用用户自定义函数比较键值!

该函数比较两个(或更多个)数组的键名和键值,并返回一个差集数组,该数组包括了所有在被比较的数组(array1)中,但是不在任何其他参数数组(array2 或 array3 等等)中的键名和键值。

2语法

array_udiff_assoc(array1,array2,array3...,myfunction)

3看个例子

注:只有键和值都相等时,才会不出现在结果集中。

2.2PHP array_udiff_uassoc() 函数

1定义和用法

array_udiff_uassoc() 函数用于比较两个(或更多个)数组的键名和键值,并返回差集。

注释:该函数使用两个用户自定义函数进行比较;第一个函数比较键名,第二个函数比较键值!

该函数比较两个(或更多个)数组的键名和键值,并返回一个差集数组,该数组包括了所有在被比较的数组(array1)中,但是不在任何其他参数数组(array2 或 array3 等等)中的键名和键值。

2语法

array_udiff_uassoc(array1,array2,array3...,myfunction_key,myfunction_value)

3看个例子如下:

注:必须满足两个自定义函数才从结果集里移除。

2017年3月14日星期二

1 0
原创粉丝点击