@rivalis/core
Advanced tools
+1
-1
@@ -61,2 +61,2 @@ export default Actor; | ||
| } | ||
| import Room from "./Room"; | ||
| import Room from './Room'; |
@@ -59,2 +59,2 @@ export default WSClient; | ||
| } | ||
| import { Broadcast } from "@toolcase/base"; | ||
| import { Broadcast } from '@toolcase/base'; |
+2
-2
@@ -17,3 +17,3 @@ export default Config; | ||
| } | ||
| import Transport from "./Transport"; | ||
| import AuthMiddleware from "./AuthMiddleware"; | ||
| import Transport from './Transport'; | ||
| import AuthMiddleware from './AuthMiddleware'; |
@@ -6,4 +6,4 @@ export default CustomLoggerFactory; | ||
| declare namespace CustomLoggerFactory { | ||
| const Instance: CustomLoggerFactory; | ||
| let Instance: CustomLoggerFactory; | ||
| } | ||
| import { LoggerFactory } from "@toolcase/logging"; | ||
| import { LoggerFactory } from '@toolcase/logging'; |
+6
-6
| export type TopicListener = (actor: Actor, payload: Uint8Array, topic: string) => void; | ||
| import Rivalis from "./Rivalis"; | ||
| import Rivalis from './Rivalis'; | ||
| export namespace Transports { | ||
@@ -9,7 +9,7 @@ export { WSTransport }; | ||
| } | ||
| import AuthMiddleware from "./AuthMiddleware"; | ||
| import Room from "./Room"; | ||
| import Actor from "./Actor"; | ||
| import WSTransport from "./transports/WSTransport"; | ||
| import WSClient from "./clients/WSClient"; | ||
| import AuthMiddleware from './AuthMiddleware'; | ||
| import Room from './Room'; | ||
| import Actor from './Actor'; | ||
| import WSTransport from './transports/WSTransport'; | ||
| import WSClient from './clients/WSClient'; | ||
| export { Rivalis, AuthMiddleware, Room, Actor }; |
+67
-71
| var $hkjh6$toolcasebase = require("@toolcase/base"); | ||
| var $hkjh6$toolcaselogging = require("@toolcase/logging"); | ||
| var $hkjh6$buffer = require("buffer"); | ||
| require("http"); | ||
@@ -8,2 +7,3 @@ var $hkjh6$url = require("url"); | ||
| function $parcel$export(e, n, v, s) { | ||
@@ -40,3 +40,3 @@ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true}); | ||
| */ async getRoomId(ticket) { | ||
| throw new Error("AuthMiddleware#getRoomId not implemented"); | ||
| throw new Error('AuthMiddleware#getRoomId not implemented'); | ||
| } | ||
@@ -62,14 +62,14 @@ } | ||
| const $7caca5bb9afdd12b$var$serializer = new (0, $hkjh6$toolcasebase.Serializer)("@rivalis/message"); | ||
| const $7caca5bb9afdd12b$var$DATA_MODEL = "realtime_message"; | ||
| const $7caca5bb9afdd12b$var$serializer = new (0, $hkjh6$toolcasebase.Serializer)('@rivalis/message'); | ||
| const $7caca5bb9afdd12b$var$DATA_MODEL = 'realtime_message'; | ||
| $7caca5bb9afdd12b$var$serializer.define($7caca5bb9afdd12b$var$DATA_MODEL, [ | ||
| { | ||
| key: "topic", | ||
| type: "string", | ||
| rule: "required" | ||
| key: 'topic', | ||
| type: 'string', | ||
| rule: 'required' | ||
| }, | ||
| { | ||
| key: "payload", | ||
| type: "bytes", | ||
| rule: "required" | ||
| key: 'payload', | ||
| type: 'bytes', | ||
| rule: 'required' | ||
| } | ||
@@ -103,3 +103,3 @@ ]); | ||
| */ class $4ad9d110c913e368$var$TLayer { | ||
| logger = (0, $6d41a970687a7435$export$2e2bcd8739ae039).Instance.getLogger("transport layer"); | ||
| logger = (0, $6d41a970687a7435$export$2e2bcd8739ae039).Instance.getLogger('transport layer'); | ||
| /** | ||
@@ -159,5 +159,5 @@ * @private | ||
| let isValid = await this.authMiddleware.validateTicket(ticket); | ||
| if (isValid !== true) throw new Error("invalid ticket"); | ||
| if (isValid !== true) throw new Error('invalid ticket'); | ||
| let data = await this.authMiddleware.extractPayload(ticket); | ||
| if (data !== null && typeof data !== "object") throw new Error(`actor data can be an object or null, provided=${data}`); | ||
| if (data !== null && typeof data !== 'object') throw new Error(`actor data can be an object or null, provided=${data}`); | ||
| let roomId = await this.authMiddleware.getRoomId(ticket); | ||
@@ -178,3 +178,3 @@ let room = this.getRoom(roomId); | ||
| let data = (0, $7caca5bb9afdd12b$export$2f872c0f2117be69)(message); | ||
| this.logger.verbose("decoded data:", data); | ||
| this.logger.verbose('decoded data:', data); | ||
| let roomId = this.roomIds.get(actorId); | ||
@@ -203,3 +203,3 @@ let room = this.getRoom(roomId); | ||
| let message = (0, $7caca5bb9afdd12b$export$c564cdbbe6da493)(topic, payload); | ||
| this.emit("message", actorId, message); | ||
| this.emit('message', actorId, message); | ||
| } | ||
@@ -211,3 +211,3 @@ /** | ||
| */ kick(actorId, payload) { | ||
| this.emit("kick", actorId, payload); | ||
| this.emit('kick', actorId, payload); | ||
| } | ||
@@ -243,4 +243,4 @@ } | ||
| */ constructor(config = {}){ | ||
| if (typeof config !== "object") throw new Error("config error: provided config is not an object"); | ||
| if (!Array.isArray(config.transports)) throw new Error("config error: transports must be an array"); | ||
| if (typeof config !== 'object') throw new Error('config error: provided config is not an object'); | ||
| if (!Array.isArray(config.transports)) throw new Error('config error: transports must be an array'); | ||
| for (let [index, transport] of config.transports.entries()){ | ||
@@ -316,3 +316,3 @@ if (!(transport instanceof (0, $38f245fbae6fed18$export$2e2bcd8739ae039))) throw new Error(`config error: transports[${index}] must be an instance of Transport`); | ||
| let data = this.storage.get(key); | ||
| if (typeof data === "undefined") return null; | ||
| if (typeof data === 'undefined') return null; | ||
| return data; | ||
@@ -327,7 +327,5 @@ } | ||
| var $9ecb24433caae8b1$require$Buffer = $hkjh6$buffer.Buffer; | ||
| const $9ecb24433caae8b1$var$ERROR = { | ||
| INVALID_MESSAGE: "invalid_message", | ||
| ROOM_DESTROYED: "room_destroyed" | ||
| INVALID_MESSAGE: 'invalid_message', | ||
| ROOM_DESTROYED: 'room_destroyed' | ||
| }; | ||
@@ -373,3 +371,3 @@ /** | ||
| this.onCreate(); | ||
| this.logger.info("created"); | ||
| this.logger.info('created'); | ||
| } | ||
@@ -392,4 +390,4 @@ /** @protected */ onCreate() {} | ||
| */ bind(topic, topicListener, context = null) { | ||
| if (typeof topic !== "string") throw new Error(`topic must be a string, ${topic} provided`); | ||
| if (typeof topicListener !== "function") throw new Error(`topicListener must be a function, ${topicListener} provided`); | ||
| if (typeof topic !== 'string') throw new Error(`topic must be a string, ${topic} provided`); | ||
| if (typeof topicListener !== 'function') throw new Error(`topicListener must be a function, ${topicListener} provided`); | ||
| if (this.topics.has(topic)) return false; | ||
@@ -403,3 +401,3 @@ this.topics.set(topic, topicListener.bind(context === null ? this : context)); | ||
| */ unbind(topic) { | ||
| if (typeof topic !== "string") throw new Error(`topic must be a string, ${topic} provided`); | ||
| if (typeof topic !== 'string') throw new Error(`topic must be a string, ${topic} provided`); | ||
| return this.topics.delete(topic); | ||
@@ -413,6 +411,6 @@ } | ||
| */ send(actor, topic, payload) { | ||
| if (typeof topic !== "string") throw new Error(`send error: topic must be a sting, ${topic} provided`); | ||
| if (typeof topic !== 'string') throw new Error(`send error: topic must be a sting, ${topic} provided`); | ||
| if (!(actor instanceof (0, $ca19624070d65670$export$2e2bcd8739ae039))) throw new Error(`send error: actor=${actor} must be an instance of Actor`); | ||
| if (payload instanceof Uint8Array) return this.transportLayer.send(actor.id, topic, payload); | ||
| if (typeof payload === "string") return this.transportLayer.send(actor.id, topic, $9ecb24433caae8b1$require$Buffer.from(payload, "utf-8")); | ||
| if (typeof payload === 'string') return this.transportLayer.send(actor.id, topic, Buffer.from(payload, 'utf-8')); | ||
| throw new Error(`send error: invalid payload=${payload}, must be a string or Buffer`); | ||
@@ -437,5 +435,5 @@ } | ||
| * @param {Uint8Array|string} [payload] | ||
| */ kick(actor, payload = "") { | ||
| */ kick(actor, payload = '') { | ||
| if (payload instanceof Uint8Array) return this.transportLayer.kick(actor.id, payload); | ||
| if (typeof payload === "string") return this.transportLayer.kick(actor.id, $9ecb24433caae8b1$require$Buffer.from(payload, "utf-8")); | ||
| if (typeof payload === 'string') return this.transportLayer.kick(actor.id, Buffer.from(payload, 'utf-8')); | ||
| throw new Error(`kick error: invalid payload=${payload}, must be a string or Buffer`); | ||
@@ -453,3 +451,3 @@ } | ||
| this.manager = null; | ||
| this.logger.info("destroyed"); | ||
| this.logger.info('destroyed'); | ||
| this.logger = null; | ||
@@ -473,3 +471,3 @@ } | ||
| let topicListener = this.topics.get(topic) || null; | ||
| if (topicListener === null) topicListener = this.topics.get("*") || null; | ||
| if (topicListener === null) topicListener = this.topics.get('*') || null; | ||
| let actor = this.actors.get(actorId) || null; | ||
@@ -538,8 +536,8 @@ if (topicListener === null) { | ||
| */ define(key, roomClass) { | ||
| if (typeof key !== "string") throw new Error(`room define error: definition key=(${key}) must be of the type string`); | ||
| if (typeof roomClass !== "function") throw new Error(`room define error: roomClass=(${roomClass}) is not a class`); | ||
| if (typeof key !== 'string') throw new Error(`room define error: definition key=(${key}) must be of the type string`); | ||
| if (typeof roomClass !== 'function') throw new Error(`room define error: roomClass=(${roomClass}) is not a class`); | ||
| if (!(roomClass.prototype instanceof (0, $9ecb24433caae8b1$export$2e2bcd8739ae039))) throw new Error(`room define error: roomClass=(${roomClass}) must extends Room`); | ||
| if (this.defs.has(key)) throw new Error(`room define error: definition key=(${key}) exists`); | ||
| this.defs.set(key, roomClass); | ||
| this.emit("define", key); | ||
| this.emit('define', key); | ||
| } | ||
@@ -552,6 +550,6 @@ /** | ||
| */ create(roomType, roomId = null) { | ||
| if (typeof roomType !== "string") throw new Error(`room create error: type=(${type}) must be a string`); | ||
| if (typeof roomType !== 'string') throw new Error(`room create error: type=(${type}) must be a string`); | ||
| if (!this.defs.has(roomType)) throw new Error(`room create error: type=(${roomType}) is not defined`); | ||
| if (roomId === null) roomId = (0, $hkjh6$toolcasebase.generateId)(32); | ||
| else if (typeof roomId !== "string") throw new Error(`room create error: room id=(${roomId}) must be a string`); | ||
| else if (typeof roomId !== 'string') throw new Error(`room create error: room id=(${roomId}) must be a string`); | ||
| if (this.rooms.has(roomId)) throw new Error(`room create error: room id=(${roomId}) is taken`); | ||
@@ -561,3 +559,3 @@ let RoomClass = this.defs.get(roomType); | ||
| this.rooms.set(roomId, room); | ||
| this.emit("create", roomId); | ||
| this.emit('create', roomId); | ||
| return room; | ||
@@ -570,3 +568,3 @@ } | ||
| room.handleDestroy(); | ||
| this.emit("destroy", roomId); | ||
| this.emit('destroy', roomId); | ||
| } | ||
@@ -616,7 +614,7 @@ } | ||
| class $242ffa6a7732843a$var$WSTransport extends (0, $38f245fbae6fed18$export$2e2bcd8739ae039) { | ||
| /** @private */ logger = (0, $6d41a970687a7435$export$2e2bcd8739ae039).Instance.getLogger("transport:websocket"); | ||
| /** @private */ logger = (0, $6d41a970687a7435$export$2e2bcd8739ae039).Instance.getLogger('transport:websocket'); | ||
| /** | ||
| * @readonly | ||
| * @private | ||
| */ QUERY_TICKET_PARAM = "ticket"; | ||
| */ QUERY_TICKET_PARAM = 'ticket'; | ||
| /** | ||
@@ -635,5 +633,5 @@ * @private | ||
| super(); | ||
| if (typeof queryTicketParam === "string") this.QUERY_TICKET_PARAM = queryTicketParam; | ||
| if (typeof queryTicketParam === 'string') this.QUERY_TICKET_PARAM = queryTicketParam; | ||
| this.ws = new (0, $hkjh6$ws.WebSocketServer)(options); | ||
| this.ws.on("connection", this.handleReject); | ||
| this.ws.on('connection', this.handleReject); | ||
| } | ||
@@ -645,5 +643,5 @@ /** | ||
| this.transportLayer = transportLayer; | ||
| this.ws.off("connection", this.handleReject); | ||
| this.ws.on("connection", this.handleConnect); | ||
| this.logger.info("initialized"); | ||
| this.ws.off('connection', this.handleReject); | ||
| this.ws.on('connection', this.handleConnect); | ||
| this.logger.info('initialized'); | ||
| } | ||
@@ -662,3 +660,3 @@ /** | ||
| if (ticket === null) { | ||
| this.logger.debug("client disconected, invalid ticket", ticket); | ||
| this.logger.debug('client disconected, invalid ticket', ticket); | ||
| return socket.close(4001); | ||
@@ -673,3 +671,3 @@ } | ||
| } | ||
| socket.on("message", (data, isBinary)=>{ | ||
| socket.on('message', (data, isBinary)=>{ | ||
| if (!isBinary) { | ||
@@ -679,10 +677,10 @@ this.logger.debug(`actor id=(${actorId}) ticket=(${ticket}) sent non-binary data`); | ||
| } | ||
| if ((0, $6d41a970687a7435$export$2e2bcd8739ae039).Instance.level === "verbose") this.logger.verbose("message received", data); | ||
| if ((0, $6d41a970687a7435$export$2e2bcd8739ae039).Instance.level === 'verbose') this.logger.verbose('message received', data); | ||
| this.transportLayer.handleMessage(actorId, data); | ||
| }); | ||
| socket.once("close", ()=>this.transportLayer.handleClose(actorId)); | ||
| this.transportLayer.on("message", actorId, (_, message)=>{ | ||
| socket.once('close', ()=>this.transportLayer.handleClose(actorId)); | ||
| this.transportLayer.on('message', actorId, (_, message)=>{ | ||
| socket.send(message); | ||
| }); | ||
| this.transportLayer.on("kick", actorId, (_, message)=>{ | ||
| this.transportLayer.on('kick', actorId, (_, message)=>{ | ||
| socket.close(4003, message); | ||
@@ -696,3 +694,3 @@ }); | ||
| */ extractTicket(request) { | ||
| let requestUrl = new (0, $hkjh6$url.URL)("https://kalevski.dev" + request.url); | ||
| let requestUrl = new (0, $hkjh6$url.URL)('https://kalevski.dev' + request.url); | ||
| return requestUrl.searchParams.get(this.QUERY_TICKET_PARAM) || null; | ||
@@ -708,4 +706,2 @@ } | ||
| var $c755dadf8674726f$require$Buffer = $hkjh6$buffer.Buffer; | ||
| const $c755dadf8674726f$var$EMPTY_PAYLOAD = new Uint8Array(); | ||
@@ -727,3 +723,3 @@ /** | ||
| */ baseURL = null; | ||
| /** @private */ logger = (0, $6d41a970687a7435$export$2e2bcd8739ae039).Instance.getLogger("ws client"); | ||
| /** @private */ logger = (0, $6d41a970687a7435$export$2e2bcd8739ae039).Instance.getLogger('ws client'); | ||
| /** | ||
@@ -743,10 +739,10 @@ * @private | ||
| } | ||
| connect(ticket = "") { | ||
| if (this.connected) return this.logger.warning("the client is already connected"); | ||
| if (typeof ticket !== "string") throw new Error(`ticket must be a sting, ${ticket} provided`); | ||
| connect(ticket = '') { | ||
| if (this.connected) return this.logger.warning('the client is already connected'); | ||
| if (typeof ticket !== 'string') throw new Error(`ticket must be a sting, ${ticket} provided`); | ||
| let url = new URL(this.baseURL); | ||
| url.searchParams.append("ticket", ticket); | ||
| url.searchParams.append('ticket', ticket); | ||
| this.ws = new (0, $hkjh6$ws.WebSocket)(url.toString()); | ||
| this.ws.once("open", ()=>this.onOpen()); | ||
| this.ws.once("close", (code, reason)=>this.onClose(code, reason)); | ||
| this.ws.once('open', ()=>this.onOpen()); | ||
| this.ws.once('close', (code, reason)=>this.onClose(code, reason)); | ||
| } | ||
@@ -758,3 +754,3 @@ disconnect() { | ||
| this.ws = null; | ||
| this.emit("client:disconnect", $c755dadf8674726f$require$Buffer.from("terminated")); | ||
| this.emit('client:disconnect', Buffer.from('terminated')); | ||
| } | ||
@@ -766,11 +762,11 @@ /** | ||
| */ send(topic, payload = $c755dadf8674726f$var$EMPTY_PAYLOAD) { | ||
| if (!this.connected) return this.logger.warning("send fail: connection is not established yet"); | ||
| if (typeof topic !== "string") throw new Error(`topic must be a string, ${topic} provided`); | ||
| if (!this.connected) return this.logger.warning('send fail: connection is not established yet'); | ||
| if (typeof topic !== 'string') throw new Error(`topic must be a string, ${topic} provided`); | ||
| if (payload instanceof Uint8Array) return this.ws.send((0, $7caca5bb9afdd12b$export$c564cdbbe6da493)(topic, payload)); | ||
| if (typeof payload === "string") return this.ws.send((0, $7caca5bb9afdd12b$export$c564cdbbe6da493)(topic, $c755dadf8674726f$require$Buffer.from(payload, "utf-8"))); | ||
| if (typeof payload === 'string') return this.ws.send((0, $7caca5bb9afdd12b$export$c564cdbbe6da493)(topic, Buffer.from(payload, 'utf-8'))); | ||
| throw new Error(`send error: invalid payload=${payload}, must be a string or Buffer`); | ||
| } | ||
| /** @private */ onOpen() { | ||
| this.ws.on("message", (data, isBinary)=>this.onMessage(data, isBinary)); | ||
| this.emit("client:connect"); | ||
| this.ws.on('message', (data, isBinary)=>this.onMessage(data, isBinary)); | ||
| this.emit('client:connect'); | ||
| } | ||
@@ -782,3 +778,3 @@ /** | ||
| */ onMessage(data, isBinary) { | ||
| let { topic: topic , payload: payload } = (0, $7caca5bb9afdd12b$export$2f872c0f2117be69)(data); | ||
| let { topic: topic, payload: payload } = (0, $7caca5bb9afdd12b$export$2f872c0f2117be69)(data); | ||
| this.emit(topic, payload); | ||
@@ -791,3 +787,3 @@ } | ||
| */ onClose(code, reason) { | ||
| this.emit("client:disconnect", reason); | ||
| this.emit('client:disconnect', reason); | ||
| this.ws.removeAllListeners(); | ||
@@ -794,0 +790,0 @@ this.ws = null; |
+66
-71
| import {EventEmitter as $4udxj$EventEmitter, generateId as $4udxj$generateId, Serializer as $4udxj$Serializer, Broadcast as $4udxj$Broadcast} from "@toolcase/base"; | ||
| import {ConsoleLogReporter as $4udxj$ConsoleLogReporter, LoggerFactory as $4udxj$LoggerFactory} from "@toolcase/logging"; | ||
| import {Buffer as $4udxj$Buffer} from "buffer"; | ||
| import "http"; | ||
@@ -28,3 +27,3 @@ import {URL as $4udxj$URL} from "url"; | ||
| */ async getRoomId(ticket) { | ||
| throw new Error("AuthMiddleware#getRoomId not implemented"); | ||
| throw new Error('AuthMiddleware#getRoomId not implemented'); | ||
| } | ||
@@ -50,14 +49,14 @@ } | ||
| const $66f1c142781ab216$var$serializer = new (0, $4udxj$Serializer)("@rivalis/message"); | ||
| const $66f1c142781ab216$var$DATA_MODEL = "realtime_message"; | ||
| const $66f1c142781ab216$var$serializer = new (0, $4udxj$Serializer)('@rivalis/message'); | ||
| const $66f1c142781ab216$var$DATA_MODEL = 'realtime_message'; | ||
| $66f1c142781ab216$var$serializer.define($66f1c142781ab216$var$DATA_MODEL, [ | ||
| { | ||
| key: "topic", | ||
| type: "string", | ||
| rule: "required" | ||
| key: 'topic', | ||
| type: 'string', | ||
| rule: 'required' | ||
| }, | ||
| { | ||
| key: "payload", | ||
| type: "bytes", | ||
| rule: "required" | ||
| key: 'payload', | ||
| type: 'bytes', | ||
| rule: 'required' | ||
| } | ||
@@ -91,3 +90,3 @@ ]); | ||
| */ class $66e81346ede591a8$var$TLayer { | ||
| logger = (0, $2789fb96ce099342$export$2e2bcd8739ae039).Instance.getLogger("transport layer"); | ||
| logger = (0, $2789fb96ce099342$export$2e2bcd8739ae039).Instance.getLogger('transport layer'); | ||
| /** | ||
@@ -147,5 +146,5 @@ * @private | ||
| let isValid = await this.authMiddleware.validateTicket(ticket); | ||
| if (isValid !== true) throw new Error("invalid ticket"); | ||
| if (isValid !== true) throw new Error('invalid ticket'); | ||
| let data = await this.authMiddleware.extractPayload(ticket); | ||
| if (data !== null && typeof data !== "object") throw new Error(`actor data can be an object or null, provided=${data}`); | ||
| if (data !== null && typeof data !== 'object') throw new Error(`actor data can be an object or null, provided=${data}`); | ||
| let roomId = await this.authMiddleware.getRoomId(ticket); | ||
@@ -166,3 +165,3 @@ let room = this.getRoom(roomId); | ||
| let data = (0, $66f1c142781ab216$export$2f872c0f2117be69)(message); | ||
| this.logger.verbose("decoded data:", data); | ||
| this.logger.verbose('decoded data:', data); | ||
| let roomId = this.roomIds.get(actorId); | ||
@@ -191,3 +190,3 @@ let room = this.getRoom(roomId); | ||
| let message = (0, $66f1c142781ab216$export$c564cdbbe6da493)(topic, payload); | ||
| this.emit("message", actorId, message); | ||
| this.emit('message', actorId, message); | ||
| } | ||
@@ -199,3 +198,3 @@ /** | ||
| */ kick(actorId, payload) { | ||
| this.emit("kick", actorId, payload); | ||
| this.emit('kick', actorId, payload); | ||
| } | ||
@@ -231,4 +230,4 @@ } | ||
| */ constructor(config = {}){ | ||
| if (typeof config !== "object") throw new Error("config error: provided config is not an object"); | ||
| if (!Array.isArray(config.transports)) throw new Error("config error: transports must be an array"); | ||
| if (typeof config !== 'object') throw new Error('config error: provided config is not an object'); | ||
| if (!Array.isArray(config.transports)) throw new Error('config error: transports must be an array'); | ||
| for (let [index, transport] of config.transports.entries()){ | ||
@@ -304,3 +303,3 @@ if (!(transport instanceof (0, $dcfb6ff3542fe396$export$2e2bcd8739ae039))) throw new Error(`config error: transports[${index}] must be an instance of Transport`); | ||
| let data = this.storage.get(key); | ||
| if (typeof data === "undefined") return null; | ||
| if (typeof data === 'undefined') return null; | ||
| return data; | ||
@@ -315,7 +314,5 @@ } | ||
| var $36a7a4da3fea4b87$require$Buffer = $4udxj$Buffer; | ||
| const $36a7a4da3fea4b87$var$ERROR = { | ||
| INVALID_MESSAGE: "invalid_message", | ||
| ROOM_DESTROYED: "room_destroyed" | ||
| INVALID_MESSAGE: 'invalid_message', | ||
| ROOM_DESTROYED: 'room_destroyed' | ||
| }; | ||
@@ -361,3 +358,3 @@ /** | ||
| this.onCreate(); | ||
| this.logger.info("created"); | ||
| this.logger.info('created'); | ||
| } | ||
@@ -380,4 +377,4 @@ /** @protected */ onCreate() {} | ||
| */ bind(topic, topicListener, context = null) { | ||
| if (typeof topic !== "string") throw new Error(`topic must be a string, ${topic} provided`); | ||
| if (typeof topicListener !== "function") throw new Error(`topicListener must be a function, ${topicListener} provided`); | ||
| if (typeof topic !== 'string') throw new Error(`topic must be a string, ${topic} provided`); | ||
| if (typeof topicListener !== 'function') throw new Error(`topicListener must be a function, ${topicListener} provided`); | ||
| if (this.topics.has(topic)) return false; | ||
@@ -391,3 +388,3 @@ this.topics.set(topic, topicListener.bind(context === null ? this : context)); | ||
| */ unbind(topic) { | ||
| if (typeof topic !== "string") throw new Error(`topic must be a string, ${topic} provided`); | ||
| if (typeof topic !== 'string') throw new Error(`topic must be a string, ${topic} provided`); | ||
| return this.topics.delete(topic); | ||
@@ -401,6 +398,6 @@ } | ||
| */ send(actor, topic, payload) { | ||
| if (typeof topic !== "string") throw new Error(`send error: topic must be a sting, ${topic} provided`); | ||
| if (typeof topic !== 'string') throw new Error(`send error: topic must be a sting, ${topic} provided`); | ||
| if (!(actor instanceof (0, $f76fa2311181b493$export$2e2bcd8739ae039))) throw new Error(`send error: actor=${actor} must be an instance of Actor`); | ||
| if (payload instanceof Uint8Array) return this.transportLayer.send(actor.id, topic, payload); | ||
| if (typeof payload === "string") return this.transportLayer.send(actor.id, topic, $36a7a4da3fea4b87$require$Buffer.from(payload, "utf-8")); | ||
| if (typeof payload === 'string') return this.transportLayer.send(actor.id, topic, Buffer.from(payload, 'utf-8')); | ||
| throw new Error(`send error: invalid payload=${payload}, must be a string or Buffer`); | ||
@@ -425,5 +422,5 @@ } | ||
| * @param {Uint8Array|string} [payload] | ||
| */ kick(actor, payload = "") { | ||
| */ kick(actor, payload = '') { | ||
| if (payload instanceof Uint8Array) return this.transportLayer.kick(actor.id, payload); | ||
| if (typeof payload === "string") return this.transportLayer.kick(actor.id, $36a7a4da3fea4b87$require$Buffer.from(payload, "utf-8")); | ||
| if (typeof payload === 'string') return this.transportLayer.kick(actor.id, Buffer.from(payload, 'utf-8')); | ||
| throw new Error(`kick error: invalid payload=${payload}, must be a string or Buffer`); | ||
@@ -441,3 +438,3 @@ } | ||
| this.manager = null; | ||
| this.logger.info("destroyed"); | ||
| this.logger.info('destroyed'); | ||
| this.logger = null; | ||
@@ -461,3 +458,3 @@ } | ||
| let topicListener = this.topics.get(topic) || null; | ||
| if (topicListener === null) topicListener = this.topics.get("*") || null; | ||
| if (topicListener === null) topicListener = this.topics.get('*') || null; | ||
| let actor = this.actors.get(actorId) || null; | ||
@@ -526,8 +523,8 @@ if (topicListener === null) { | ||
| */ define(key, roomClass) { | ||
| if (typeof key !== "string") throw new Error(`room define error: definition key=(${key}) must be of the type string`); | ||
| if (typeof roomClass !== "function") throw new Error(`room define error: roomClass=(${roomClass}) is not a class`); | ||
| if (typeof key !== 'string') throw new Error(`room define error: definition key=(${key}) must be of the type string`); | ||
| if (typeof roomClass !== 'function') throw new Error(`room define error: roomClass=(${roomClass}) is not a class`); | ||
| if (!(roomClass.prototype instanceof (0, $36a7a4da3fea4b87$export$2e2bcd8739ae039))) throw new Error(`room define error: roomClass=(${roomClass}) must extends Room`); | ||
| if (this.defs.has(key)) throw new Error(`room define error: definition key=(${key}) exists`); | ||
| this.defs.set(key, roomClass); | ||
| this.emit("define", key); | ||
| this.emit('define', key); | ||
| } | ||
@@ -540,6 +537,6 @@ /** | ||
| */ create(roomType, roomId = null) { | ||
| if (typeof roomType !== "string") throw new Error(`room create error: type=(${type}) must be a string`); | ||
| if (typeof roomType !== 'string') throw new Error(`room create error: type=(${type}) must be a string`); | ||
| if (!this.defs.has(roomType)) throw new Error(`room create error: type=(${roomType}) is not defined`); | ||
| if (roomId === null) roomId = (0, $4udxj$generateId)(32); | ||
| else if (typeof roomId !== "string") throw new Error(`room create error: room id=(${roomId}) must be a string`); | ||
| else if (typeof roomId !== 'string') throw new Error(`room create error: room id=(${roomId}) must be a string`); | ||
| if (this.rooms.has(roomId)) throw new Error(`room create error: room id=(${roomId}) is taken`); | ||
@@ -549,3 +546,3 @@ let RoomClass = this.defs.get(roomType); | ||
| this.rooms.set(roomId, room); | ||
| this.emit("create", roomId); | ||
| this.emit('create', roomId); | ||
| return room; | ||
@@ -558,3 +555,3 @@ } | ||
| room.handleDestroy(); | ||
| this.emit("destroy", roomId); | ||
| this.emit('destroy', roomId); | ||
| } | ||
@@ -604,7 +601,7 @@ } | ||
| class $b61ac5915e62c1b1$var$WSTransport extends (0, $dcfb6ff3542fe396$export$2e2bcd8739ae039) { | ||
| /** @private */ logger = (0, $2789fb96ce099342$export$2e2bcd8739ae039).Instance.getLogger("transport:websocket"); | ||
| /** @private */ logger = (0, $2789fb96ce099342$export$2e2bcd8739ae039).Instance.getLogger('transport:websocket'); | ||
| /** | ||
| * @readonly | ||
| * @private | ||
| */ QUERY_TICKET_PARAM = "ticket"; | ||
| */ QUERY_TICKET_PARAM = 'ticket'; | ||
| /** | ||
@@ -623,5 +620,5 @@ * @private | ||
| super(); | ||
| if (typeof queryTicketParam === "string") this.QUERY_TICKET_PARAM = queryTicketParam; | ||
| if (typeof queryTicketParam === 'string') this.QUERY_TICKET_PARAM = queryTicketParam; | ||
| this.ws = new (0, $4udxj$WebSocketServer)(options); | ||
| this.ws.on("connection", this.handleReject); | ||
| this.ws.on('connection', this.handleReject); | ||
| } | ||
@@ -633,5 +630,5 @@ /** | ||
| this.transportLayer = transportLayer; | ||
| this.ws.off("connection", this.handleReject); | ||
| this.ws.on("connection", this.handleConnect); | ||
| this.logger.info("initialized"); | ||
| this.ws.off('connection', this.handleReject); | ||
| this.ws.on('connection', this.handleConnect); | ||
| this.logger.info('initialized'); | ||
| } | ||
@@ -650,3 +647,3 @@ /** | ||
| if (ticket === null) { | ||
| this.logger.debug("client disconected, invalid ticket", ticket); | ||
| this.logger.debug('client disconected, invalid ticket', ticket); | ||
| return socket.close(4001); | ||
@@ -661,3 +658,3 @@ } | ||
| } | ||
| socket.on("message", (data, isBinary)=>{ | ||
| socket.on('message', (data, isBinary)=>{ | ||
| if (!isBinary) { | ||
@@ -667,10 +664,10 @@ this.logger.debug(`actor id=(${actorId}) ticket=(${ticket}) sent non-binary data`); | ||
| } | ||
| if ((0, $2789fb96ce099342$export$2e2bcd8739ae039).Instance.level === "verbose") this.logger.verbose("message received", data); | ||
| if ((0, $2789fb96ce099342$export$2e2bcd8739ae039).Instance.level === 'verbose') this.logger.verbose('message received', data); | ||
| this.transportLayer.handleMessage(actorId, data); | ||
| }); | ||
| socket.once("close", ()=>this.transportLayer.handleClose(actorId)); | ||
| this.transportLayer.on("message", actorId, (_, message)=>{ | ||
| socket.once('close', ()=>this.transportLayer.handleClose(actorId)); | ||
| this.transportLayer.on('message', actorId, (_, message)=>{ | ||
| socket.send(message); | ||
| }); | ||
| this.transportLayer.on("kick", actorId, (_, message)=>{ | ||
| this.transportLayer.on('kick', actorId, (_, message)=>{ | ||
| socket.close(4003, message); | ||
@@ -684,3 +681,3 @@ }); | ||
| */ extractTicket(request) { | ||
| let requestUrl = new (0, $4udxj$URL)("https://kalevski.dev" + request.url); | ||
| let requestUrl = new (0, $4udxj$URL)('https://kalevski.dev' + request.url); | ||
| return requestUrl.searchParams.get(this.QUERY_TICKET_PARAM) || null; | ||
@@ -696,4 +693,2 @@ } | ||
| var $f8156bde3aaf414b$require$Buffer = $4udxj$Buffer; | ||
| const $f8156bde3aaf414b$var$EMPTY_PAYLOAD = new Uint8Array(); | ||
@@ -715,3 +710,3 @@ /** | ||
| */ baseURL = null; | ||
| /** @private */ logger = (0, $2789fb96ce099342$export$2e2bcd8739ae039).Instance.getLogger("ws client"); | ||
| /** @private */ logger = (0, $2789fb96ce099342$export$2e2bcd8739ae039).Instance.getLogger('ws client'); | ||
| /** | ||
@@ -731,10 +726,10 @@ * @private | ||
| } | ||
| connect(ticket = "") { | ||
| if (this.connected) return this.logger.warning("the client is already connected"); | ||
| if (typeof ticket !== "string") throw new Error(`ticket must be a sting, ${ticket} provided`); | ||
| connect(ticket = '') { | ||
| if (this.connected) return this.logger.warning('the client is already connected'); | ||
| if (typeof ticket !== 'string') throw new Error(`ticket must be a sting, ${ticket} provided`); | ||
| let url = new URL(this.baseURL); | ||
| url.searchParams.append("ticket", ticket); | ||
| url.searchParams.append('ticket', ticket); | ||
| this.ws = new (0, $4udxj$WebSocket)(url.toString()); | ||
| this.ws.once("open", ()=>this.onOpen()); | ||
| this.ws.once("close", (code, reason)=>this.onClose(code, reason)); | ||
| this.ws.once('open', ()=>this.onOpen()); | ||
| this.ws.once('close', (code, reason)=>this.onClose(code, reason)); | ||
| } | ||
@@ -746,3 +741,3 @@ disconnect() { | ||
| this.ws = null; | ||
| this.emit("client:disconnect", $f8156bde3aaf414b$require$Buffer.from("terminated")); | ||
| this.emit('client:disconnect', Buffer.from('terminated')); | ||
| } | ||
@@ -754,11 +749,11 @@ /** | ||
| */ send(topic, payload = $f8156bde3aaf414b$var$EMPTY_PAYLOAD) { | ||
| if (!this.connected) return this.logger.warning("send fail: connection is not established yet"); | ||
| if (typeof topic !== "string") throw new Error(`topic must be a string, ${topic} provided`); | ||
| if (!this.connected) return this.logger.warning('send fail: connection is not established yet'); | ||
| if (typeof topic !== 'string') throw new Error(`topic must be a string, ${topic} provided`); | ||
| if (payload instanceof Uint8Array) return this.ws.send((0, $66f1c142781ab216$export$c564cdbbe6da493)(topic, payload)); | ||
| if (typeof payload === "string") return this.ws.send((0, $66f1c142781ab216$export$c564cdbbe6da493)(topic, $f8156bde3aaf414b$require$Buffer.from(payload, "utf-8"))); | ||
| if (typeof payload === 'string') return this.ws.send((0, $66f1c142781ab216$export$c564cdbbe6da493)(topic, Buffer.from(payload, 'utf-8'))); | ||
| throw new Error(`send error: invalid payload=${payload}, must be a string or Buffer`); | ||
| } | ||
| /** @private */ onOpen() { | ||
| this.ws.on("message", (data, isBinary)=>this.onMessage(data, isBinary)); | ||
| this.emit("client:connect"); | ||
| this.ws.on('message', (data, isBinary)=>this.onMessage(data, isBinary)); | ||
| this.emit('client:connect'); | ||
| } | ||
@@ -770,3 +765,3 @@ /** | ||
| */ onMessage(data, isBinary) { | ||
| let { topic: topic , payload: payload } = (0, $66f1c142781ab216$export$2f872c0f2117be69)(data); | ||
| let { topic: topic, payload: payload } = (0, $66f1c142781ab216$export$2f872c0f2117be69)(data); | ||
| this.emit(topic, payload); | ||
@@ -779,3 +774,3 @@ } | ||
| */ onClose(code, reason) { | ||
| this.emit("client:disconnect", reason); | ||
| this.emit('client:disconnect', reason); | ||
| this.ws.removeAllListeners(); | ||
@@ -782,0 +777,0 @@ this.ws = null; |
+3
-3
@@ -25,4 +25,4 @@ export default Rivalis; | ||
| } | ||
| import CustomLoggerFactory from "./CustomLoggerFactory"; | ||
| import RoomManager from "./RoomManager"; | ||
| import Config from "./Config"; | ||
| import CustomLoggerFactory from './CustomLoggerFactory'; | ||
| import RoomManager from './RoomManager'; | ||
| import Config from './Config'; |
+5
-5
@@ -65,3 +65,3 @@ export default Room; | ||
| */ | ||
| protected bind(topic: string, topicListener: import('./main').TopicListener, context?: any | null): boolean; | ||
| protected bind(topic: string, topicListener: import("./main").TopicListener, context?: any | null): boolean; | ||
| /** | ||
@@ -118,5 +118,5 @@ * | ||
| } | ||
| import Actor from "./Actor"; | ||
| import { Logger } from "@toolcase/logging"; | ||
| import RoomManager from "./RoomManager"; | ||
| import TLayer from "./TLayer"; | ||
| import Actor from './Actor'; | ||
| import { Logger } from '@toolcase/logging'; | ||
| import RoomManager from './RoomManager'; | ||
| import TLayer from './TLayer'; |
| export default RoomManager; | ||
| export type EventTypes = ('define' | 'create' | 'destroy'); | ||
| export type EventTypes = ("define" | "create" | "destroy"); | ||
| /** | ||
@@ -33,3 +33,3 @@ * @typedef EventTypes | ||
| get count(): number; | ||
| keys(): IterableIterator<string>; | ||
| keys(): MapIterator<string>; | ||
| /** | ||
@@ -55,4 +55,4 @@ * | ||
| } | ||
| import { Broadcast } from "@toolcase/base"; | ||
| import Room from "./Room"; | ||
| import TLayer from "./TLayer"; | ||
| import { Broadcast } from '@toolcase/base'; | ||
| import Room from './Room'; | ||
| import TLayer from './TLayer'; |
+4
-4
| export default TLayer; | ||
| export type Message = string; | ||
| export type EventType = ('message' | 'kick'); | ||
| export type EventType = ("message" | "kick"); | ||
| export type EventFn = (actorId: string, message: Message) => any; | ||
| export type GetRoomFn = (roomId: string) => any; | ||
| export type GetRoomFn = (roomId: string) => import("./Room").Room; | ||
| /** | ||
@@ -31,3 +31,3 @@ * @typedef Message | ||
| constructor(authMiddleware: AuthMiddleware, getRoomFn?: GetRoomFn); | ||
| logger: import("@toolcase/logging/lib/Logger").default; | ||
| logger: import("@toolcase/logging").Logger; | ||
| /** | ||
@@ -108,2 +108,2 @@ * @private | ||
| } | ||
| import AuthMiddleware from "./AuthMiddleware"; | ||
| import AuthMiddleware from './AuthMiddleware'; |
@@ -15,2 +15,2 @@ export default Transport; | ||
| } | ||
| import TLayer from "./TLayer"; | ||
| import TLayer from './TLayer'; |
@@ -7,3 +7,3 @@ export default WSTransport; | ||
| */ | ||
| constructor(options: import('ws').ServerOptions, queryTicketParam?: any); | ||
| constructor(options: import("ws").ServerOptions, queryTicketParam?: any); | ||
| /** @private */ | ||
@@ -40,2 +40,2 @@ private logger; | ||
| } | ||
| import Transport from "../Transport"; | ||
| import Transport from '../Transport'; |
+1
-1
| { | ||
| "name": "@rivalis/core", | ||
| "version": "5.0.5", | ||
| "version": "5.0.6", | ||
| "description": "NodeJS framework for building real-time applications", | ||
@@ -5,0 +5,0 @@ "source": "src/main.js", |
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
65900
-0.8%1987
-0.3%