Skip to content

Commit

Permalink
## 0.6.4
Browse files Browse the repository at this point in the history
 * 添加--controller命令
 * 解决host绑定bug
 * 解决页面刷新后,websocket通信失败的bug
  • Loading branch information
ksky521 committed Mar 1, 2014
1 parent 6946bcf commit 1d5b395
Show file tree
Hide file tree
Showing 12 changed files with 97 additions and 56 deletions.
24 changes: 14 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
nodePPT v0.6.2 —— 让每个人都能写出高大上的网页版ppt!
nodePPT v0.6.4 —— 让每个人都能写出高大上的网页版ppt!
=============
![nodePPT演示](https://raw.github.com/ksky521/nodePPT/master/demo.gif "nodePPT演示")
## 0.6.1
* 修复复制图片资源等bug
* 新增导出功能:``nodeppt generate``
* 去除grunt依赖
* 模板升级到ejs
* 重新组织了下lib下的代码

查看demo:[http://ppt.js8.in/](http://ppt.js8.in/)
## 0.6.4
* 添加--controller命令
* 解决host绑定bug
* 解决页面刷新后,websocket通信失败的bug

## 安装

Expand All @@ -25,9 +21,17 @@ nodeppt start -p port
```

```bash
nodeppt start -p port -d path/for/ppts
nodeppt start -p 8090 -d path/for/ppts
# 绑定host,默认绑定0.0.0.0
nodeppt start -p 8080 -d path/for/ppts -h 127.0.0.1
# 使用socket通信(按Q键显示/关闭二维码,手机扫描,即可控制)
# socket须知:1、注意手机和pc要可以相互访问,2、防火墙,3、ip
nodeppt start -c socket
# 不加-c默认使用postMessage,窗口联动,即list页面【多窗口】链接
```



### 创建
支持markdown语法快速创建网页幻灯片。

Expand Down
1 change: 1 addition & 0 deletions assets/css/nodeppt.css
Original file line number Diff line number Diff line change
Expand Up @@ -1544,6 +1544,7 @@ aside.gdbar img {
/* line 1133, ../scss/nodeppt.scss */
.qrcode p {
text-align: center;
line-height: 44px;
}

/* line 1139, ../scss/nodeppt.scss */
Expand Down
37 changes: 29 additions & 8 deletions assets/js/nodeppt.control.socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ var socketIOURL = '//' + location.host + '/socket.io/socket.io.js';
Slide.Control.add('socket', function(S, broadcast) {
S.clientUID = 0;

function time2str(time) {
time = '00' + time;
return time.substr(-2);
}
var qrcodeLink = function() {
//按 q显示控制区域二维码
document.addEventListener('keydown', function(e) {
Expand Down Expand Up @@ -38,10 +42,8 @@ Slide.Control.add('socket', function(S, broadcast) {
role: '', //角色
clientConnect: function() {
//角色是client,即被控制端,则连控制端服务器

webSocket.on('data from another client', function(data) {
var action = data.action;

switch (action) {
case 'from control order':
var fnName = data.fn;
Expand Down Expand Up @@ -96,7 +98,9 @@ Slide.Control.add('socket', function(S, broadcast) {
if (Socket.role === 'client') {
MixJS.loadJS('/js/qrcode.js', function() {
qrcodeLink();
var url = location.href.split('#')[0] + '#control' + uid;
var url = location.href.split('#')[0];
url += (!~url.indexOf('?')) ? '?' : '&';
url += 'iscontroller=1&clientid=' + uid;
var qrcode = new QRCode('qrcode', {
text: url,
width: 256,
Expand Down Expand Up @@ -134,15 +138,32 @@ Slide.Control.add('socket', function(S, broadcast) {

init: function(args) {
this.host = args.host || location.href;
this.clientUID = location.hash.slice(8);
this.clientUID = args.clientId;
// console.log(this.clientUID);
//角色,是否为控制端
if (args.isControl) {
console.log(this.clientUID);
this.role = 'control';
document.body.classList.add('popup');
document.body.classList.add('with-notes');

var $body = document.body;
$body.classList.add('popup');
$body.classList.add('with-notes');
var $timer = document.createElement('time');
$timer.id = '_timer_';
$body.appendChild($timer);
var hour = 0,
sec = 0,
min = 0;
timer = setInterval(function() {
sec++;
if (sec === 60) {
sec = 0;
min++;
}
if (min === 60) {
hour++;
}
$timer.innerHTML = ['时间:' + time2str(hour), time2str(min), time2str(sec) + ' 幻灯片:' + Slide.current + '/' + Slide.count].join(':');
}, 1000);
} else {
this.role = 'client';
}
Expand All @@ -166,4 +187,4 @@ Slide.Control.add('socket', function(S, broadcast) {
}
};
return Socket;
});
});
5 changes: 3 additions & 2 deletions assets/js/nodeppt.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
var touchDY = 0; //touch事件y数据
var touchStartX = 0;
var touchStartY = 0;
var ISSYNC = false;

var ctrlType = 'bind';
var doHash = true;
Expand Down Expand Up @@ -193,15 +194,15 @@
//切换动画

function doSlide(slideID, isSync) {
isSync = typeof isSync === 'boolean' ? isSync : true;
ISSYNC = typeof isSync === 'boolean' ? isSync : true;
slideID = slideID === undefined ? curIndex : (slideID | 0);
curIndex = slideID;

// $container.style.marginLeft = -(slideID * slideWidth) + 'px';
updateSlideClass();
setProgress();
//发布slide切换状态广播
isSync && $B.fire('slide change ID', {
ISSYNC && $B.fire('slide change ID', {
slideID: slideID
});
if (doHash) {
Expand Down
1 change: 1 addition & 0 deletions assets/scss/nodeppt.scss
Original file line number Diff line number Diff line change
Expand Up @@ -1132,6 +1132,7 @@ aside.gdbar {
}
p{
text-align: center;
line-height: 44px;
}
}

Expand Down
4 changes: 3 additions & 1 deletion bin/nodeppt
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ var opts = {
'-f': '--file',
'-o': '--output',
'-a': '--all',
'-h': '--host'
'-h': '--host',
'-c': '--controller'
};

var argv = parseArgs(process.argv);

var action = argv.slice(2, 3).toString();

if (typeof nodePPT[action] === 'function') {
Expand Down
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.6.4
* 添加--controller命令,简写-c
* 解决host绑定bug
* 解决页面刷新后,websocket通信失败的bug

## 0.6.3
* 添加--host
* 添加port占用报错
Expand Down
7 changes: 4 additions & 3 deletions lib/md_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ marked.setOptions({
var emptyFn = function(str) {
// console.log(str);
};
var parser = function(string, callback) {
var parser = function(string, callback, argvObj, queryObj) {
if (typeof callback !== 'function') {
callback = emptyFn;
}
Expand All @@ -46,12 +46,13 @@ var parser = function(string, callback) {
// console.log(contents.length, slidesSetting);
//第一个是封面
var cover = contents.shift();

var json = parseCover(cover);
var config = require(path.join(libDir, '../package.json'));
json.nodeppt_version = config.version
json.nodeppt_site = config.site;
json = mix(defaultJSON, json);
json = mix(defaultJSON, json, {
query: mix(queryObj,argvObj || {})
});
if (json.files) {
var files = json.files.split(/\s?,\s?/);
json.files = files.map(function(v) {
Expand Down
5 changes: 3 additions & 2 deletions lib/nodePPT.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ var ppt = module.exports = {
console.log(' | nodeppt start -p 8000: 启动8000端口 |'.bold.green);
console.log(' | nodeppt start -p 8000 -d ./ 指定路径 |'.bold.green);
console.log(' | nodeppt start -h 127.0.0.1 指定host |'.bold.green);
console.log(' | nodeppt start -c socket 用socket双屏控制 |'.bold.green);
console.log(' | nodeppt create fileName: 创建一个ppt |'.bold.green);
console.log(' | nodeppt pdf url -o a.pdf: 输出一个pdf |'.bold.green);
console.log(' | nodeppt generate path: 输导出html |'.bold.green);
Expand All @@ -85,7 +86,7 @@ var ppt = module.exports = {
var argsObj = {
port: 8080,
dir: '',
host: '127.0.0.1',
host: '0.0.0.0',
file: ''
};
args = args.join(' ').split('--');
Expand Down Expand Up @@ -118,7 +119,7 @@ var ppt = module.exports = {
}
}

require(libDir + '/server').start(argsObj.port, dir, argsObj.host);
require(libDir + '/server').start(argsObj.port, dir, argsObj.host, argsObj);
},
create: function(args) {
var curRoot = process.cwd();
Expand Down
36 changes: 18 additions & 18 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ var storeMemory = new MemoryStore({
reapInterval: 60000 * 10
});

module.exports.start = function(port, pptDir) {
module.exports.start = function(port, pptDir, host, argvObj) {
port = parseInt(port, 10) || 8080;
var app = startApp(port, pptDir);
var app = startApp(port, pptDir, host, argvObj);
var io = require('socket.io').listen(app, {
log: false,
origins: '*:*' //解决同源策略
Expand Down Expand Up @@ -61,6 +61,7 @@ module.exports.start = function(port, pptDir) {

socket.uid = uid;
console.log('socket.io:' + uid);

sockets[uid] = socket;
//监听添加map
socket.on('add client', function(data) {
Expand Down Expand Up @@ -95,14 +96,14 @@ module.exports.start = function(port, pptDir) {
action: 'leave',
leaveUid: uid
});
delete sockets[targetUid];
delete sockets[uid];
});
});

}

function startApp(port, dir, host) {
host = host || '127.0.0.1';
function startApp(port, dir, host, argvObj) {
host = host || '0.0.0.0';
var staticDir = path.normalize(path.join(__dirname, '../assets')) + path.sep;
var pptDir = (dir || path.join(__dirname, '../ppts')) + path.sep;
try {
Expand Down Expand Up @@ -136,7 +137,7 @@ function startApp(port, dir, host) {
realPath = pptDir + path.basename(url);
ext = 'html';
} else if (dirname === '/') {
pptlist(res, pptDir);
pptlist(res, pptDir, argvObj);
return;
} else if (dirname === '/md') {
var uid = req.session.uid;
Expand All @@ -149,10 +150,10 @@ function startApp(port, dir, host) {
}
url = URL.parse(req.url).pathname;
var basename = path.basename(url);

var queryObj = URL.parse(req.url, true).query;
realPath = pptDir + basename;
console.log('markdown', realPath);
markdown(realPath, basename, res)
markdown(realPath, basename, res, argvObj, queryObj);
return;
} else {
//优先选择pptDir的静态资源
Expand All @@ -163,22 +164,22 @@ function startApp(port, dir, host) {
ext = path.extname(realPath);
ext = ext ? ext.slice(1) : 'unknown';
}
assets(realPath, ext, url, res);
assets(realPath, ext, url, res, argvObj);
}).listen(port, host);
return app.on('listening', function() {
var server = app.address();
console.log('ppt directory : '.cyan + pptDir + '\n' + 'assets directory : '.cyan + staticDir);
console.log('nodeppt server started : '.bold.green + server.address + ':' + server.port);
}).on('error', function(e) {
if (e.code === 'EADDRINUSE') {
if (e.code === 'EADDRINUSE' || e.code === 'EACCES') {
console.log('ERROR: '.red + 'port ' + port + ' is in use!');
} else {
console.log('ERROR: '.red + e.code);
console.log('ERROR: '.red + 'server start ' + host + ':' + port + ' info : ' + e.code);
}
});
}

function assets(realPath, ext, url, res) {
function assets(realPath, ext, url, res, argvObj) {
//静态资源
if (fs.existsSync(realPath)) {

Expand Down Expand Up @@ -215,12 +216,11 @@ function page404(res, url) {
res.end();
}

function markdown(realPath, url, res) {

function markdown(realPath, url, res, argvObj, queryObj) {
if (fs.existsSync(realPath)) {
var content = fs.readFileSync(realPath, 'utf-8').toString();
try {
var html = md_parser(content, function() {});
var html = md_parser(content, function() {}, argvObj, queryObj);
res.writeHead(200, {
'Powered-By': 'nodePPT',
'Content-Type': mimes.html
Expand All @@ -235,7 +235,6 @@ function markdown(realPath, url, res) {
res.end(e.toString());
}


} else {
page404(res, url);
}
Expand All @@ -249,7 +248,7 @@ function markdown(realPath, url, res) {
* @return {[type]} [description]
*/

function pptlist(res, dir) {
function pptlist(res, dir, argvObj) {
var staticDir = path.join(__dirname, '../assets') + '/';
res.writeHead(200, {
'Powered-By': 'nodePPT',
Expand Down Expand Up @@ -289,7 +288,8 @@ function pptlist(res, dir) {
title = filename;
}
var url = '/md/' + filename;
list += '<li><a class="star" href="' + url + '" target="_blank">' + title + '</a> &nbsp; [<a href="' + url + '?_multiscreen=1" target="_blank" title="多窗口打开">多窗口</a>]</li>';
list += '<li><a class="star" href="' + url + '" target="_blank">' + title + '</a>';
list += (argvObj.controller === 'socket' ? '' : '&nbsp; [<a href="' + url + '?_multiscreen=1" target="_blank" title="多窗口打开">多窗口</a>]') + '</li>';
}, '', '', function(filename) {
return /\.(md|markdown)$/.test(filename);
});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "nodeppt",
"jsname": "nodeppt",
"description": "Create a PowerPoint presentation with Markdown",
"version": "0.6.3",
"version": "0.6.4",
"site": "https://github.com/ksky521/nodePPT",
"author": {
"name": "Theo Wang",
Expand Down
Loading

0 comments on commit 1d5b395

Please sign in to comment.