frc-ui
Version:
React Web UI
193 lines (154 loc) • 9.41 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _react = _interopRequireDefault(require("react"));
var _classnames = _interopRequireDefault(require("classnames"));
var _Hoc = require("./common/Hoc");
var _interfaces = require("./interfaces");
var _header = _interopRequireDefault(require("./header"));
var _content = _interopRequireDefault(require("./content"));
var _send = _interopRequireDefault(require("./send"));
var _tool = _interopRequireDefault(require("./tool"));
var _Notice = _interopRequireDefault(require("./Notice"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a 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); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
var __decorate = void 0 && (void 0).__decorate || function (decorators, target, key, desc) {
var c = arguments.length,
r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
d;
if ((typeof Reflect === "undefined" ? "undefined" : _typeof(Reflect)) === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);else for (var i = decorators.length - 1; i >= 0; i--) {
if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
}
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var Chat = /*#__PURE__*/function (_React$Component) {
_inherits(Chat, _React$Component);
var _super = _createSuper(Chat);
function Chat() {
var _this;
_classCallCheck(this, Chat);
_this = _super.apply(this, arguments);
_this.sub = function () {
var _this$props = _this.props,
channel = _this$props.channel,
Socket = _this$props.Socket;
Socket.join(channel);
};
_this.leave = function () {
var _this$props2 = _this.props,
channel = _this$props2.channel,
Socket = _this$props2.Socket;
Socket && Socket.leave(channel);
};
_this.getStyle = function () {};
return _this;
}
_createClass(Chat, [{
key: "componentDidMount",
value: function componentDidMount() {
var _this$props3 = this.props,
channel = _this$props3.channel,
user = _this$props3.user,
emit = _this$props3.emit,
success = _this$props3.success,
Socket = _this$props3.Socket;
if (emit && Socket) {
emit('chatPermission', channel);
emit('chatGag.isGag', {
userId: user && user.userId,
chatRoomCode: channel
});
emit('chatMessage.clientCount', channel);
emit('chatDict', ['textMaxLength', 'SysNotice']);
this.sub();
Socket.on('connect', this.sub);
Socket.on('reconnect', this.sub);
Socket.on("chatroom_userpermission_".concat(channel), function (permission) {
success && success('chatPermission', {
result: permission
});
});
Socket.on("gag_message_".concat(channel), function (isGag) {
success && success('chatGag.isGag', {
result: isGag === true
});
});
Socket.on('dict', function (dict) {
success && success('chatDict', {
result: dict
});
});
Socket.on('patr_permission_msg', function () {
emit && emit('pc.hasAuth');
});
Socket.on('patr_apply_permission_msg', function () {
emit && emit('pc.applyAuth');
});
}
window.addEventListener('beforeunload', this.leave);
}
}, {
key: "render",
value: function render() {
var _classNames;
var _this$props4 = this.props,
className = _this$props4.className,
useSend = _this$props4.useSend,
useHeader = _this$props4.useHeader,
useMessage = _this$props4.useMessage,
tools = _this$props4.tools,
sendSize = _this$props4.sendSize,
prefix = _this$props4.prefix,
setName = _this$props4.setName;
var useTool = false;
if (tools instanceof Array) useTool = tools.length > 0;else useTool = !!tools;
var cls = (0, _classnames["default"])(prefix, className, (_classNames = {}, _defineProperty(_classNames, "".concat(prefix, "-use-header"), useHeader), _defineProperty(_classNames, "".concat(prefix, "-use-message"), useMessage), _defineProperty(_classNames, "".concat(prefix, "-use-tool"), useTool), _defineProperty(_classNames, "".concat(prefix, "-use-send"), useSend), _classNames));
var bottom = 0;
if (useSend) bottom += sendSize === 'small' ? 50 : 128;
if (useTool) bottom += 28;
var style = {
paddingBottom: bottom + 10
};
return /*#__PURE__*/_react["default"].createElement("div", {
className: cls,
style: style
}, useHeader && /*#__PURE__*/_react["default"].createElement(_header["default"], null), /*#__PURE__*/_react["default"].createElement(_Notice["default"], {
top: useHeader ? 24 + 1 : 1
}), useMessage && /*#__PURE__*/_react["default"].createElement(_content["default"], null), useTool && useSend && /*#__PURE__*/_react["default"].createElement("div", {
className: "".concat(prefix, "-bottom"),
style: {
height: bottom + 10
}
}, useTool && /*#__PURE__*/_react["default"].createElement(_tool["default"], null), useSend && /*#__PURE__*/_react["default"].createElement(_send["default"], {
setName: setName,
className: sendSize === 'small' ? "".concat(prefix, "-send-sm") : ''
})));
}
}]);
return Chat;
}(_react["default"].Component);
Chat.MessageTypeEnum = _interfaces.MessageTypeEnum;
Chat.ChatToolEnum = _interfaces.ChatToolEnum;
Chat.defaultProps = {
messageTypes: Object.keys(_interfaces.MessageTypeEnum),
tools: Object.keys(_interfaces.ChatToolEnum),
useSend: true,
useHeader: true,
useMessage: true
};
Chat = __decorate([_Hoc.Provider], Chat);
var _default = Chat;
exports["default"] = _default;