index.uts 1.5 KB
Newer Older
DCloud-yyl's avatar
DCloud-yyl 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
import { ConnectSocket, ConnectSocketOptions, SocketTask, SendSocketMessage, SendSocketMessageOptions, CloseSocket, CloseSocketOptions, OnSocketOpen, OnSocketOpenCallback, OnSocketError, OnSocketErrorCallback, OnSocketMessage, OnSocketMessageCallback, OnSocketClose, OnSocketCloseCallback } from "../interface";
import { WebSocketManager } from "./websocket/WebSocketManager"


export const connectSocket : ConnectSocket = (options : ConnectSocketOptions) : SocketTask => {
	return WebSocketManager.getInstance().connectSocket(options);
}

export const sendSocketMessage : SendSocketMessage = (options : SendSocketMessageOptions) : void => {
	return WebSocketManager.getInstance().sendSocketMessage(options);
}

export const closeSocket : CloseSocket = (options : CloseSocketOptions) : void => {
	return WebSocketManager.getInstance().closeSocket(options);
}

export const onSocketOpen : OnSocketOpen = (callback : OnSocketOpenCallback) : void => {
	return WebSocketManager.getInstance().onSocketOpen(callback);
}

export const onSocketMessage : OnSocketMessage = (callback : OnSocketMessageCallback) : void => {
	return WebSocketManager.getInstance().onSocketMessage(callback);
}

export const onSocketClose : OnSocketClose = (callback : OnSocketCloseCallback) : void => {
	return WebSocketManager.getInstance().onSocketClose(callback);
}

export const onSocketError : OnSocketError = (callback : OnSocketErrorCallback) : void => {
	return WebSocketManager.getInstance().onSocketError(callback);
}