This commit is contained in:
DIYgod
2016-05-16 04:00:02 +08:00
parent 492da45d98
commit de8b3387cb
8 changed files with 131 additions and 99 deletions
-2
View File
@@ -49,8 +49,6 @@ $ npm run build
- [ ] 右键
- [ ] 全屏进度控制
## LICENSE
MIT © [DIYgod](http://github.com/DIYgod)
+27 -90
View File
@@ -1,169 +1,106 @@
{
"code": 1,
"danmaku": [
{
"player": "9E2E3368B56CDBB4",
"author": "DIYgod",
"time": "2.8",
"time": 2.8,
"text": "此生无悔入",
"color": "#f00",
"type": "right"
},
{
"player": "9E2E3368B56CDBB4",
"author": "DIYgod",
"time": "1.6",
"time": 1.6,
"text": "此生无悔入四月来世愿做友人A",
"color": "#ff0",
"type": "right"
},
{
"player": "9E2E3368B56CDBB4",
"author": "DIYgod",
"time": "0.4",
"time": 0.4,
"text": "此生无悔入四月来世",
"color": "#f00",
"type": "right"
},
{
"player": "9E2E3368B56CDBB4",
"author": "DIYgod",
"time": "0.8",
"time": 0.8,
"text": "此生无悔入四月来世愿做友人A此生无悔入四月来世愿做",
"color": "#0f0",
"type": "right"
},
{
"player": "9E2E3368B56CDBB4",
"author": "DIYgod",
"time": "1.2",
"time": 1.2,
"text": "此生无悔入四月来世愿做友人",
"color": "#00f",
"type": "right"
},
{
"player": "9E2E3368B56CDBB4",
"author": "DIYgod",
"time": "2.0",
"time": 2.0,
"text": "此生无悔入四月来世愿做友人A",
"color": "#f0f",
"type": "right"
},
{
"player": "9E2E3368B56CDBB4",
"author": "DIYgod",
"time": "2.4",
"time": 2.4,
"text": "此生无悔入四月来世愿做友人A",
"color": "#0ff",
"type": "right"
},
{
"player": "9E2E3368B56CDBB4",
"author": "DIYgod",
"time": "88.4",
"text": "此生无悔入四月来世愿做友人A",
"color": "#fff",
"type": "right"
},
{
"author": "DIYgod",
"time": "88.4",
"text": "此生无悔入四月来世愿做友人A",
"color": "#fff",
"type": "right"
},
{
"author": "DIYgod",
"time": "88.4",
"text": "此生无悔入四月来世愿做友人A",
"color": "#fff",
"type": "right"
},
{
"author": "DIYgod",
"time": "87.8",
"text": "此生无悔入",
"color": "#f00",
"type": "right"
},
{
"author": "DIYgod",
"time": "86.6",
"text": "此生无悔入四月来世愿做友人A",
"color": "#ff0",
"type": "right"
},
{
"author": "DIYgod",
"time": "85.4",
"text": "此生无悔入四月来世",
"color": "#f00",
"type": "right"
},
{
"author": "DIYgod",
"time": "85.8",
"text": "此生无悔入四月来世愿做友人A此生无悔入四月来世愿做",
"color": "#0f0",
"type": "right"
},
{
"author": "DIYgod",
"time": "86.2",
"text": "此生无悔入四月来世愿做友人",
"color": "#00f",
"type": "right"
},
{
"author": "DIYgod",
"time": "87.0",
"text": "此生无悔入四月来世愿做友人A",
"color": "#f0f",
"type": "right"
},
{
"author": "DIYgod",
"time": "87.4",
"text": "此生无悔入四月来世愿做友人A",
"color": "#0ff",
"type": "right"
},
{
"author": "DIYgod",
"time": "88.4",
"text": "此生无悔入四月来世愿做友人A",
"color": "#fff",
"type": "right"
},
{
"author": "DIYgod",
"time": "2.4",
"time": 2.4,
"text": "此生无悔入四月来世",
"color": "#f00",
"type": "top"
},
{
"player": "9E2E3368B56CDBB4",
"author": "DIYgod",
"time": "2.8",
"time": 2.8,
"text": "此生无悔入四月",
"color": "#0f0",
"type": "top"
},
{
"player": "9E2E3368B56CDBB4",
"author": "DIYgod",
"time": "4.0",
"time": 4.0,
"text": "此生无悔入四月来世愿做友人A",
"color": "#ff0",
"type": "top"
},
{
"player": "9E2E3368B56CDBB4",
"author": "DIYgod",
"time": "4.0",
"time": 4.0,
"text": "此生无悔入四做友人A",
"color": "#f0f",
"type": "top"
},
{
"player": "9E2E3368B56CDBB4",
"author": "DIYgod",
"time": "6",
"time": 6,
"text": "此生无悔入",
"color": "#f00",
"type": "bottom"
},
{
"player": "9E2E3368B56CDBB4",
"author": "DIYgod",
"time": "6.4",
"time": 6.4,
"text": "此生无悔入四月来世愿做友人A",
"color": "#f0f",
"type": "bottom"
+2 -2
View File
@@ -65,8 +65,8 @@
pic: 'http://devtest.qiniudn.com/poster.jpg'
},
danmaku: {
get: 'danmaku.json',
add: 'add'
id: '9E2E3368B56CDBB4',
api: 'https://dan.anotherhome.net/'
}
});
dp.init();
+1 -1
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
+83
View File
@@ -0,0 +1,83 @@
var http = require('http');
var url = require('url');
var util = require('util');
var querystring = require('querystring');
var mongoose = require('mongoose');
var mongodbUrl = 'mongodb://localhost:27017/danmaku';
var express = require('express');
var app = express();
var danmakuSchema = new mongoose.Schema({
player: String,
author: String,
time: Number,
text: String,
color: String,
type: String
});
var danmaku = mongoose.model('dan', danmakuSchema);
app.all('*', function(req, res, next) {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Headers', 'Content-Type, Content-Length, Authorization, Accept, X-Requested-With , yourHeaderFeild');
res.header('Access-Control-Allow-Methods', 'PUT, POST, GET, DELETE, OPTIONS');
if (req.method == 'OPTIONS') {
res.send(200);
}
else {
next();
}
});
app.get('/', function(req, res) {
mongoose.connect(mongodbUrl);
var db = mongoose.connection;
db.on('error',console.error);
var id = url.parse(req.url,true).query.id;
db.once('open', function() {
danmaku.find({player: id}, function (err, data) {
if (err) {
console.error(err);
}
var json = `{"code": 1,"danmaku":[`;
for (var i = 0; i < data.length; i++) {
json += JSON.stringify(data[i]);
if (i !== data.length - 1) {
json += `,`;
}
}
json += `]}`;
res.write(json);
res.end();
db.close();
})
});
});
app.post('/', function (req, res) {
var body = '', jsonStr;
req.on('data', function (chunk) {
body += chunk;
});
req.on('end', function () {
try {
jsonStr = JSON.parse(body);
} catch (err) {
jsonStr = null;
}
// jsonStr ? res.send({"status":"success", "name": jsonStr.test}) : res.send({"status":"error"});
var dan = new danmaku({player: jsonStr.player, author: jsonStr.author, time: jsonStr.time, text: jsonStr.text, color: jsonStr.color, type: jsonStr.type});
dan.save(function (err, d) {
if (err){
console.error(err);
}
});
});
});
app.listen(1207);
+13
View File
@@ -0,0 +1,13 @@
{
"name": "DPlayer_nodejs",
"version": "0.0.1",
"description": "",
"main": "index.js",
"author": "DIYgod",
"license": "MIT",
"devDependencies": {},
"dependencies": {
"express": "^4.13.4",
"mongoose": "^4.1.9"
}
}
+4 -3
View File
@@ -300,7 +300,7 @@
this.trigger('playing');
const item = this.dan[this.danIndex];
if (item && this.audio.currentTime >= item.time) {
if (item && this.audio.currentTime >= parseFloat(item.time)) {
this.danmakuIn(item.text, item.color, item.type);
this.danIndex++;
}
@@ -780,7 +780,7 @@
}
}
};
xhr.open('get', this.option.danmaku.get, true);
xhr.open('get', this.option.danmaku.api + '?id=' + this.option.danmaku.id, true);
xhr.send(null);
}
else {
@@ -870,6 +870,7 @@
}
const danmakuData = {
id: this.option.danmaku.id,
time: this.audio.currentTime,
text: commentInput.value,
color: this.element.querySelector('input[name="dplayer-danmaku-color"]:checked').value,
@@ -886,7 +887,7 @@
}
}
};
xhr.open('post', this.option.danmaku.add, true);
xhr.open('post', this.option.danmaku.api, true);
xhr.send(JSON.stringify(danmakuData));
commentInput.value = '';