index.uts 1.4 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
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);
}

DCloud-yyl's avatar
DCloud-yyl 已提交
17
export function onSocketOpen(callback : OnSocketOpenCallback) : void {
DCloud-yyl's avatar
DCloud-yyl 已提交
18 19 20
	return WebSocketManager.getInstance().onSocketOpen(callback);
}

DCloud-yyl's avatar
DCloud-yyl 已提交
21
export function onSocketMessage(callback : OnSocketMessageCallback) : void {
DCloud-yyl's avatar
DCloud-yyl 已提交
22 23 24
	return WebSocketManager.getInstance().onSocketMessage(callback);
}

DCloud-yyl's avatar
DCloud-yyl 已提交
25
export function onSocketClose(callback : OnSocketCloseCallback) : void {
DCloud-yyl's avatar
DCloud-yyl 已提交
26 27 28
	return WebSocketManager.getInstance().onSocketClose(callback);
}

DCloud-yyl's avatar
DCloud-yyl 已提交
29
export function onSocketError(callback : OnSocketErrorCallback) : void {
DCloud-yyl's avatar
DCloud-yyl 已提交
30 31
	return WebSocketManager.getInstance().onSocketError(callback);
}