Commit 1028eedeb8cec074139cb56a1d88f5ca93e6c0c8
1 parent
62299c31
fix bug
Showing
7 changed files
with
155 additions
and
21 deletions
server/app.js
| ... | ... | @@ -10,9 +10,21 @@ var content; |
| 10 | 10 | |
| 11 | 11 | io.on('connection', function(socket) { |
| 12 | 12 | |
| 13 | - // | |
| 13 | + // 进入房间后同步老师端内容 | |
| 14 | 14 | io.emit('programming.content', content || ""); |
| 15 | 15 | |
| 16 | + // 开始直播 | |
| 17 | + socket.on('start.live', function(msg) { | |
| 18 | + console.log('input ---- ' + msg); | |
| 19 | + io.emit('start.live', msg); | |
| 20 | + }); | |
| 21 | + | |
| 22 | + // 同步老师代码 | |
| 23 | + socket.on('sync.programming', function(msg) { | |
| 24 | + console.log('input ---- ' + msg); | |
| 25 | + io.emit('programming.content', content); | |
| 26 | + }); | |
| 27 | + | |
| 16 | 28 | // 老师录制代码 |
| 17 | 29 | socket.on('teacher.programming', function(msg) { |
| 18 | 30 | console.log('input ---- ' + msg); |
| ... | ... | @@ -23,7 +35,6 @@ io.on('connection', function(socket) { |
| 23 | 35 | socket.on('programming.content', function(msg) { |
| 24 | 36 | console.log('programming.content ---- ' + msg); |
| 25 | 37 | content = msg; |
| 26 | - // io.emit('programming.content', msg); | |
| 27 | 38 | }); |
| 28 | 39 | |
| 29 | 40 | // 编译操作 |
| ... | ... | @@ -36,7 +47,13 @@ io.on('connection', function(socket) { |
| 36 | 47 | socket.on('programming.clear', function(msg) { |
| 37 | 48 | console.log('programming.clear ---- ' + msg); |
| 38 | 49 | content = msg; |
| 39 | - // io.emit('programming.content', msg); | |
| 50 | + io.emit('programming.content', msg); | |
| 51 | + }); | |
| 52 | + | |
| 53 | + // 切换编译 tab | |
| 54 | + socket.on('check.tab', function(msg) { | |
| 55 | + console.log('check.tab ---- ' + msg); | |
| 56 | + io.emit('check.tab', msg); | |
| 40 | 57 | }); |
| 41 | 58 | |
| 42 | 59 | // 选择 menu | ... | ... |
src/live/js/student.js
| 1 | 1 | $(function() { |
| 2 | 2 | var teacherId = document.getElementById('teacher'); |
| 3 | 3 | var studentId = document.getElementById('student'); |
| 4 | - var socket = io('https://live-api.gaoxiaobang.com'); | |
| 5 | - // var socket = io('http://live-api:5000'); | |
| 4 | + // var socket = io('https://live-api.gaoxiaobang.com'); | |
| 5 | + var socket = io('http://localhost:5000'); | |
| 6 | 6 | |
| 7 | 7 | var teacher = CodeMirror.fromTextArea(teacherId, { |
| 8 | 8 | value: '输入HTML代码', |
| ... | ... | @@ -19,22 +19,41 @@ $(function() { |
| 19 | 19 | smartIndent: false |
| 20 | 20 | }); |
| 21 | 21 | |
| 22 | + // 标准输入 | |
| 23 | + socket.on('start.live', function(msg) { | |
| 24 | + console.log('start.live ---- ' + msg); | |
| 25 | + var seconds = 2; | |
| 26 | + $('.countdown').show(); | |
| 27 | + var countdown = setInterval(function() { | |
| 28 | + $(".countdown h1").html(seconds); | |
| 29 | + seconds = seconds - 1; | |
| 30 | + if (seconds == -1) { | |
| 31 | + $(".countdown").hide(); | |
| 32 | + clearInterval(countdown); | |
| 33 | + | |
| 34 | + // | |
| 35 | + socket.on('teacher.programming', function(msg) { | |
| 36 | + console.log(msg); | |
| 37 | + var msgObj = JSON.parse(msg) | |
| 38 | + // student.setValue(msg) | |
| 39 | + processChangeObject(teacher, msgObj); | |
| 40 | + | |
| 41 | + $('#messages').append($('<li>').text(msg)); | |
| 42 | + window.scrollTo(0, document.body.scrollHeight); | |
| 43 | + }); | |
| 44 | + } | |
| 45 | + }, 1000); | |
| 46 | + }); | |
| 22 | 47 | |
| 23 | - socket.on('teacher.programming', function(msg) { | |
| 24 | - console.log(msg); | |
| 25 | - var msgObj = JSON.parse(msg) | |
| 26 | - // student.setValue(msg) | |
| 27 | - processChangeObject(teacher, msgObj); | |
| 28 | 48 | |
| 29 | - $('#messages').append($('<li>').text(msg)); | |
| 30 | - window.scrollTo(0, document.body.scrollHeight); | |
| 31 | - }); | |
| 32 | 49 | |
| 50 | + // 同步代码内容 | |
| 33 | 51 | socket.on('programming.content', function(msg) { |
| 34 | - console.log('programming.content ---- ' + msg); | |
| 35 | 52 | teacher.setValue(msg); |
| 36 | - // socket.emit('programming.content', teacher.getValue()); | |
| 37 | 53 | }); |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 38 | 57 | |
| 39 | 58 | // 选中 input |
| 40 | 59 | socket.on('select.menu', function(msg) { |
| ... | ... | @@ -48,6 +67,21 @@ $(function() { |
| 48 | 67 | $('#runtimeArgus').val(msg) |
| 49 | 68 | }); |
| 50 | 69 | |
| 70 | + // 切换 tab | |
| 71 | + socket.on('check.tab', function(msg) { | |
| 72 | + console.log('check.tab ---- ' + msg); | |
| 73 | + if(msg === 0){ | |
| 74 | + $('#cmprun-tabs a[href="#stdin"]').tab('show'); | |
| 75 | + }else if(msg === 1){ | |
| 76 | + $('#cmprun-tabs a[href="#cmpinfo"]').tab('show'); | |
| 77 | + }else if(msg === 2){ | |
| 78 | + $('#cmprun-tabs a[href="#stderr"]').tab('show'); | |
| 79 | + }else if(msg === 3){ | |
| 80 | + $('#cmprun-tabs a[href="#output"]').tab('show'); | |
| 81 | + } | |
| 82 | + // $('#runtimeArgus').val(msg) | |
| 83 | + }); | |
| 84 | + | |
| 51 | 85 | |
| 52 | 86 | |
| 53 | 87 | ... | ... |
src/live/js/teacher.js
| 1 | 1 | $(function(){ |
| 2 | 2 | var teacherId = document.getElementById('teacher'); |
| 3 | - var socket = io('https://live-api.gaoxiaobang.com'); | |
| 4 | - // var socket = io('http://live-api:5000'); | |
| 3 | + // var socket = io('https://live-api.gaoxiaobang.com'); | |
| 4 | + var socket = io('http://localhost:5000'); | |
| 5 | 5 | |
| 6 | 6 | // 初始化codemirror页面 |
| 7 | 7 | var teacher = CodeMirror.fromTextArea(teacherId, { |
| ... | ... | @@ -30,9 +30,9 @@ $(function(){ |
| 30 | 30 | }); |
| 31 | 31 | |
| 32 | 32 | // 链接时执行初始化代码 |
| 33 | - socket.on('programming.content', function(msg) { | |
| 33 | + // socket.on('programming.content', function(msg) { | |
| 34 | 34 | // teacher.setValue(msg); |
| 35 | - }); | |
| 35 | + // }); | |
| 36 | 36 | |
| 37 | 37 | |
| 38 | 38 | |
| ... | ... | @@ -98,11 +98,32 @@ $(function(){ |
| 98 | 98 | |
| 99 | 99 | LiveTeacher.init(); |
| 100 | 100 | |
| 101 | + | |
| 102 | + $('#cmprun-tabs').on('click', 'li', function(){ | |
| 103 | + console.log($(this).index()); | |
| 104 | + socket.emit('check.tab', $(this).index()); | |
| 105 | + }) | |
| 106 | + | |
| 107 | + | |
| 101 | 108 | // 开始录制 |
| 102 | 109 | function liveStartFun(){ |
| 103 | 110 | // $('.tip-wrap').show(); |
| 111 | + var seconds = 2; | |
| 112 | + socket.emit('start.live') | |
| 113 | + $('.countdown').show(); | |
| 104 | 114 | $('#liveStart').hide(); |
| 105 | 115 | $('#liveEnd').show(); |
| 116 | + | |
| 117 | + // 倒计时 | |
| 118 | + var countdown = setInterval(function() { | |
| 119 | + $(".countdown h1").html(seconds); | |
| 120 | + seconds = seconds - 1; | |
| 121 | + if (seconds == -1) { | |
| 122 | + $(".countdown").hide(); | |
| 123 | + clearInterval(countdown); | |
| 124 | + socket.emit('sync.programming'); | |
| 125 | + } | |
| 126 | + }, 1000); | |
| 106 | 127 | } |
| 107 | 128 | |
| 108 | 129 | // 确认开始录制 | ... | ... |
src/live/js/utils.js
| ... | ... | @@ -3,6 +3,40 @@ |
| 3 | 3 | * by Kira 2017-5-19 |
| 4 | 4 | */ |
| 5 | 5 | |
| 6 | + $(document).on('click', '#full-screen', function(event) { | |
| 7 | + event.preventDefault(); | |
| 8 | + launchFullScreen(document.body); | |
| 9 | + $('#back-screen').show(); | |
| 10 | + $('#full-screen').hide(); | |
| 11 | +}); | |
| 12 | +$(document).on('click', '#back-screen', function(event) { | |
| 13 | + exitFullscreen(); | |
| 14 | + $('#full-screen').show(); | |
| 15 | + $('#back-screen').hide(); | |
| 16 | +}) | |
| 17 | + | |
| 18 | +// 找到支持的方法, 使用需要全屏的 element 调用 | |
| 19 | +function launchFullScreen(element) { | |
| 20 | + if (element.requestFullscreen) { | |
| 21 | + element.requestFullscreen(); | |
| 22 | + } else if (element.mozRequestFullScreen) { | |
| 23 | + element.mozRequestFullScreen(); | |
| 24 | + } else if (element.webkitRequestFullscreen) { | |
| 25 | + element.webkitRequestFullscreen(); | |
| 26 | + } else if (element.msRequestFullscreen) { | |
| 27 | + element.msRequestFullscreen(); | |
| 28 | + } | |
| 29 | +} | |
| 30 | +function exitFullscreen() { | |
| 31 | + if (document.exitFullscreen) { | |
| 32 | + document.exitFullscreen(); | |
| 33 | + } else if (document.mozExitFullScreen) { | |
| 34 | + document.mozExitFullScreen(); | |
| 35 | + } else if (document.webkitExitFullscreen) { | |
| 36 | + document.webkitExitFullscreen(); | |
| 37 | + } | |
| 38 | +} | |
| 39 | + | |
| 6 | 40 | // 往编辑器中写入代码 |
| 7 | 41 | function processChangeObject(playbackcm, obj) { |
| 8 | 42 | ... | ... |
src/live/student.html
src/live/style/main.css
| ... | ... | @@ -238,6 +238,27 @@ button{ |
| 238 | 238 | .tips .tip-content{} |
| 239 | 239 | .tips .tip-btn{} |
| 240 | 240 | |
| 241 | +.countdown{ | |
| 242 | + position: absolute; | |
| 243 | + top: 0; | |
| 244 | + width: 100%; | |
| 245 | + height: 100%; | |
| 246 | + background: rgba(0, 0, 0, 0.7); | |
| 247 | + z-index: 9999; | |
| 248 | + display: none; | |
| 249 | +} | |
| 250 | +.countdown h1{ | |
| 251 | + font-size: 360px; | |
| 252 | + color: #fff; | |
| 253 | + display: block; | |
| 254 | + position: absolute; | |
| 255 | + font-weight: bold; | |
| 256 | + top: 50%; | |
| 257 | + left: 50%; | |
| 258 | + transform: translate(-50%, -50%); | |
| 259 | + margin-top: -35px; | |
| 260 | +} | |
| 261 | + | |
| 241 | 262 | |
| 242 | 263 | |
| 243 | 264 | ... | ... |
src/live/teacher.html
| ... | ... | @@ -73,10 +73,14 @@ |
| 73 | 73 | <button class="btn compile-btn" id="liveEnd">结束</button> |
| 74 | 74 | </div> |
| 75 | 75 | <div class="save-cancel"> |
| 76 | - <button class="btn compile-btn" id="liveSave" disabled="disabled">保存</button> | |
| 76 | + <!-- <button class="btn compile-btn" id="liveSave" disabled="disabled">保存</button> --> | |
| 77 | 77 | <button class="btn compile-btn" id="liveOut">关闭</button> |
| 78 | 78 | </div> |
| 79 | 79 | </div> |
| 80 | + | |
| 81 | + <div class="countdown"> | |
| 82 | + <h1>3</h1> | |
| 83 | + </div> | |
| 80 | 84 | |
| 81 | 85 | <div class="tip-wrap"> |
| 82 | 86 | <div class="tips"> | ... | ... |