"use strict";var _Object$defineProperty = require("@babel/runtime-corejs2/core-js/object/define-property");var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");_Object$defineProperty(exports, "__esModule", { value: true });exports.createSocketServer = createSocketServer;



var _socket = _interopRequireDefault(require("socket.io"));
var _logger = require("./logger"); /**
 * Copyright (C) 2017, hapjs.org. All rights reserved.
 */function createSocketServer(server, app) {
  const io = (0, _socket.default)(server);
  // 暂时绑定io
  app.context.io = io;

  io.on('connection', (socket) => {
    io.on('error', (err) => {
      _logger.logger.error(`### App Socket Server ### websocket server发生错误: ${err.message}`);
    });

    socket.on('disconnect', () => {
      _logger.logger.info(`### App Socket Server ### websocket client与websocket server断开`);
      io.emit('user disconnected');
    });
  });
}