app.js
2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
var express = require('express');
var app = express();
var http = require('http').Server(app);
var io = require('socket.io')(http);
var nsp = io.of('/my-namespace');
var port = process.env.PORT || 5000;
var path = require('path');
var content;
io.on('connection', function(socket) {
socket.on('join', function(username){
})
// 进入房间后同步老师端内容
io.emit('programming.content', content || "");
// 开始直播
socket.on('start.live', function(msg) {
console.log('input ---- ' + msg);
io.emit('start.live', msg);
});
// 同步老师代码
socket.on('sync.programming', function(msg) {
console.log('input ---- ' + msg);
io.emit('programming.content', content);
});
// 老师录制代码
socket.on('teacher.programming', function(msg) {
console.log('input ---- ' + msg);
io.emit('teacher.programming', msg);
});
// 获取编程页面的内容
socket.on('programming.content', function(msg) {
console.log('programming.content ---- ' + msg);
content = msg;
});
// 编译操作
socket.on('programming.compile', function(msg) {
console.log('programming.compile ---- ' + msg);
io.emit('programming.compile', msg);
});
// 清空服务器
socket.on('programming.clear', function(msg) {
console.log('programming.clear ---- ' + msg);
content = msg;
io.emit('programming.content', msg);
});
// 切换编译 tab
socket.on('check.tab', function(msg) {
console.log('check.tab ---- ' + msg);
io.emit('check.tab', msg);
});
// 选择 menu
socket.on('select.menu', function(msg) {
console.log('select.menu ---- ' + msg);
io.emit('select.menu', msg);
});
// 记录输入的值
socket.on('stdin.value', function(msg) {
console.log('stdin.value ---- ' + msg);
io.emit('stdin.value', msg);
});
socket.on('disconnect', function (msg) {
console.log( msg);
});
socket.on('connect', function (msg) {
});
});
http.listen(port, function() {
console.log('listening on --------:' + port);
});