Skip to content
This repository has been archived by the owner on Mar 8, 2024. It is now read-only.

Commit

Permalink
Merge pull request #6 from proshunsuke/v0.1.0
Browse files Browse the repository at this point in the history
V0.1.0
  • Loading branch information
proshunsuke authored Nov 23, 2016
2 parents c96bf6f + 091c615 commit f0af475
Show file tree
Hide file tree
Showing 49 changed files with 3,001 additions and 615 deletions.
92 changes: 79 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

A client library for niconico live broadcast.

User live broadcast, channel broadcast, official broadcast comments can be obtained.

## Installation

```
Expand All @@ -20,13 +22,10 @@ yarn add niconama-client

## Examples

### login
### Login
```javascript
import NiconamaClient from 'niconama-client';

const email = 'email';
const password = 'password';

const client = new NiconamaClient();
client.login(email, password)
.then( session => {
Expand All @@ -35,26 +34,93 @@ client.login(email, password)
// user_session=user_session_00000_123abc
```

### comments of all rooms (co00000, 立ち見A, 立ち見B, etc)
### Comments of all rooms (co00000, 立ち見A, 立ち見B, etc)
```javascript
import NiconamaClient from 'niconama-client';

const liveId = 'liveId';
const session = 'session';

const client = new NiconamaClient();
client.liveComments(liveId, session, comment => {
client.setLiveInfo(liveId, session);
const commentStream = client.createLiveCommentStream();
commentStream.on('readable', () => {
const comment = commentStream.read();
console.log(
`コメ番: ${comment['no']}\tユーザーID: ${comment['user_id']}\t時間: ${timestampToDateformat(comment['date'])}\t
コメント: ${comment['comment']}\tプレミア: ${comment['premium']}\t NGスコア: ${comment['score']}\t 部屋: ${comment['roomLabel']}`
`コメ番: ${comment.no}\tユーザーID: ${comment.user_id}\t時間: ${timestampToDateformat(comment.date)}\t
コメント: ${comment.comment}\tプレミア: ${comment.premium}\t NGスコア: ${comment.score}\t 部屋: ${comment.roomLabel}`
);
});

client.liveComments();

// コメ番: 10 ユーザーID: aaa 時間: 22:20:4 コメント: comment1 プレミア: 2 部屋: 立ち見C列
// コメ番: 106 ユーザーID: bbb 時間: 22:20:4 コメント: comment2 プレミア: 2 部屋: 立ち見B列
// コメ番: 10 ユーザーID: ccc 時間: 22:20:4 コメント: comment3 プレミア: 2 部屋: 立ち見D列
// ...
});
// ...
```

### Do comment

```javascript
import NiconamaClient from 'niconama-client';

const client = new NiconamaClient();
client.setLiveInfo(liveId, session);

client.liveComments()
.then( () => {
client.doLiveComment(comment, option);
});
```

Detailed examples are [here](https://github.com/proshunsuke/niconama-client/tree/master/examples)

## Methods

## login(email: string, password: string)

- Returns: `Promise.<session>`

Login to niconico, and receive session.

## setLiveInfo(liveId: string, session: string)

Create Live instance with liveId and session. liveId is the string starting with `lv` in niconico live URL

ex. http://live.nicovideo.jp/watch/lv0000000

In this case, `lv0000000` is the liveId

## liveComments()

- Returns: `Promise.<>`

Get comments from niconico comment servers

## createLiveCommentStream()

- Returns: `LiveCommentStream`

Create LiveCommentStream instance. Call this method after calling [liveComments()](#livecomments)

## doLiveComment(comment: string[, option: string])

Do comment to niconico live broadcast. Call this method after calling [liveComments()](#livecomments)

Options argument is a string with space separator. ex: `184 red big`. Options are below

| items | details |
|:------------- |:-------------|
| size | small, big |
| vertical position | ue/top, shita/bottom |
| horizontal position | migi/right, hidari/left |
| color(not premium) | white, red, green, blue, cyan, yellow, purple, pink, orange |
| color(premium or broadcaster) | niconicowhite/white2, marineblue/blue2, madyellow/yellow2, passionorange/orange2, nobleviolet/purple2, elementalgreen/green2, truered/red2, black |
| color(psyllium) | passionorange/orange2, nobleviolet/purple2, elementalgreen/green2, truered/red2, black |
| other | 184, hidden |

## TODO

- In channel broadcast, cannot get comments, for examples, from アリーナ席 to 立ち見席 and from 立ち見席 to アリーナ席.

## License

[MIT](LICENSE) © [pro_shunsuke](https://twitter.com/pro_shunsuke)
6 changes: 0 additions & 6 deletions dist/addrPorts.js

This file was deleted.

128 changes: 0 additions & 128 deletions dist/live.js

This file was deleted.

101 changes: 101 additions & 0 deletions dist/live/commentStream/liveCommentStream.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

var _stream = require('stream');

var _commentInfo = require('../model/commentInfo');

var _commentInfo2 = _interopRequireDefault(_commentInfo);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }

/**
*
* LiveCommentStream
*/
var LiveCommentStream = function (_Duplex) {
_inherits(LiveCommentStream, _Duplex);

/**
*
* @param options
*/
function LiveCommentStream(options) {
_classCallCheck(this, LiveCommentStream);

var _this = _possibleConstructorReturn(this, (LiveCommentStream.__proto__ || Object.getPrototypeOf(LiveCommentStream)).call(this, options));

if (!options) options = {};
options.objectMode = true;
if (_stream.Duplex instanceof Function) _stream.Duplex.call(_this, options);
return _this;
}

/**
*
* @param chunk
* @param encoding
* @param callback
* @private
*/


_createClass(LiveCommentStream, [{
key: '_write',
value: function _write(chunk, encoding, callback) {
this.push(chunk);
callback();
}

/**
*
* @param size
* @private
*/

}, {
key: '_read',
value: function _read(size) {}

/**
*
* @param chat
* @param room
*/

}, {
key: 'writeComment',
value: function writeComment(chat, room) {
this.write(this.getCommentInfo(chat, room));
}

/**
*
* @param chat
* @param room
* @returns {CommentInfo}
*/

}, {
key: 'getCommentInfo',
value: function getCommentInfo(chat, room) {
return new _commentInfo2.default(chat['_thread'], chat['_no'], chat['_vpos'], chat['_date'], chat['_date_usec'], chat['_mail'], chat['_user_id'], chat['_premium'], chat['_anonymity'], chat['_locale'], chat['_score'], chat['_yourpost'], chat['_deleted'], chat['_origin'], chat['__text'], room['roomLabel']);
}
}]);

return LiveCommentStream;
}(_stream.Duplex);

exports.default = LiveCommentStream;
module.exports = exports['default'];
6 changes: 6 additions & 0 deletions dist/live/constraints/addrPortsChannel.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions dist/live/constraints/addrPortsCommunity.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit f0af475

Please sign in to comment.