'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()
  }
}

SocketController.toString = () => '[class SocketController]';
module.exports = SocketController;
