ZLMediaKit/api/include/websocket.h

106 lines
3.7 KiB
C++
Raw Normal View History

2019-12-25 15:15:16 +08:00
/*
* MIT License
*
* Copyright (c) 2019 xiongziliang <771730766@qq.com>
*
* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit).
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef MK_WEBSOCKET_H
#define MK_WEBSOCKET_H
#include "common.h"
#include "events_objects.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct {
/**
* websocket客户端连接服务器时触发
* @param session
*/
void (API_CALL *on_mk_websocket_session_create)(mk_tcp_session session);
/**
* session会话对象销毁时触发
*
* mk_tcp_session_send/mk_tcp_session_send_safe函数
* @param session
*/
void (API_CALL *on_mk_websocket_session_destory)(mk_tcp_session session);
/**
* websocket客户端发过来的数据
* @param session
* @param data
* @param len
*/
void (API_CALL *on_mk_websocket_session_data)(mk_tcp_session session,const char *data,int len);
/**
* 2
* @param session
*/
void (API_CALL *on_mk_websocket_session_manager)(mk_tcp_session session);
/**
* on_mk_websocket_session_destory之前触发on_mk_websocket_session_err
* tcp触发
* mk_tcp_session_send_safe函数
* @param session
* @param code
* @param msg
*/
void (API_CALL *on_mk_websocket_session_err)(mk_tcp_session session,int code,const char *msg);
} mk_websocket_events;
API_EXPORT void API_CALL mk_websocket_events_listen(const mk_websocket_events *events);
/**
* websocket会话对象附着用户数据
* @param session websocket会话对象
* @param user_data
*/
API_EXPORT void API_CALL mk_websocket_session_set_user_data(mk_tcp_session session,void *user_data);
/**
* websocket会话对象上附着的用户数据
* @param session websocket会话对象
* @return
*/
API_EXPORT void* API_CALL mk_websocket_session_get_user_data(mk_tcp_session session);
2019-12-25 15:15:16 +08:00
/**
* websocket服务器,websocket服务器包含了Http服务器的所有功能
* mk_websocket_server_start后不用再调用mk_http_server_start
* @param port 0
* @param ssl wss/ws
* @return 0
*/
API_EXPORT uint16_t API_CALL mk_websocket_server_start(uint16_t port, int ssl);
#ifdef __cplusplus
}
#endif
#endif //MK_WEBSOCKET_H