| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- 'use strict';
- const { Controller } = require('ee-core');
- const socket = require('../utils/socket')
- const pySocket = new socket()
- class SocketController extends Controller {
- constructor(ctx) {
- super(ctx);
- }
- /**
- * Connect to WebSocket server
- */
- async connect() {
- await new Promise(async (resolve,reject) => {
- pySocket.init(this.app)
- })
- }
- /**
- * 发送 ping 消息
- */
- sendPing() {
- pySocket.sendPing()
- }
- /**
- * 发送消息到服务器
- * @param {string} message - JSON 字符串
- */
- sendMessage(message) {
- pySocket.sendMessage(message)
- }
- /**
- * 断开连接
- */
- disconnect() {
- pySocket.disconnect()
- }
- /**
- * 获取 MCU 错误日志列表
- */
- getMcuErrorLogs() {
- return pySocket.getMcuErrorLogs();
- }
- /**
- * 获取 MCU 错误日志未读数
- */
- getMcuErrorUnreadCount() {
- return pySocket.getMcuErrorUnreadCount();
- }
- /**
- * 清除 MCU 错误日志未读状态
- */
- clearMcuErrorUnread() {
- return pySocket.clearMcuErrorUnread();
- }
- /**
- * 设置 MCU 错误日志最大条数
- * @param {number} max - 最大条数
- */
- setMcuErrorLogMax(max) {
- return pySocket.setMcuErrorLogMax(max);
- }
- }
- SocketController.toString = () => '[class SocketController]';
- module.exports = SocketController;
|