@alipay/faas-biz-server-sdk
Advanced tools
Comparing version 1.1.1-alpha.2 to 1.1.1-alpha.3
@@ -1,4 +0,5 @@ | ||
import { StorageOptions } from "../../types/Websocket"; | ||
import { StorageOptions, WebSocketEvent } from "../../types/Websocket"; | ||
import Chain from "./Chain"; | ||
import { Room } from "./Room"; | ||
import FaasWebSocket from "./Websocket"; | ||
export default class FaasWebSocketIO extends Chain { | ||
@@ -14,4 +15,5 @@ private ws; | ||
expect(roomId: string): this; | ||
on(event: WebSocketEvent, handler: (socket: FaasWebSocket) => void): void; | ||
emit(event: string, data: any): this; | ||
broadcast(roomId: string, event: string, data: any): this; | ||
} |
@@ -11,2 +11,3 @@ "use strict"; | ||
const RedisStorage_1 = __importDefault(require("./Storage/RedisStorage")); | ||
const Websocket_2 = __importDefault(require("./Websocket")); | ||
class FaasWebSocketIO extends Chain_1.default { | ||
@@ -57,4 +58,18 @@ ws; | ||
} | ||
on(event, handler) { | ||
addEventListener(`websocket:${event}`, (event) => { | ||
event.handle((async () => { | ||
const socket = new Websocket_2.default({ | ||
connectionId: event.connectionId, | ||
}); | ||
socket.storage = this._storage; | ||
handler(socket); | ||
})()); | ||
}); | ||
} | ||
emit(event, data) { | ||
this.later(async () => { | ||
if (!this._rooms) { | ||
throw new Error('No room specified'); | ||
} | ||
for (const room of this._rooms) { | ||
@@ -61,0 +76,0 @@ for (const socket of room.sockets) { |
{ | ||
"name": "@alipay/faas-biz-server-sdk", | ||
"version": "1.1.1-alpha.2", | ||
"version": "1.1.1-alpha.3", | ||
"description": "支付宝云开发业务 SDK(函数端)", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
156476
3530