nicolive-api
Version:
api client for live.nicovideo.jp
84 lines (67 loc) • 2.67 kB
JavaScript
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 _net = require('net');
var _net2 = _interopRequireDefault(_net);
var _cheerio = require('cheerio');
var _cheerio2 = _interopRequireDefault(_cheerio);
var _NicoliveAPI = require('../NicoliveAPI');
var _NicoliveAPI2 = _interopRequireDefault(_NicoliveAPI);
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"); } }
var BaseViewer = function () {
function BaseViewer(_ref) {
var port = _ref.port,
addr = _ref.addr,
thread = _ref.thread,
version = _ref.version,
res_from = _ref.res_from,
cookie = _ref.cookie;
_classCallCheck(this, BaseViewer);
this.port = port;
this.addr = addr;
this.thread = thread;
this.version = version;
this.res_from = res_from;
this.connection = null;
this.client = new _NicoliveAPI2.default(cookie);
}
_createClass(BaseViewer, [{
key: 'establish',
value: function establish(viewer) {
this.connect();
this.setOnConnectEvent();
this.setOnDataEvent(viewer);
}
}, {
key: 'connect',
value: function connect() {
this.connection = _net2.default.connect(this.port, this.addr);
}
}, {
key: 'setOnConnectEvent',
value: function setOnConnectEvent() {
var _this = this;
this.connection.on('connect', function () {
var comment = (0, _cheerio2.default)('<thread />');
comment.attr({
thread: _this.thread,
version: _this.version,
res_from: _this.res_from
});
comment.options.xmlMode = 'on';
_this.connection.write(comment + '\0');
_this.connection.setEncoding('utf-8');
});
}
}, {
key: 'setOnDataEvent',
value: function setOnDataEvent() {
throw new Error('Not implemented error');
}
}]);
return BaseViewer;
}();
exports.default = BaseViewer;
;