# Danmaku **Repository Path**: tompes/Danmaku ## Basic Information - **Project Name**: Danmaku - **Description**: A high-performance JavaScript danmaku engine. 高性能弹幕引擎库 - **Primary Language**: JavaScript - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-07-01 - **Last Updated**: 2023-11-01 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Danmaku [](https://travis-ci.org/weizhenye/Danmaku) [](https://coveralls.io/github/weizhenye/Danmaku?branch=master) [](https://david-dm.org/weizhenye/Danmaku) [](https://www.npmjs.com/package/danmaku) [](https://github.com/weizhenye/Danmaku/blob/master/LICENSE) [](https://unpkg.com/danmaku/dist/danmaku.min.js) [](https://saucelabs.com/u/danmaku) Danmaku is a JavaScript library to display flying comments on HTML5 video. It can also display comments to your container in real time without timeline or be used with HTML5 audio. [Demo](https://danmaku.js.org/) [中文文档](https://github.com/weizhenye/Danmaku/wiki/%E4%B8%AD%E6%96%87%E6%96%87%E6%A1%A3) ## Installation You can install it by using npm or bower: ```bash npm install danmaku ``` ```bash bower install danmaku ``` You can also download [danmaku.min.js](https://github.com/weizhenye/Danmaku/raw/master/dist/danmaku.min.js) directly and include it in your HTML. ## Usage ### Video mode ```html ``` ### Audio mode ```html
``` ### Live mode To display comments in real time, you need to set up server and use something like [Socket.IO](http://socket.io/). Danmaku is just receiving comments data and display them to container. Here is a simple example using with Socket.IO and Node.js. Server: ```js const app = require('http').createServer(handler); const io = require('socket.io')(app); app.listen(80); function handler(req, res) { // your handler... } io.on('connection', socket => { socket.on('danmaku', comment => { socket.broadcast.emit('danmaku', comment); }); }); ``` Client: ```html ``` ## API ### Initialization ```js var danmaku = new Danmaku(); danmaku.init({ // The stage to display comments will be appended to container. container: document.getElementById('my-container'), // Danmaku will create a container automatically and append video to the // container if container isn't assigned. video: document.getElementById('my-video'), // You should always assign a container when using audio mode. audio: document.getElementById('my-audio'), // Array of comment, you can find its format in `danmaku.emit` API. comments: [], // You can use 'DOM' engine or 'canvas' engine to render comments. // Canvas engine may more efficient than DOM however it costs more memory. // 'DOM' by default, available in all mode. engine: 'canvas', // You can also set speed by using `danmaku.speed` API. speed: 144 }); ``` Or just put options here: ```js var danmaku = new Danmaku({/* options */}); ``` ### Emit a comment ```js danmaku.emit({ text: 'example', // When using DOM engine, `text` can be parsed as HTML if `html` is `true`. // You should never pass in users' inputs directly to avoid XSS. // `false` by default. html: false, // 'rtl'(right to left) by default, available mode: 'ltr', 'rtl', 'top', 'bottom'. mode: 'rtl', // Specified in seconds, if not provided when using with media(video or audio), // it will be set to `media.currentTime`. Not required in live mode. time: 233.3, // When using DOM engine, Danmaku will create a