Compare commits
8 Commits
v0.27.5
...
v0.28.0-be
| Author | SHA1 | Date | |
|---|---|---|---|
| e70c78a255 | |||
| 9cfac1672a | |||
| 9126ec8035 | |||
| 23bc6068b5 | |||
| 27b428fbe2 | |||
| c07f1131c4 | |||
| 002f2c47c6 | |||
| 8633d9ea95 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,3 +1,4 @@
|
|||||||
|
.yarn*
|
||||||
.vscode
|
.vscode
|
||||||
.theia
|
.theia
|
||||||
node_modules
|
node_modules
|
||||||
|
|||||||
47
README.MD
47
README.MD
@@ -8,27 +8,28 @@
|
|||||||
|
|
||||||
```txt
|
```txt
|
||||||
└─packages
|
└─packages
|
||||||
├─api 全平台兼容的接口
|
├─api 全平台兼容的接口
|
||||||
├─core 核心代码 用于引导加载
|
├─core 核心代码 用于引导加载
|
||||||
├─common 公共类库代码 例如 http reflect 模块
|
├─common 公共类库代码 例如 http reflect 模块
|
||||||
├─client NodeJS的Minecraft客户端 用于调试插件
|
├─compile 编译器相关功能
|
||||||
├─container IOC容器 用于注入具体实现
|
├─client NodeJS 的 Minecraft 客户端 已迁移至 ms-client
|
||||||
├─ployfill Nashorn 的一些自定义增强
|
├─container IOC容器 用于注入具体实现
|
||||||
├─nashorn Nashorn 的类型定义
|
├─database 数据库相关功能
|
||||||
├─bungee BungeeCordAPI内部实现
|
├─protocol 协议处理相关功能
|
||||||
├─bukkit BukkitAPI内部实现
|
├─service 服务相关功能
|
||||||
├─sponge SpongeAPI内部实现
|
├─i18n 多语言环境相关支持
|
||||||
├─nukkit NukkitAPI内部实现
|
├─polyfill Nashorn 的一些自定义增强
|
||||||
├─plugin 插件管理器
|
├─nashorn Nashorn 的类型定义
|
||||||
├─websocket Netty的WebSocket注入
|
├─nodejs NodeJS 的部分 Java 实现
|
||||||
├─type Java的类型定义
|
├─bungee BungeeCordAPI 内部实现
|
||||||
| ├─bungee BungeeCord类型定义
|
├─bukkit BukkitAPI 内部实现
|
||||||
| ├─bukkit Bukkit类型定义
|
├─sponge SpongeAPI 内部实现
|
||||||
| ├─sponge Sponge类型定义
|
├─nukkit NukkitAPI 内部实现
|
||||||
| └─nukkit Nukkit类型定义
|
├─molang MoLang 解析库
|
||||||
└─plugins 这里当然是插件啦
|
├─qrcode 二维码相关类库
|
||||||
├─bungee 只兼容BungeeCord的插件
|
├─plugin 插件管理器
|
||||||
├─bukkit 只兼容Bukkit的插件
|
├─websocket WebSocket 相关实现
|
||||||
├─sponge 只兼容Sponge的插件
|
| ├─client 基于 Netty 的 WebSocket 客户端
|
||||||
└─nukkit 只兼容Nukkit的插件
|
| └─server 基于 Netty 的 WebSocket 服务端
|
||||||
|
└─type 类型定义 已迁移到 @javatypes
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
{
|
{
|
||||||
"version": "0.27.5",
|
"version": "0.28.0-beta.2",
|
||||||
"useWorkspaces": true,
|
|
||||||
"npmClient": "yarn",
|
"npmClient": "yarn",
|
||||||
"packages": [
|
"packages": [
|
||||||
"packages/*"
|
"packages/*"
|
||||||
|
|||||||
13
package.json
13
package.json
@@ -10,18 +10,19 @@
|
|||||||
"clean": "lerna run clean",
|
"clean": "lerna run clean",
|
||||||
"watch": "lerna run watch --parallel",
|
"watch": "lerna run watch --parallel",
|
||||||
"build": "lerna run build",
|
"build": "lerna run build",
|
||||||
"ug": "yarn upgrade-interactive --latest",
|
"ug": "yarn upgrade-interactive",
|
||||||
"np": "./script/push.sh",
|
"np": "./script/push.sh",
|
||||||
"lsp": "npm login -scope=@ccms",
|
"lsp": "npm login -scope=@ccms",
|
||||||
"lp": "lerna publish --verify-access --force-publish",
|
"lp": "lerna publish --force-publish",
|
||||||
"lpb": "lerna publish --preid beta --dist-tag beta --verify-access --force-publish",
|
"lpb": "lerna publish --preid beta --dist-tag beta --force-publish",
|
||||||
"lpc": "lerna publish --canary --preid beta --pre-dist-tag beta --verify-access --force-publish",
|
"lpc": "lerna publish --canary --preid beta --pre-dist-tag beta --force-publish",
|
||||||
"lpf": "lerna publish from-package --yes"
|
"lpf": "lerna publish from-package --yes",
|
||||||
|
"sync": "./script/sync.sh"
|
||||||
},
|
},
|
||||||
"workspaces": [
|
"workspaces": [
|
||||||
"packages/*"
|
"packages/*"
|
||||||
],
|
],
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"lerna": "^6.4.1"
|
"lerna": "^7.1.4"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/amqp",
|
"name": "@ccms/amqp",
|
||||||
"version": "0.27.5",
|
"version": "0.28.0-beta.2",
|
||||||
"description": "MiaoScript amqp package",
|
"description": "MiaoScript amqp package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -19,12 +19,12 @@
|
|||||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ccms/api": "^0.27.5",
|
"@ccms/api": "^0.28.0-beta.2",
|
||||||
"@ccms/common": "^0.27.5",
|
"@ccms/common": "^0.28.0-beta.2",
|
||||||
"@ccms/container": "^0.27.5"
|
"@ccms/container": "^0.28.0-beta.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@ccms/nashorn": "^0.27.5",
|
"@ccms/nashorn": "^0.28.0-beta.2",
|
||||||
"@javatypes/amqp-client": "^0.0.3",
|
"@javatypes/amqp-client": "^0.0.3",
|
||||||
"@javatypes/spring-amqp": "^0.0.3",
|
"@javatypes/spring-amqp": "^0.0.3",
|
||||||
"@javatypes/spring-rabbit": "^0.0.3",
|
"@javatypes/spring-rabbit": "^0.0.3",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/api",
|
"name": "@ccms/api",
|
||||||
"version": "0.27.5",
|
"version": "0.28.0-beta.2",
|
||||||
"description": "MiaoScript api package",
|
"description": "MiaoScript api package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -19,9 +19,9 @@
|
|||||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ccms/common": "^0.27.5",
|
"@ccms/common": "^0.28.0-beta.2",
|
||||||
"@ccms/container": "^0.27.5",
|
"@ccms/container": "^0.28.0-beta.2",
|
||||||
"@ccms/polyfill": "^0.27.5",
|
"@ccms/polyfill": "^0.28.0-beta.2",
|
||||||
"base64-js": "^1.5.1",
|
"base64-js": "^1.5.1",
|
||||||
"source-map-builder": "^0.0.7"
|
"source-map-builder": "^0.0.7"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -5,6 +5,13 @@ import { plugin } from './plugin'
|
|||||||
export namespace command {
|
export namespace command {
|
||||||
@injectable()
|
@injectable()
|
||||||
export abstract class Command {
|
export abstract class Command {
|
||||||
|
/**
|
||||||
|
* first time script engine need optimize jit code
|
||||||
|
* so ignore first slow exec notify
|
||||||
|
*/
|
||||||
|
private cacheSlowCommandKey = {};
|
||||||
|
private cacheSlowCompleteKey = {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 注册插件命令
|
* 注册插件命令
|
||||||
* @param plugin 插件
|
* @param plugin 插件
|
||||||
@@ -48,6 +55,8 @@ export namespace command {
|
|||||||
let result = executor(sender, command, Java.from(args))
|
let result = executor(sender, command, Java.from(args))
|
||||||
let cost = Date.now() - time
|
let cost = Date.now() - time
|
||||||
if (cost > global.ScriptSlowExecuteTime) {
|
if (cost > global.ScriptSlowExecuteTime) {
|
||||||
|
let commandKey = `${plugin.description.name}-${command}-${sender.name}`
|
||||||
|
if (!this.cacheSlowCommandKey[commandKey]) { return this.cacheSlowCommandKey[commandKey] = cost }
|
||||||
console.i18n("ms.api.command.execute.slow", {
|
console.i18n("ms.api.command.execute.slow", {
|
||||||
player: sender.name,
|
player: sender.name,
|
||||||
plugin: plugin.description.name,
|
plugin: plugin.description.name,
|
||||||
@@ -58,23 +67,17 @@ export namespace command {
|
|||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
} catch (ex: any) {
|
} catch (ex: any) {
|
||||||
console.i18n("ms.api.command.execute.error", {
|
let message = i18n.translate("ms.api.command.execute.error", {
|
||||||
player: sender.name,
|
player: sender.name,
|
||||||
plugin: plugin.description.name,
|
plugin: plugin.description.name,
|
||||||
command,
|
command,
|
||||||
args: Java.from(args).join(' '),
|
args: Java.from(args).join(' '),
|
||||||
ex
|
ex
|
||||||
})
|
})
|
||||||
|
console.console(message)
|
||||||
console.ex(ex)
|
console.ex(ex)
|
||||||
if (sender.name != 'CONSOLE') {
|
if (sender.name != 'CONSOLE') {
|
||||||
console.sender(sender, [i18n.translate("ms.api.command.execute.error", {
|
console.sender(sender, [message, ...console.stack(ex)])
|
||||||
player: sender.name,
|
|
||||||
plugin: plugin.description.name,
|
|
||||||
command,
|
|
||||||
args: Java.from(args).join(' '),
|
|
||||||
ex
|
|
||||||
}),
|
|
||||||
...console.stack(ex)])
|
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@@ -89,6 +92,8 @@ export namespace command {
|
|||||||
let result = this.copyPartialMatches(complete, token)
|
let result = this.copyPartialMatches(complete, token)
|
||||||
let cost = Date.now() - time
|
let cost = Date.now() - time
|
||||||
if (cost > global.ScriptSlowExecuteTime) {
|
if (cost > global.ScriptSlowExecuteTime) {
|
||||||
|
let completerKey = `${plugin.description.name}-${command}-${sender.name}`
|
||||||
|
if (!this.cacheSlowCompleteKey[completerKey]) { return this.cacheSlowCompleteKey[completerKey] = cost }
|
||||||
console.i18n("ms.api.command.tab.completer.slow", {
|
console.i18n("ms.api.command.tab.completer.slow", {
|
||||||
player: sender.name,
|
player: sender.name,
|
||||||
plugin: plugin.description.name,
|
plugin: plugin.description.name,
|
||||||
@@ -99,25 +104,17 @@ export namespace command {
|
|||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
} catch (ex: any) {
|
} catch (ex: any) {
|
||||||
console.i18n("ms.api.command.tab.completer.error", {
|
let message = i18n.translate("ms.api.command.tab.completer.error", {
|
||||||
player: sender.name,
|
player: sender.name,
|
||||||
plugin: plugin.description.name,
|
plugin: plugin.description.name,
|
||||||
command,
|
command,
|
||||||
args: Java.from(args).join(' '),
|
args: Java.from(args).join(' '),
|
||||||
ex
|
ex
|
||||||
})
|
})
|
||||||
|
console.console(message)
|
||||||
console.ex(ex)
|
console.ex(ex)
|
||||||
if (sender.name != 'CONSOLE') {
|
if (sender.name != 'CONSOLE') {
|
||||||
console.sender(sender, [
|
console.sender(sender, [message, ...console.stack(ex)])
|
||||||
i18n.translate("ms.api.command.tab.completer.error", {
|
|
||||||
player: sender.name,
|
|
||||||
plugin: plugin.description.name,
|
|
||||||
command,
|
|
||||||
args: Java.from(args).join(' '),
|
|
||||||
ex
|
|
||||||
}),
|
|
||||||
...console.stack(ex)
|
|
||||||
])
|
|
||||||
}
|
}
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ export namespace event {
|
|||||||
public EventPriority = EventPriority;
|
public EventPriority = EventPriority;
|
||||||
|
|
||||||
private mapEvent = [];
|
private mapEvent = [];
|
||||||
private listenerMap = [];
|
private pluginEventMap = [];
|
||||||
private cacheSlowEventKey = {};
|
private cacheSlowEventKey = {};
|
||||||
|
|
||||||
protected baseEventDir = '';
|
protected baseEventDir = '';
|
||||||
@@ -130,7 +130,7 @@ export namespace event {
|
|||||||
if (!plugin || !plugin.description || !plugin.description.name) throw new TypeError(i18n.translate("ms.api.event.listen.plugin.name.empty"))
|
if (!plugin || !plugin.description || !plugin.description.name) throw new TypeError(i18n.translate("ms.api.event.listen.plugin.name.empty"))
|
||||||
var name = plugin.description.name
|
var name = plugin.description.name
|
||||||
var eventCls = this.name2Class(name, event)
|
var eventCls = this.name2Class(name, event)
|
||||||
if (!eventCls) { return }
|
if (!eventCls) { return () => { console.warn('event ' + event + ' not found ignore off listener.') } }
|
||||||
if (typeof priority === 'boolean') {
|
if (typeof priority === 'boolean') {
|
||||||
ignoreCancel = priority
|
ignoreCancel = priority
|
||||||
priority = EventPriority.NORMAL
|
priority = EventPriority.NORMAL
|
||||||
@@ -140,16 +140,15 @@ export namespace event {
|
|||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
let executor = exec.name || exec.executor || '[anonymous]'
|
let executor = exec.name || exec.executor || '[anonymous]'
|
||||||
// noinspection JSUnusedGlobalSymbols
|
// noinspection JSUnusedGlobalSymbols
|
||||||
var listener = this.register(
|
let listener = this.register(
|
||||||
eventCls,
|
eventCls,
|
||||||
this.createExecute(name, exec, eventCls),
|
this.createExecute(name, exec, eventCls),
|
||||||
priority,
|
priority,
|
||||||
ignoreCancel
|
ignoreCancel
|
||||||
)
|
)
|
||||||
var listenerMap = this.listenerMap
|
|
||||||
// add to cache Be used for close plugin to close event
|
// add to cache Be used for close plugin to close event
|
||||||
if (!listenerMap[name]) listenerMap[name] = []
|
if (!this.pluginEventMap[name]) this.pluginEventMap[name] = []
|
||||||
var off = () => {
|
let off = () => {
|
||||||
if (off['offed']) return
|
if (off['offed']) return
|
||||||
off['offed'] = true
|
off['offed'] = true
|
||||||
this.unregister(eventCls, listener)
|
this.unregister(eventCls, listener)
|
||||||
@@ -159,7 +158,7 @@ export namespace event {
|
|||||||
exec: executor
|
exec: executor
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
listenerMap[name].push(off)
|
this.pluginEventMap[name].push(off)
|
||||||
// noinspection JSUnresolvedVariable
|
// noinspection JSUnresolvedVariable
|
||||||
console.debug(i18n.translate("ms.api.event.register", {
|
console.debug(i18n.translate("ms.api.event.register", {
|
||||||
name,
|
name,
|
||||||
@@ -176,10 +175,10 @@ export namespace event {
|
|||||||
* @param plugin 插件
|
* @param plugin 插件
|
||||||
*/
|
*/
|
||||||
disable(plugin: any) {
|
disable(plugin: any) {
|
||||||
var eventCache = this.listenerMap[plugin.description.name]
|
var eventCache = this.pluginEventMap[plugin.description.name]
|
||||||
if (eventCache) {
|
if (eventCache) {
|
||||||
eventCache.forEach((off: () => any) => off())
|
eventCache.forEach((off: () => any) => off())
|
||||||
delete this.listenerMap[plugin.description.name]
|
delete this.pluginEventMap[plugin.description.name]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,12 @@ const UUID = Java.type('java.util.UUID')
|
|||||||
const Math = Java.type('java.lang.Math')
|
const Math = Java.type('java.lang.Math')
|
||||||
|
|
||||||
export namespace particle {
|
export namespace particle {
|
||||||
|
@injectable()
|
||||||
|
export abstract class ParticleSpawner {
|
||||||
|
abstract spawn(location: any, particle: Particle)
|
||||||
|
abstract spawnToPlayer(player: any, location: any, particle: Particle)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 表示一个特效对象
|
* 表示一个特效对象
|
||||||
*
|
*
|
||||||
@@ -498,10 +504,4 @@ export namespace particle {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@injectable()
|
|
||||||
export abstract class ParticleSpawner {
|
|
||||||
abstract spawn(location: any, particle: Particle)
|
|
||||||
abstract spawnToPlayer(player: any, location: any, particle: Particle)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import { plugin } from './index'
|
import { EventEmitter } from 'events'
|
||||||
import { injectable } from '@ccms/container'
|
import { injectable } from '@ccms/container'
|
||||||
|
|
||||||
|
import { plugin } from './index'
|
||||||
|
|
||||||
const AtomicInteger = Java.type("java.util.concurrent.atomic.AtomicInteger")
|
const AtomicInteger = Java.type("java.util.concurrent.atomic.AtomicInteger")
|
||||||
|
|
||||||
export namespace task {
|
export namespace task {
|
||||||
@@ -79,7 +81,7 @@ export namespace task {
|
|||||||
/**
|
/**
|
||||||
* 任务抽象
|
* 任务抽象
|
||||||
*/
|
*/
|
||||||
export abstract class Task implements Cancelable {
|
export abstract class Task extends EventEmitter implements Cancelable {
|
||||||
protected func: Function
|
protected func: Function
|
||||||
protected isAsync: boolean = false;
|
protected isAsync: boolean = false;
|
||||||
protected laterTime: number = 0;
|
protected laterTime: number = 0;
|
||||||
@@ -88,7 +90,10 @@ export namespace task {
|
|||||||
protected taskId: number
|
protected taskId: number
|
||||||
protected innerTask: any
|
protected innerTask: any
|
||||||
|
|
||||||
|
private cancelled: boolean = false
|
||||||
|
|
||||||
constructor(owner: plugin.Plugin, func: Function, id: number) {
|
constructor(owner: plugin.Plugin, func: Function, id: number) {
|
||||||
|
super()
|
||||||
this.owner = owner
|
this.owner = owner
|
||||||
this.func = func
|
this.func = func
|
||||||
this.taskId = id
|
this.taskId = id
|
||||||
@@ -134,20 +139,35 @@ export namespace task {
|
|||||||
*/
|
*/
|
||||||
cancel(): boolean {
|
cancel(): boolean {
|
||||||
let result = this.cancel0()
|
let result = this.cancel0()
|
||||||
process.emit('task.finish', this)
|
this.finish()
|
||||||
|
this.cancelled = true
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
protected run(...args: any[]): void {
|
protected run(...args: any[]): void {
|
||||||
try {
|
try {
|
||||||
|
this.emit('before', this)
|
||||||
|
if (this.cancelled) { return }
|
||||||
this.func(...args)
|
this.func(...args)
|
||||||
!this.interval && process.emit('task.finish', this)
|
this.emit('after', this)
|
||||||
} catch (ex: any) {
|
} catch (error: any) {
|
||||||
console.console('§4插件执行任务时发生错误', ex)
|
this.emit('error', error)
|
||||||
console.ex(ex)
|
if (!error.processed) {
|
||||||
|
console.console('§4插件执行任务时发生错误', error)
|
||||||
|
console.ex(error)
|
||||||
|
this.cancel()
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
this.emit('finally', this)
|
||||||
|
if (!this.interval && !this.cancelled) { this.finish() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected finish() {
|
||||||
|
process.emit('task.finish', this)
|
||||||
|
this.emit('finish', this)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 提交任务
|
* 提交任务
|
||||||
* @param args 任务参数
|
* @param args 任务参数
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/bukkit",
|
"name": "@ccms/bukkit",
|
||||||
"version": "0.27.5",
|
"version": "0.28.0-beta.2",
|
||||||
"description": "MiaoScript bukkit package",
|
"description": "MiaoScript bukkit package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -25,8 +25,8 @@
|
|||||||
"typescript": "^4.9.5"
|
"typescript": "^4.9.5"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ccms/api": "^0.27.5",
|
"@ccms/api": "^0.28.0-beta.2",
|
||||||
"@ccms/common": "^0.27.5",
|
"@ccms/common": "^0.28.0-beta.2",
|
||||||
"@ccms/container": "^0.27.5"
|
"@ccms/container": "^0.28.0-beta.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/bungee",
|
"name": "@ccms/bungee",
|
||||||
"version": "0.27.5",
|
"version": "0.28.0-beta.2",
|
||||||
"description": "MiaoScript bungee package",
|
"description": "MiaoScript bungee package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -25,8 +25,8 @@
|
|||||||
"typescript": "^4.9.5"
|
"typescript": "^4.9.5"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ccms/api": "^0.27.5",
|
"@ccms/api": "^0.28.0-beta.2",
|
||||||
"@ccms/common": "^0.27.5",
|
"@ccms/common": "^0.28.0-beta.2",
|
||||||
"@ccms/container": "^0.27.5"
|
"@ccms/container": "^0.28.0-beta.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/common",
|
"name": "@ccms/common",
|
||||||
"version": "0.27.5",
|
"version": "0.28.0-beta.2",
|
||||||
"description": "MiaoScript common package",
|
"description": "MiaoScript common package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -19,7 +19,7 @@
|
|||||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@ccms/nashorn": "^0.27.5",
|
"@ccms/nashorn": "^0.28.0-beta.2",
|
||||||
"@javatypes/jdk": "^0.0.3",
|
"@javatypes/jdk": "^0.0.3",
|
||||||
"reflect-metadata": "^0.1.13",
|
"reflect-metadata": "^0.1.13",
|
||||||
"rimraf": "^4.1.2",
|
"rimraf": "^4.1.2",
|
||||||
|
|||||||
@@ -137,7 +137,7 @@ function declaredField(clazz: java.lang.Class<any>, name: string | java.lang.Str
|
|||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
if (target === undefined) { break }
|
if (target === undefined) { break }
|
||||||
target = target.getSuperclass()
|
target = target.getSuperclass()
|
||||||
console.debug(`切换到超类: ${target.getName()}`)
|
console.debug(`switch to super class: ${target.getName()}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (field === null) {
|
if (field === null) {
|
||||||
@@ -174,7 +174,7 @@ function declaredMethod(clazz: java.lang.Class<any>, nameOrIndex: string | numbe
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (target === undefined) { break }
|
if (target === undefined) { break }
|
||||||
target = target.getSuperclass()
|
target = target.getSuperclass()
|
||||||
console.debug(`切换到超类: ${target.getName()}`)
|
console.debug(`switch to super class: ${target.getName()}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -187,7 +187,7 @@ function declaredMethods(clazz: java.lang.Class<any>) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function mapToObject(javaObj) {
|
function mapToObject(javaObj) {
|
||||||
if (!Java.isJavaObject(javaObj)) { throw new TypeError(`参数 ${javaObj} 不是一个Java对象!`) }
|
if (!Java.isJavaObject(javaObj)) { throw new TypeError(`argument ${javaObj} is not a java object.`) }
|
||||||
let target = Proxy.newProxy(javaObj, {
|
let target = Proxy.newProxy(javaObj, {
|
||||||
apply: (target, name, args) => { return args ? javaObj[name](args) : javaObj[name]() }
|
apply: (target, name, args) => { return args ? javaObj[name](args) : javaObj[name]() }
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/compile",
|
"name": "@ccms/compile",
|
||||||
"version": "0.27.5",
|
"version": "0.28.0-beta.2",
|
||||||
"description": "MiaoScript compile package",
|
"description": "MiaoScript compile package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/container",
|
"name": "@ccms/container",
|
||||||
"version": "0.27.5",
|
"version": "0.28.0-beta.2",
|
||||||
"description": "MiaoScript container package",
|
"description": "MiaoScript container package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -19,7 +19,7 @@
|
|||||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@ccms/nashorn": "^0.27.5",
|
"@ccms/nashorn": "^0.28.0-beta.2",
|
||||||
"reflect-metadata": "^0.1.13",
|
"reflect-metadata": "^0.1.13",
|
||||||
"rimraf": "^4.1.2",
|
"rimraf": "^4.1.2",
|
||||||
"typescript": "^4.9.5"
|
"typescript": "^4.9.5"
|
||||||
|
|||||||
@@ -154,8 +154,10 @@ export const reduceMetadata = (ctx: interfaces.Context): any => {
|
|||||||
function initAutowired(container: Container) {
|
function initAutowired(container: Container) {
|
||||||
container.bind(ioc.Autowired).toDynamicValue((ctx) => {
|
container.bind(ioc.Autowired).toDynamicValue((ctx) => {
|
||||||
var metadata: any = reduceMetadata(ctx)
|
var metadata: any = reduceMetadata(ctx)
|
||||||
let key = Object.toString.call(metadata.named)
|
let key = Object.prototype.toString.call(metadata.named)
|
||||||
if (key === "[object Function]" || key === "[object Symbol]") { return container.get(metadata.named) }
|
if (key === "[object Function]" || key === "[object Symbol]") { return container.get(metadata.named) }
|
||||||
|
console.warn('container Autowired', metadata.named, 'failed. Error: illegal serviceIdentifier type', key)
|
||||||
|
console.debug(metadata.named, 'metadata', JSON.stringify(metadata))
|
||||||
return undefined
|
return undefined
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/core",
|
"name": "@ccms/core",
|
||||||
"version": "0.27.5",
|
"version": "0.28.0-beta.2",
|
||||||
"description": "MiaoScript core package",
|
"description": "MiaoScript core package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -24,8 +24,8 @@
|
|||||||
"typescript": "^4.9.5"
|
"typescript": "^4.9.5"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ccms/api": "^0.27.5",
|
"@ccms/api": "^0.28.0-beta.2",
|
||||||
"@ccms/container": "^0.27.5"
|
"@ccms/container": "^0.28.0-beta.2"
|
||||||
},
|
},
|
||||||
"gitHead": "781524f83e52cad26d7c480513e3c525df867121"
|
"gitHead": "781524f83e52cad26d7c480513e3c525df867121"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/database",
|
"name": "@ccms/database",
|
||||||
"version": "0.27.5",
|
"version": "0.28.0-beta.2",
|
||||||
"description": "MiaoScript database package",
|
"description": "MiaoScript database package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -25,7 +25,7 @@
|
|||||||
"typescript": "^4.9.5"
|
"typescript": "^4.9.5"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ccms/api": "^0.27.5",
|
"@ccms/api": "^0.28.0-beta.2",
|
||||||
"@ccms/container": "^0.27.5"
|
"@ccms/container": "^0.28.0-beta.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/i18n",
|
"name": "@ccms/i18n",
|
||||||
"version": "0.27.5",
|
"version": "0.28.0-beta.2",
|
||||||
"description": "MiaoScript i18n package",
|
"description": "MiaoScript i18n package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -19,7 +19,7 @@
|
|||||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@ccms/nashorn": "^0.27.5",
|
"@ccms/nashorn": "^0.28.0-beta.2",
|
||||||
"@types/js-yaml": "^4.0.5",
|
"@types/js-yaml": "^4.0.5",
|
||||||
"reflect-metadata": "^0.1.13",
|
"reflect-metadata": "^0.1.13",
|
||||||
"rimraf": "^4.1.2",
|
"rimraf": "^4.1.2",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/keyvalue",
|
"name": "@ccms/keyvalue",
|
||||||
"version": "0.27.5",
|
"version": "0.28.0-beta.2",
|
||||||
"description": "MiaoScript keyvalue package",
|
"description": "MiaoScript keyvalue package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -19,12 +19,12 @@
|
|||||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ccms/api": "^0.27.5",
|
"@ccms/api": "^0.28.0-beta.2",
|
||||||
"@ccms/common": "^0.27.5",
|
"@ccms/common": "^0.28.0-beta.2",
|
||||||
"@ccms/container": "^0.27.5"
|
"@ccms/container": "^0.28.0-beta.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@ccms/nashorn": "^0.27.5",
|
"@ccms/nashorn": "^0.28.0-beta.2",
|
||||||
"@javatypes/amqp-client": "^0.0.3",
|
"@javatypes/amqp-client": "^0.0.3",
|
||||||
"@javatypes/spring-amqp": "^0.0.3",
|
"@javatypes/spring-amqp": "^0.0.3",
|
||||||
"@javatypes/spring-rabbit": "^0.0.3",
|
"@javatypes/spring-rabbit": "^0.0.3",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/molang",
|
"name": "@ccms/molang",
|
||||||
"version": "0.27.5",
|
"version": "0.28.0-beta.2",
|
||||||
"description": "A fast parser for Minecraft's MoLang",
|
"description": "A fast parser for Minecraft's MoLang",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"types": "dist/index.d.ts",
|
"types": "dist/index.d.ts",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/nashorn",
|
"name": "@ccms/nashorn",
|
||||||
"version": "0.27.5",
|
"version": "0.28.0-beta.2",
|
||||||
"description": "MiaoScript nashorn package",
|
"description": "MiaoScript nashorn package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/nodejs",
|
"name": "@ccms/nodejs",
|
||||||
"version": "0.27.5",
|
"version": "0.28.0-beta.2",
|
||||||
"description": "MiaoScript nodejs package",
|
"description": "MiaoScript nodejs package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -19,7 +19,7 @@
|
|||||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@ccms/nashorn": "^0.27.5",
|
"@ccms/nashorn": "^0.28.0-beta.2",
|
||||||
"reflect-metadata": "^0.1.13",
|
"reflect-metadata": "^0.1.13",
|
||||||
"rimraf": "^4.1.2",
|
"rimraf": "^4.1.2",
|
||||||
"tslib": "^2.5.0",
|
"tslib": "^2.5.0",
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
var Throwable = Java.type('java.lang.Throwable')
|
||||||
var R = typeof Reflect === 'object' ? Reflect : null
|
var R = typeof Reflect === 'object' ? Reflect : null
|
||||||
var ReflectApply = R && typeof R.apply === 'function'
|
var ReflectApply = R && typeof R.apply === 'function'
|
||||||
? R.apply
|
? R.apply
|
||||||
@@ -136,13 +137,19 @@ EventEmitter.prototype.emit = function emit(type) {
|
|||||||
var er;
|
var er;
|
||||||
if (args.length > 0)
|
if (args.length > 0)
|
||||||
er = args[0];
|
er = args[0];
|
||||||
if (er instanceof Error) {
|
if (er instanceof Error || er instanceof Throwable) {
|
||||||
// Note: The comments on the `throw` lines are intentional, they show
|
// Note: The comments on the `throw` lines are intentional, they show
|
||||||
// up in Node's output if this results in an unhandled exception.
|
// up in Node's output if this results in an unhandled exception.
|
||||||
throw er; // Unhandled 'error' event
|
throw er; // Unhandled 'error' event
|
||||||
}
|
}
|
||||||
|
if (er.error instanceof Error || er.error instanceof Throwable) {
|
||||||
|
throw er.error; // Unhandled 'error' event
|
||||||
|
}
|
||||||
|
if (er.cause instanceof Error || er.error instanceof Throwable) {
|
||||||
|
throw er.error; // Unhandled 'error' event
|
||||||
|
}
|
||||||
// At least give some kind of context to the user
|
// At least give some kind of context to the user
|
||||||
var err = new Error('Unhandled error.' + (er ? ' (' + er.message + ')' : ''));
|
var err = new Error('Unhandled error.' + (er ? ' (' + (er.message || er.error || er.cause || er) + ')' : ''));
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
err.context = er;
|
err.context = er;
|
||||||
throw err; // Unhandled 'error' event
|
throw err; // Unhandled 'error' event
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ const Path = Java.type("java.nio.file.Path");
|
|||||||
const JavaString = Java.type("java.lang.String");
|
const JavaString = Java.type("java.lang.String");
|
||||||
const File = Java.type("java.io.File");
|
const File = Java.type("java.io.File");
|
||||||
const Files = Java.type("java.nio.file.Files");
|
const Files = Java.type("java.nio.file.Files");
|
||||||
|
const Paths = Java.type("java.nio.file.Paths");
|
||||||
const Collector = Java.type("java.util.stream.Collector")
|
const Collector = Java.type("java.util.stream.Collector")
|
||||||
const separatorChar = File.separatorChar;
|
const separatorChar = File.separatorChar;
|
||||||
const StandardCopyOption = Java.type("java.nio.file.StandardCopyOption");
|
const StandardCopyOption = Java.type("java.nio.file.StandardCopyOption");
|
||||||
@@ -37,7 +38,7 @@ function javaFile(...opts: any[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function renameSync(oldPath: PathLike, newPath: PathLike): void {
|
export function renameSync(oldPath: PathLike, newPath: PathLike): void {
|
||||||
|
Files.move(Paths.get(oldPath), Paths.get(oldPath), StandardCopyOption['ATOMIC_MOVE'])
|
||||||
}
|
}
|
||||||
export function truncateSync() {
|
export function truncateSync() {
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/nukkit",
|
"name": "@ccms/nukkit",
|
||||||
"version": "0.27.5",
|
"version": "0.28.0-beta.2",
|
||||||
"description": "MiaoScript nukkit package",
|
"description": "MiaoScript nukkit package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -25,8 +25,8 @@
|
|||||||
"typescript": "^4.9.5"
|
"typescript": "^4.9.5"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ccms/api": "^0.27.5",
|
"@ccms/api": "^0.28.0-beta.2",
|
||||||
"@ccms/common": "^0.27.5",
|
"@ccms/common": "^0.28.0-beta.2",
|
||||||
"@ccms/container": "^0.27.5"
|
"@ccms/container": "^0.28.0-beta.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/plugin",
|
"name": "@ccms/plugin",
|
||||||
"version": "0.27.5",
|
"version": "0.28.0-beta.2",
|
||||||
"description": "MiaoScript plugin package",
|
"description": "MiaoScript plugin package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -26,10 +26,10 @@
|
|||||||
"typescript": "^4.9.5"
|
"typescript": "^4.9.5"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ccms/api": "^0.27.5",
|
"@ccms/api": "^0.28.0-beta.2",
|
||||||
"@ccms/common": "^0.27.5",
|
"@ccms/common": "^0.28.0-beta.2",
|
||||||
"@ccms/container": "^0.27.5",
|
"@ccms/container": "^0.28.0-beta.2",
|
||||||
"@ccms/i18n": "^0.27.5",
|
"@ccms/i18n": "^0.28.0-beta.2",
|
||||||
"@ccms/verify": "^0.25.1",
|
"@ccms/verify": "^0.25.1",
|
||||||
"crypto-js": "^4.1.1",
|
"crypto-js": "^4.1.1",
|
||||||
"js-yaml": "^4.1.0"
|
"js-yaml": "^4.1.0"
|
||||||
|
|||||||
@@ -15,51 +15,51 @@ export class PluginCommandManager {
|
|||||||
process.on('plugin.after.disable', this.unregistryCommand.bind(this))
|
process.on('plugin.after.disable', this.unregistryCommand.bind(this))
|
||||||
}
|
}
|
||||||
|
|
||||||
private registryCommand(pluginInstance: plugin.Plugin) {
|
public registryCommand(pluginInstance: plugin.Plugin, executor: any = pluginInstance) {
|
||||||
let cmds = getPluginCommandMetadata(pluginInstance)
|
let cmds = getPluginCommandMetadata(executor)
|
||||||
let tabs = getPluginTabCompleterMetadata(pluginInstance)
|
let tabs = getPluginTabCompleterMetadata(executor)
|
||||||
for (const cmd of cmds) {
|
for (const cmd of cmds) {
|
||||||
if (!this.ServerChecker.check(cmd.servers)) {
|
if (!this.ServerChecker.check(cmd.servers)) {
|
||||||
console.debug(`[${pluginInstance.description.name}] ${cmd.target.constructor.name} incompatible command ${cmd.name} server(${cmd.servers}) ignore.`)
|
console.debug(`[${pluginInstance.description.name}] ${cmd.target.constructor.name} incompatible command ${cmd.name} server(${cmd.servers}) ignore.`)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
for (let command of [cmd.name, ...cmd.alias]) {
|
for (let command of [cmd.name, ...cmd.alias]) {
|
||||||
let [cmdExecutor, cmdCompleter] = this.generateAutoMainCommand(pluginInstance, cmd, tabs.get(command))
|
let [cmdExecutor, cmdCompleter] = this.generateAutoMainCommand(pluginInstance, executor, cmd, tabs.get(command))
|
||||||
this.CommandManager.on(pluginInstance, command, {
|
this.CommandManager.on(pluginInstance, command, {
|
||||||
cmd: cmdExecutor.bind(pluginInstance),
|
cmd: cmdExecutor.bind(executor),
|
||||||
tab: cmdCompleter?.bind(pluginInstance)
|
tab: cmdCompleter?.bind(executor)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private unregistryCommand(pluginInstance: plugin.Plugin) {
|
public unregistryCommand(pluginInstance: plugin.Plugin, executor: any = pluginInstance) {
|
||||||
let cmds = getPluginCommandMetadata(pluginInstance)
|
let cmds = getPluginCommandMetadata(executor)
|
||||||
for (const cmd of cmds) {
|
for (const cmd of cmds) {
|
||||||
if (!this.ServerChecker.check(cmd.servers)) {
|
if (!this.ServerChecker.check(cmd.servers)) {
|
||||||
console.debug(`[${pluginInstance.description.name}] ${cmd.target.constructor.name} incompatible command ${cmd.name} server(${cmd.servers}) ignore.`)
|
console.debug(`[${pluginInstance.description.name}] ${cmd.target.constructor.name} incompatible command ${cmd.name} server(${cmd.servers}) ignore.`)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
for (let command of [cmd.name, ...cmd.alias]) {
|
for (let command of [cmd.name, ...cmd.alias]) {
|
||||||
this.CommandManager.off(pluginInstance, command)
|
this.CommandManager.off(executor, command)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private generateAutoMainCommand(pluginInstance: plugin.Plugin, cmd: interfaces.CommandMetadata, tab: interfaces.CommandMetadata) {
|
private generateAutoMainCommand(pluginInstance: plugin.Plugin, executor: any, cmd: interfaces.CommandMetadata, tab: interfaces.CommandMetadata) {
|
||||||
let cmdExecutor = pluginInstance[cmd.executor]
|
let cmdExecutor = executor[cmd.executor]
|
||||||
let cmdCompleter = tab ? pluginInstance[tab.executor] : undefined
|
let cmdCompleter = tab ? executor[tab.executor] : undefined
|
||||||
let cmdSubCache = Object.keys(pluginInstance.constructor.prototype).filter(s => s.startsWith('cmd')).map(s => s.substring(3))
|
let cmdSubCache = Object.keys(executor.constructor.prototype).filter(s => s.startsWith('cmd')).map(s => s.substring(3))
|
||||||
if (cmd.autoMain) {
|
if (cmd.autoMain) {
|
||||||
cmdExecutor = (sender: any, command: string, args: string[]) => {
|
cmdExecutor = (sender: any, command: string, args: string[]) => {
|
||||||
let subcommand = args[0]
|
let subcommand = args[0]
|
||||||
let cmdKey = 'cmd' + subcommand
|
let cmdKey = 'cmd' + subcommand
|
||||||
if (!cmdSubCache.includes(subcommand)) {
|
if (!cmdSubCache.includes(subcommand)) {
|
||||||
if (!pluginInstance[cmd.executor].apply(pluginInstance, [sender, command, args])) {
|
if (!executor[cmd.executor].apply(executor, [sender, command, args])) {
|
||||||
subcommand && pluginInstance.logger.sender(sender, `§4未知的命令: §b/${command} §c${subcommand}`)
|
subcommand && pluginInstance.logger.sender(sender, `§4未知的命令: §b/${command} §c${subcommand}`)
|
||||||
pluginInstance.logger.sender(
|
pluginInstance.logger.sender(
|
||||||
sender,
|
sender,
|
||||||
pluginInstance['cmdhelp'] ?
|
executor['cmdhelp'] ?
|
||||||
`§6请执行 §b/${command} §ahelp §6查看帮助!` :
|
`§6请执行 §b/${command} §ahelp §6查看帮助!` :
|
||||||
[
|
[
|
||||||
`§6插件: §b${pluginInstance.description.name}`,
|
`§6插件: §b${pluginInstance.description.name}`,
|
||||||
@@ -69,7 +69,7 @@ export class PluginCommandManager {
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
let subcommandexec = pluginInstance[cmdKey]
|
let subcommandexec = executor[cmdKey]
|
||||||
let permission: string
|
let permission: string
|
||||||
if (cmd.permission && sender.hasPermission) {
|
if (cmd.permission && sender.hasPermission) {
|
||||||
if (typeof cmd.permission == "string") {
|
if (typeof cmd.permission == "string") {
|
||||||
@@ -82,7 +82,7 @@ export class PluginCommandManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
args.shift()
|
args.shift()
|
||||||
return subcommandexec.apply(pluginInstance, [sender, ...args])
|
return subcommandexec.apply(executor, [sender, ...args])
|
||||||
}
|
}
|
||||||
let originCompleter = cmdCompleter
|
let originCompleter = cmdCompleter
|
||||||
cmdCompleter = (sender: any, command: string, args: string[]) => {
|
cmdCompleter = (sender: any, command: string, args: string[]) => {
|
||||||
@@ -95,7 +95,7 @@ export class PluginCommandManager {
|
|||||||
}
|
}
|
||||||
if (!sender.hasPermission(permission)) { return [] }
|
if (!sender.hasPermission(permission)) { return [] }
|
||||||
}
|
}
|
||||||
return (args.length == 1 ? cmdSubCache : []).concat(originCompleter?.apply(pluginInstance, [sender, command, args]) || [])
|
return (args.length == 1 ? cmdSubCache : []).concat(originCompleter?.apply(executor, [sender, command, args]) || [])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!cmdCompleter) { console.debug(`[${pluginInstance.description.name}] command ${cmd.name} is not registry tabCompleter`) }
|
if (!cmdCompleter) { console.debug(`[${pluginInstance.description.name}] command ${cmd.name} is not registry tabCompleter`) }
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ export class PluginEventManager {
|
|||||||
@Autowired()
|
@Autowired()
|
||||||
private nativePluginChecker: server.NativePluginChecker
|
private nativePluginChecker: server.NativePluginChecker
|
||||||
|
|
||||||
|
private listenerMap = [];
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
process.on('plugin.before.enable', this.registryListener.bind(this))
|
process.on('plugin.before.enable', this.registryListener.bind(this))
|
||||||
process.on('plugin.after.disable', this.unregistryListener.bind(this))
|
process.on('plugin.after.disable', this.unregistryListener.bind(this))
|
||||||
@@ -20,8 +22,9 @@ export class PluginEventManager {
|
|||||||
return this.eventManager.mapEventName().toFixed(0)
|
return this.eventManager.mapEventName().toFixed(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
private registryListener(pluginInstance: plugin.Plugin) {
|
public registryListener(pluginInstance: plugin.Plugin, listener: any = pluginInstance) {
|
||||||
let events = getPluginListenerMetadata(pluginInstance)
|
let events = getPluginListenerMetadata(listener)
|
||||||
|
let execes = []
|
||||||
for (const event of events) {
|
for (const event of events) {
|
||||||
// ignore space listener
|
// ignore space listener
|
||||||
if (!this.serverChecker.check(event.servers)) {
|
if (!this.serverChecker.check(event.servers)) {
|
||||||
@@ -35,13 +38,25 @@ export class PluginEventManager {
|
|||||||
}
|
}
|
||||||
// here must bind this to pluginInstance
|
// here must bind this to pluginInstance
|
||||||
let exec = event.target[event.executor]
|
let exec = event.target[event.executor]
|
||||||
let execBinded = exec.bind(pluginInstance)
|
let execBinded = exec.bind(listener)
|
||||||
execBinded.executor = event.executor
|
execBinded.executor = event.executor
|
||||||
exec.off = this.eventManager.listen(pluginInstance, event.name, execBinded, event.priority, event.ignoreCancel)
|
exec.off = this.eventManager.listen(pluginInstance, event.name, execBinded, event.priority, event.ignoreCancel)
|
||||||
|
execes.push(exec)
|
||||||
}
|
}
|
||||||
|
let off = () => {
|
||||||
|
if (off['offed']) return
|
||||||
|
off['offed'] = true
|
||||||
|
execes.forEach((exec: { off: () => void }) => exec.off())
|
||||||
|
}
|
||||||
|
listener.off = off
|
||||||
}
|
}
|
||||||
|
|
||||||
private unregistryListener(pluginInstance: plugin.Plugin) {
|
private unregistryListener(pluginInstance: plugin.Plugin, listener: any = pluginInstance) {
|
||||||
this.eventManager.disable(pluginInstance)
|
if (listener && listener.off) {
|
||||||
|
listener.off()
|
||||||
|
}
|
||||||
|
if (pluginInstance) {
|
||||||
|
this.eventManager.disable(pluginInstance)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,9 @@ export * from './manager'
|
|||||||
export * from './decorators'
|
export * from './decorators'
|
||||||
export * from './interfaces'
|
export * from './interfaces'
|
||||||
|
|
||||||
|
export * from './event'
|
||||||
|
export * from './command'
|
||||||
|
|
||||||
export {
|
export {
|
||||||
plugin as JSPlugin,
|
plugin as JSPlugin,
|
||||||
cmd as Cmd,
|
cmd as Cmd,
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ export namespace interfaces {
|
|||||||
@injectable()
|
@injectable()
|
||||||
export abstract class Plugin implements plugin.Plugin {
|
export abstract class Plugin implements plugin.Plugin {
|
||||||
public description: plugin.PluginMetadata
|
public description: plugin.PluginMetadata
|
||||||
public logger: Console
|
public logger: MiaoScriptConsole
|
||||||
@inject(server.Console)
|
@inject(server.Console)
|
||||||
private Console: MiaoScriptConsole
|
private Console: MiaoScriptConsole
|
||||||
|
|
||||||
@@ -28,6 +28,11 @@ export namespace interfaces {
|
|||||||
return dataFolder.getAbsolutePath()
|
return dataFolder.getAbsolutePath()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public registryCommand(executor: any) { }
|
||||||
|
public unregistryCommand(executor: any) { }
|
||||||
|
public registryListener(listener: any) { }
|
||||||
|
public unregistryListener(listener: any) { }
|
||||||
|
|
||||||
public load() { }
|
public load() { }
|
||||||
public enable() { }
|
public enable() { }
|
||||||
public disable() { }
|
public disable() { }
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/polyfill",
|
"name": "@ccms/polyfill",
|
||||||
"version": "0.27.5",
|
"version": "0.28.0-beta.2",
|
||||||
"description": "MiaoScript polyfill package",
|
"description": "MiaoScript polyfill package",
|
||||||
"author": "MiaoWoo <admin@yumc.pw>",
|
"author": "MiaoWoo <admin@yumc.pw>",
|
||||||
"homepage": "https://github.com/circlecloud/ms.git",
|
"homepage": "https://github.com/circlecloud/ms.git",
|
||||||
@@ -14,12 +14,12 @@
|
|||||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ccms/i18n": "^0.27.5",
|
"@ccms/i18n": "^0.28.0-beta.2",
|
||||||
"@ccms/nodejs": "^0.27.5",
|
"@ccms/nodejs": "^0.28.0-beta.2",
|
||||||
"core-js": "^3.27.2"
|
"core-js": "^3.27.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@ccms/nashorn": "^0.27.5",
|
"@ccms/nashorn": "^0.28.0-beta.2",
|
||||||
"reflect-metadata": "^0.1.13",
|
"reflect-metadata": "^0.1.13",
|
||||||
"rimraf": "^4.1.2",
|
"rimraf": "^4.1.2",
|
||||||
"typescript": "^4.9.5"
|
"typescript": "^4.9.5"
|
||||||
|
|||||||
@@ -126,6 +126,7 @@ class Process extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class EventLoop {
|
class EventLoop {
|
||||||
|
private threadCount = new AtomicInteger(0)
|
||||||
private eventLoopMainThread = undefined
|
private eventLoopMainThread = undefined
|
||||||
private eventLoopTaskQueue = new DelayQueue()
|
private eventLoopTaskQueue = new DelayQueue()
|
||||||
private taskExecuteTimeout = 3000
|
private taskExecuteTimeout = 3000
|
||||||
@@ -134,10 +135,10 @@ class EventLoop {
|
|||||||
constructor() {
|
constructor() {
|
||||||
this.taskExecuteTimeout = parseInt(process.env.MS_TASK_EXECUTE_TIMEOUT) || 3000
|
this.taskExecuteTimeout = parseInt(process.env.MS_TASK_EXECUTE_TIMEOUT) || 3000
|
||||||
this.fixedThreadPool = new ThreadPoolExecutor(
|
this.fixedThreadPool = new ThreadPoolExecutor(
|
||||||
1, 1, 0, TimeUnit.SECONDS,
|
8, 16, 0, TimeUnit.SECONDS,
|
||||||
new LinkedBlockingQueue(1024),
|
new LinkedBlockingQueue(1024),
|
||||||
new ThreadFactory((run: any) => {
|
new ThreadFactory((run: any) => {
|
||||||
let thread = new Thread(run, "@ccms/event-loop")
|
let thread = new Thread(run, "@ccms/event-loop-" + this.threadCount.incrementAndGet())
|
||||||
thread.setDaemon(true)
|
thread.setDaemon(true)
|
||||||
return thread
|
return thread
|
||||||
}))
|
}))
|
||||||
@@ -198,7 +199,7 @@ class EventLoop {
|
|||||||
try {
|
try {
|
||||||
callback.apply(undefined, args)
|
callback.apply(undefined, args)
|
||||||
} catch (cause: any) {
|
} catch (cause: any) {
|
||||||
cause = cause.getCause && cause.getCause() || cause
|
cause = cause.getCause ? cause.getCause() : cause
|
||||||
try {
|
try {
|
||||||
process.emit('error', cause)
|
process.emit('error', cause)
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
@@ -213,7 +214,7 @@ class EventLoop {
|
|||||||
return console.warn(`FixedThreadPool isInterrupted exit! Task ${name} exec exit!`)
|
return console.warn(`FixedThreadPool isInterrupted exit! Task ${name} exec exit!`)
|
||||||
}
|
}
|
||||||
if (error instanceof TimeoutException) {
|
if (error instanceof TimeoutException) {
|
||||||
return console.warn(`Task ${name} => ${callback} exec time greater than ${this.taskExecuteTimeout}s!`)
|
return console.warn(`Task ${name} => ${callback} exec time greater than ${this.taskExecuteTimeout}ms!`)
|
||||||
}
|
}
|
||||||
throw error.getCause && error.getCause() || error
|
throw error.getCause && error.getCause() || error
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/protocol",
|
"name": "@ccms/protocol",
|
||||||
"version": "0.27.5",
|
"version": "0.28.0-beta.2",
|
||||||
"description": "MiaoScript protocol package",
|
"description": "MiaoScript protocol package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/qrcode",
|
"name": "@ccms/qrcode",
|
||||||
"version": "0.27.5",
|
"version": "0.28.0-beta.2",
|
||||||
"description": "MiaoScript qrcode package",
|
"description": "MiaoScript qrcode package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/sponge",
|
"name": "@ccms/sponge",
|
||||||
"version": "0.27.5",
|
"version": "0.28.0-beta.2",
|
||||||
"description": "MiaoScript sponge package",
|
"description": "MiaoScript sponge package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -25,8 +25,8 @@
|
|||||||
"typescript": "^4.9.5"
|
"typescript": "^4.9.5"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ccms/api": "^0.27.5",
|
"@ccms/api": "^0.28.0-beta.2",
|
||||||
"@ccms/common": "^0.27.5",
|
"@ccms/common": "^0.28.0-beta.2",
|
||||||
"@ccms/container": "^0.27.5"
|
"@ccms/container": "^0.28.0-beta.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/spring",
|
"name": "@ccms/spring",
|
||||||
"version": "0.27.5",
|
"version": "0.28.0-beta.2",
|
||||||
"description": "MiaoScript spring package",
|
"description": "MiaoScript spring package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -24,9 +24,9 @@
|
|||||||
"typescript": "^4.9.5"
|
"typescript": "^4.9.5"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ccms/api": "^0.27.5",
|
"@ccms/api": "^0.28.0-beta.2",
|
||||||
"@ccms/common": "^0.27.5",
|
"@ccms/common": "^0.28.0-beta.2",
|
||||||
"@ccms/container": "^0.27.5",
|
"@ccms/container": "^0.28.0-beta.2",
|
||||||
"@ccms/database": "^0.27.5"
|
"@ccms/database": "^0.28.0-beta.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/web",
|
"name": "@ccms/web",
|
||||||
"version": "0.27.5",
|
"version": "0.28.0-beta.2",
|
||||||
"description": "MiaoScript web package",
|
"description": "MiaoScript web package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -29,7 +29,7 @@
|
|||||||
"typescript": "^4.9.5"
|
"typescript": "^4.9.5"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ccms/api": "^0.27.5",
|
"@ccms/api": "^0.28.0-beta.2",
|
||||||
"@ccms/container": "^0.27.5"
|
"@ccms/container": "^0.28.0-beta.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/websocket",
|
"name": "@ccms/websocket",
|
||||||
"version": "0.27.5",
|
"version": "0.28.0-beta.2",
|
||||||
"description": "MiaoScript websocket package",
|
"description": "MiaoScript websocket package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -24,7 +24,7 @@
|
|||||||
"parseuri": "^0.0.6"
|
"parseuri": "^0.0.6"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@ccms/nashorn": "^0.27.5",
|
"@ccms/nashorn": "^0.28.0-beta.2",
|
||||||
"@javatypes/tomcat-websocket-api": "^0.0.3",
|
"@javatypes/tomcat-websocket-api": "^0.0.3",
|
||||||
"reflect-metadata": "^0.1.13",
|
"reflect-metadata": "^0.1.13",
|
||||||
"rimraf": "^4.1.2",
|
"rimraf": "^4.1.2",
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
import { EventEmitter } from 'events'
|
import { EventEmitter } from 'events'
|
||||||
import { Transport } from './transport'
|
import { Transport } from './transport'
|
||||||
import { CloseEvent, ErrorEvent, Event, EventType, MessageEvent, WebSocketHeader } from './interface'
|
import { ClientEvent, CloseEvent, ErrorEvent, Event, EventType, MessageEvent, WebSocketHeader } from './interface'
|
||||||
|
|
||||||
export class WebSocketManager {
|
export class WebSocketManager {
|
||||||
private clients = new Map<string, WebSocket>()
|
private clients = new Map<string, WebSocket>()
|
||||||
@@ -18,7 +18,9 @@ export class WebSocketManager {
|
|||||||
add(client: WebSocket) {
|
add(client: WebSocket) {
|
||||||
this.clients.set(client.id, client)
|
this.clients.set(client.id, client)
|
||||||
}
|
}
|
||||||
|
|
||||||
del(client: WebSocket) {
|
del(client: WebSocket) {
|
||||||
|
client.removeAllListeners()
|
||||||
this.clients.delete(client.id)
|
this.clients.delete(client.id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -26,12 +28,14 @@ export class WebSocketManager {
|
|||||||
export const manager = new WebSocketManager()
|
export const manager = new WebSocketManager()
|
||||||
|
|
||||||
export class WebSocket extends EventEmitter {
|
export class WebSocket extends EventEmitter {
|
||||||
|
public static manager: WebSocketManager = manager
|
||||||
|
|
||||||
public static CONNECTING = 0
|
public static CONNECTING = 0
|
||||||
public static OPEN = 1
|
public static OPEN = 1
|
||||||
public static CLOSING = 2
|
public static CLOSING = 2
|
||||||
public static CLOSED = 3
|
public static CLOSED = 3
|
||||||
|
|
||||||
public binaryType: 'blob' | 'arraybuffer'
|
public binaryType: 'blob' | 'arraybuffer'
|
||||||
protected manager: WebSocketManager
|
|
||||||
|
|
||||||
protected _url: string
|
protected _url: string
|
||||||
protected _headers: WebSocketHeader = {}
|
protected _headers: WebSocketHeader = {}
|
||||||
@@ -40,7 +44,6 @@ export class WebSocket extends EventEmitter {
|
|||||||
|
|
||||||
constructor(url: string, subProtocol: string | string[] = '', headers: WebSocketHeader = {}) {
|
constructor(url: string, subProtocol: string | string[] = '', headers: WebSocketHeader = {}) {
|
||||||
super()
|
super()
|
||||||
this.manager = manager
|
|
||||||
this._url = url
|
this._url = url
|
||||||
this._headers = headers
|
this._headers = headers
|
||||||
try {
|
try {
|
||||||
@@ -52,16 +55,14 @@ export class WebSocket extends EventEmitter {
|
|||||||
console.ex(error)
|
console.ex(error)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
this.client.on('open', (event) => {
|
// mamanger connected client
|
||||||
this.onopen?.(event)
|
manager.add(this)
|
||||||
manager.add(this)
|
this.client.on(ClientEvent.close, (_) => manager.del(this))
|
||||||
})
|
// add event forward
|
||||||
this.client.on('message', (event) => this.onmessage?.(event))
|
this.client.on(ClientEvent.open, (event) => this.onopen?.(event))
|
||||||
this.client.on('close', (event) => {
|
this.client.on(ClientEvent.message, (event) => this.onmessage?.(event))
|
||||||
this.onclose?.(event)
|
this.client.on(ClientEvent.close, (event) => this.onclose?.(event))
|
||||||
manager.del(this)
|
this.client.on(ClientEvent.error, (event) => this.onerror?.(event))
|
||||||
})
|
|
||||||
this.client.on('error', (event) => this.onerror?.(event))
|
|
||||||
setTimeout(() => this.client.connect(), 20)
|
setTimeout(() => this.client.connect(), 20)
|
||||||
}
|
}
|
||||||
get id() {
|
get id() {
|
||||||
@@ -77,26 +78,31 @@ export class WebSocket extends EventEmitter {
|
|||||||
return this.client.protocol
|
return this.client.protocol
|
||||||
}
|
}
|
||||||
get readyState() {
|
get readyState() {
|
||||||
return this.client.readyStatus
|
return this.client.readyState
|
||||||
}
|
}
|
||||||
get url() {
|
get url() {
|
||||||
return this._url
|
return this._url
|
||||||
}
|
}
|
||||||
|
|
||||||
public onopen: (event: Event) => void
|
public onopen: (event: Event) => void
|
||||||
public onmessage: (event: MessageEvent) => void
|
public onmessage: (event: MessageEvent) => void
|
||||||
public onclose: (event: CloseEvent) => void
|
public onclose: (event: CloseEvent) => void
|
||||||
public onerror: (event: ErrorEvent) => void
|
public onerror: (event: ErrorEvent) => void
|
||||||
|
|
||||||
addEventListener(event: EventType, callback: () => void) {
|
public on(eventName: string | symbol, listener: (...args: any[]) => void): this {
|
||||||
this[`on${event.toLowerCase()}`] = callback
|
this.client.on(eventName, listener)
|
||||||
this.client.on(event, callback)
|
return this
|
||||||
}
|
}
|
||||||
|
public emit(eventName: string | symbol, ...args: any[]): boolean {
|
||||||
|
return this.client.emit(eventName, ...args)
|
||||||
|
}
|
||||||
|
|
||||||
public send(data: any) {
|
public send(data: any) {
|
||||||
this.client.send(data)
|
return this.client.send(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
public close(code?: number, reason?: string) {
|
public close(code?: number, reason?: string) {
|
||||||
this.client.close(code, reason)
|
return this.client.close(code, reason)
|
||||||
this.removeAllListeners()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
global.setGlobal('WebSocket', WebSocket)
|
global.setGlobal('WebSocket', WebSocket)
|
||||||
|
|||||||
@@ -4,10 +4,18 @@ export interface WebSocketHeader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export type EventType =
|
export type EventType =
|
||||||
| 'close'
|
| ClientEvent.open
|
||||||
| 'error'
|
| ClientEvent.message
|
||||||
| 'message'
|
| ClientEvent.close
|
||||||
| 'open'
|
| ClientEvent.error
|
||||||
|
|
||||||
|
export enum ClientEvent {
|
||||||
|
open = 'open',
|
||||||
|
message = 'message',
|
||||||
|
close = 'close',
|
||||||
|
error = 'error',
|
||||||
|
}
|
||||||
|
|
||||||
export interface Event {
|
export interface Event {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
import { NettyWebSocket } from '.'
|
import { NettyWebSocket } from '.'
|
||||||
import { WebSocketClientHandlerAdapter } from './adapter/handler'
|
import { WebSocketClientHandlerAdapter } from './adapter/handler'
|
||||||
|
|
||||||
|
const Throwable = Java.type('java.lang.Throwable')
|
||||||
|
const RuntimeException = Java.type('java.lang.RuntimeException')
|
||||||
|
|
||||||
const CharsetUtil = Java.type('io.netty.util.CharsetUtil')
|
const CharsetUtil = Java.type('io.netty.util.CharsetUtil')
|
||||||
const TextWebSocketFrame = Java.type('io.netty.handler.codec.http.websocketx.TextWebSocketFrame')
|
const TextWebSocketFrame = Java.type('io.netty.handler.codec.http.websocketx.TextWebSocketFrame')
|
||||||
const CloseWebSocketFrame = Java.type('io.netty.handler.codec.http.websocketx.CloseWebSocketFrame')
|
const CloseWebSocketFrame = Java.type('io.netty.handler.codec.http.websocketx.CloseWebSocketFrame')
|
||||||
@@ -20,7 +23,7 @@ export class WebSocketClientHandler extends WebSocketClientHandlerAdapter {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
handlerAdded(ctx: any) {
|
handlerAdded(ctx: any) {
|
||||||
console.debug(`${ctx} handlerAdded`)
|
this.client.onconnection({})
|
||||||
if (ctx.newPromise) {
|
if (ctx.newPromise) {
|
||||||
this.handshakeFuture = ctx.newPromise()
|
this.handshakeFuture = ctx.newPromise()
|
||||||
} else {
|
} else {
|
||||||
@@ -28,20 +31,22 @@ export class WebSocketClientHandler extends WebSocketClientHandlerAdapter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
channelActive(ctx: any) {
|
channelActive(ctx: any) {
|
||||||
console.debug(`${ctx} channelActive`)
|
|
||||||
this.handshaker.handshake(ctx.channel())
|
this.handshaker.handshake(ctx.channel())
|
||||||
|
setTimeout(() => {
|
||||||
|
this.abortHandshake(new Error('handshake timed out.'))
|
||||||
|
}, 10000)
|
||||||
}
|
}
|
||||||
channelInactive(ctx: any) {
|
channelInactive(ctx: any) {
|
||||||
console.debug(`${ctx} channelInactive`)
|
this.client.close(1006, 'connection was closed abnormally.', true)
|
||||||
this.client.onclose({ code: 0, reason: 'client connection channel inactive!' })
|
|
||||||
}
|
}
|
||||||
channelRead0(ctx: any, msg: any) {
|
channelRead0(ctx: any, msg: any) {
|
||||||
console.trace(`${ctx} channelRead0 ${msg}`)
|
|
||||||
let ch = ctx.channel()
|
let ch = ctx.channel()
|
||||||
if (!this.handshaker.isHandshakeComplete()) {
|
if (!this.handshaker.isHandshakeComplete()) {
|
||||||
// web socket client connected
|
console.debug(`Netty Handler channelRead0 websocket client connected`)
|
||||||
|
// websocket client connected
|
||||||
this.handshaker.finishHandshake(ch, msg)
|
this.handshaker.finishHandshake(ch, msg)
|
||||||
this.handshakeFuture.setSuccess()
|
this.handshakeFuture.setSuccess()
|
||||||
|
this.client.onconnect({})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,14 +59,19 @@ export class WebSocketClientHandler extends WebSocketClientHandlerAdapter {
|
|||||||
if (frame instanceof TextWebSocketFrame) {
|
if (frame instanceof TextWebSocketFrame) {
|
||||||
this.client.onmessage({ data: frame.text() })
|
this.client.onmessage({ data: frame.text() })
|
||||||
} else if (frame instanceof CloseWebSocketFrame) {
|
} else if (frame instanceof CloseWebSocketFrame) {
|
||||||
this.client.onclose({ code: 0, reason: 'server close connection!' })
|
this.client.receiverClose(frame.statusCode(), frame.reasonText())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
abortHandshake(reason: Error) {
|
||||||
|
if (this.handshakeFuture.isDone()) { return }
|
||||||
|
if (!(reason instanceof Throwable)) {
|
||||||
|
reason = new RuntimeException(reason)
|
||||||
|
}
|
||||||
|
this.handshakeFuture.setFailure(reason)
|
||||||
|
}
|
||||||
exceptionCaught(ctx: any, cause: Error) {
|
exceptionCaught(ctx: any, cause: Error) {
|
||||||
console.debug(`${ctx} exceptionCaught ${cause}`)
|
console.debug(`${ctx} exceptionCaught ${cause}`)
|
||||||
|
this.client.abortHandshake(cause)
|
||||||
this.client.onerror({ error: cause })
|
this.client.onerror({ error: cause })
|
||||||
if (!this.handshakeFuture.isDone()) {
|
|
||||||
this.handshakeFuture.setFailure(cause)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,6 +60,8 @@ export class NettyWebSocket extends Transport {
|
|||||||
private channel: any
|
private channel: any
|
||||||
private b: any
|
private b: any
|
||||||
|
|
||||||
|
private handler: any
|
||||||
|
|
||||||
constructor(url: string, subProtocol: string = '', headers: WebSocketHeader = {}) {
|
constructor(url: string, subProtocol: string = '', headers: WebSocketHeader = {}) {
|
||||||
super(url, subProtocol, headers)
|
super(url, subProtocol, headers)
|
||||||
if (!url) {
|
if (!url) {
|
||||||
@@ -85,13 +87,9 @@ export class NettyWebSocket extends Transport {
|
|||||||
console.debug(`constructor NettyWebSocket url: ${url} scheme: ${this._schema} host: ${this._host} port: ${this._port} header: ${JSON.stringify(headers)}`)
|
console.debug(`constructor NettyWebSocket url: ${url} scheme: ${this._schema} host: ${this._host} port: ${this._port} header: ${JSON.stringify(headers)}`)
|
||||||
}
|
}
|
||||||
getId() {
|
getId() {
|
||||||
if (this.channel?.id) {
|
return `${this.channel?.id()}` || `NettyWebSocket#${channelCount.incrementAndGet()}`
|
||||||
return this.channel?.id() + ''
|
|
||||||
}
|
|
||||||
return 'NettyWebSocket#' + channelCount.incrementAndGet()
|
|
||||||
}
|
}
|
||||||
doConnect() {
|
doConnect() {
|
||||||
console.debug('client NettyWebSocket doConnect', this._url)
|
|
||||||
let uri = URI.create(this._url)
|
let uri = URI.create(this._url)
|
||||||
let headers = new DefaultHttpHeaders()
|
let headers = new DefaultHttpHeaders()
|
||||||
for (const key of Object.getOwnPropertyNames(this._headers || {})) {
|
for (const key of Object.getOwnPropertyNames(this._headers || {})) {
|
||||||
@@ -100,7 +98,7 @@ export class NettyWebSocket extends Transport {
|
|||||||
// Connect with V13 (RFC 6455 aka HyBi-17). You can change it to V08 or V00.
|
// Connect with V13 (RFC 6455 aka HyBi-17). You can change it to V08 or V00.
|
||||||
// If you change it to V00, ping is not supported and remember to change
|
// If you change it to V00, ping is not supported and remember to change
|
||||||
// HttpResponseDecoder to WebSocketHttpResponseDecoder in the pipeline.
|
// HttpResponseDecoder to WebSocketHttpResponseDecoder in the pipeline.
|
||||||
let handler = new WebSocketClientHandler(WebSocketClientHandshakerFactory
|
this.handler = new WebSocketClientHandler(WebSocketClientHandshakerFactory
|
||||||
.newHandshaker(uri, WebSocketVersion.V13, null, false, headers), this)
|
.newHandshaker(uri, WebSocketVersion.V13, null, false, headers), this)
|
||||||
this.b = new Bootstrap()
|
this.b = new Bootstrap()
|
||||||
this.b.group(group)
|
this.b.group(group)
|
||||||
@@ -111,7 +109,7 @@ export class NettyWebSocket extends Transport {
|
|||||||
if (this._schema == "wss") {
|
if (this._schema == "wss") {
|
||||||
if (SslContextBuilder) {
|
if (SslContextBuilder) {
|
||||||
let sslCtx = SslContextBuilder.forClient().trustManager(InsecureTrustManagerFactory.INSTANCE).build()
|
let sslCtx = SslContextBuilder.forClient().trustManager(InsecureTrustManagerFactory.INSTANCE).build()
|
||||||
pipeline.addLast(sslCtx.newHandler(ch.alloc(), this._host, this._port))
|
pipeline.addLast('ssl', sslCtx.newHandler(ch.alloc(), this._host, this._port))
|
||||||
} else {
|
} else {
|
||||||
let sslEngine = SSLContext.getDefault().createSSLEngine()
|
let sslEngine = SSLContext.getDefault().createSSLEngine()
|
||||||
sslEngine.setUseClientMode(true)
|
sslEngine.setUseClientMode(true)
|
||||||
@@ -120,35 +118,36 @@ export class NettyWebSocket extends Transport {
|
|||||||
}
|
}
|
||||||
pipeline.addLast("http-codec", new HttpClientCodec())
|
pipeline.addLast("http-codec", new HttpClientCodec())
|
||||||
pipeline.addLast("aggregator", new HttpObjectAggregator(65536))
|
pipeline.addLast("aggregator", new HttpObjectAggregator(65536))
|
||||||
pipeline.addLast("websocket", handler.getHandler())
|
pipeline.addLast("websocket", this.handler.getHandler())
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
this.b.connect(this._host, this._port).addListener(new ChannelFutureListener((future: any) => {
|
try {
|
||||||
try {
|
this.channel = this.b.connect(this._host, this._port).sync().channel()
|
||||||
this.channel = future.sync().channel()
|
this.handler.handshakeFuture.sync()
|
||||||
this.onconnection({})
|
} catch (error) {
|
||||||
handler.handshakeFuture.addListener(new ChannelFutureListener((future: any) => {
|
// ignore connect error
|
||||||
try {
|
// tigger error at handshakeFuture
|
||||||
future.sync()
|
}
|
||||||
// only trigger onconnect when not have error
|
|
||||||
this.onconnect({})
|
|
||||||
} catch (error: any) {
|
|
||||||
// ignore error exceptionCaught from handler
|
|
||||||
// this.onerror({ error })
|
|
||||||
}
|
|
||||||
}))
|
|
||||||
} catch (error: any) {
|
|
||||||
this.onerror({ error })
|
|
||||||
}
|
|
||||||
}))
|
|
||||||
}
|
}
|
||||||
doSend(text: string) {
|
doSend(text: string) {
|
||||||
this.channel.writeAndFlush(new TextWebSocketFrame(text))
|
this.channel.writeAndFlush(new TextWebSocketFrame(text))
|
||||||
}
|
}
|
||||||
doClose(code: number, reason: string) {
|
doClose(code: number, reason: string, wasClean: boolean = false) {
|
||||||
this.channel.writeAndFlush(new CloseWebSocketFrame())
|
console.debug(`Netty Client doClose code: ${code} reason: ${reason}`)
|
||||||
this.channel.close()
|
if (this.readyState == WebSocket.CLOSING) {
|
||||||
this.channel.closeFuture().addListener(new ChannelFutureListener(() => console.debug(`NettyWebSocket close code: ${code} reason: ${reason}`)))
|
if (!this._closeFrameSent) {
|
||||||
|
console.debug(`Netty Client doClose send close frame`)
|
||||||
|
this.channel?.writeAndFlush(new CloseWebSocketFrame(code, reason))
|
||||||
|
this._closeFrameSent = true
|
||||||
|
}
|
||||||
|
if (!this._closeFrameReceived && !wasClean) { return console.debug(`Netty Client doClose wait server send close`) }
|
||||||
|
}
|
||||||
|
this.channel?.closeFuture().addListener(new ChannelFutureListener(() => {
|
||||||
|
this.onclose({ code, reason })
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
abortHandshake(reason: Error): void {
|
||||||
|
this.handler.abortHandshake(reason)
|
||||||
}
|
}
|
||||||
getChannel() {
|
getChannel() {
|
||||||
return this.channel
|
return this.channel
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { EventEmitter } from 'events'
|
import { EventEmitter } from 'events'
|
||||||
import { WebSocket } from './index'
|
import { WebSocket } from './index'
|
||||||
import { CloseEvent, ErrorEvent, Event, MessageEvent, WebSocketHeader } from './interface'
|
import { ClientEvent, CloseEvent, ErrorEvent, Event, MessageEvent, WebSocketHeader } from './interface'
|
||||||
|
|
||||||
export abstract class Transport extends EventEmitter {
|
export abstract class Transport extends EventEmitter {
|
||||||
protected _url: string
|
protected _url: string
|
||||||
@@ -8,6 +8,9 @@ export abstract class Transport extends EventEmitter {
|
|||||||
protected _protocol: string
|
protected _protocol: string
|
||||||
protected _headers: WebSocketHeader = {}
|
protected _headers: WebSocketHeader = {}
|
||||||
|
|
||||||
|
protected _closeFrameReceived = false;
|
||||||
|
protected _closeFrameSent = false;
|
||||||
|
|
||||||
constructor(uri: string, subProtocol: string = '', headers: WebSocketHeader = {}) {
|
constructor(uri: string, subProtocol: string = '', headers: WebSocketHeader = {}) {
|
||||||
super()
|
super()
|
||||||
this._url = uri
|
this._url = uri
|
||||||
@@ -23,25 +26,22 @@ export abstract class Transport extends EventEmitter {
|
|||||||
return this._protocol
|
return this._protocol
|
||||||
}
|
}
|
||||||
|
|
||||||
get readyStatus() {
|
get readyState() {
|
||||||
return this._state
|
return this._state
|
||||||
}
|
}
|
||||||
|
|
||||||
set readyStatus(state: number) {
|
set readyState(state: number) {
|
||||||
this._state = state
|
this._state = state
|
||||||
}
|
}
|
||||||
|
|
||||||
connect() {
|
connect() {
|
||||||
console.debug(`client Transport connect`)
|
this.doConnect()
|
||||||
try {
|
|
||||||
this.doConnect()
|
|
||||||
} catch (error: any) {
|
|
||||||
console.ex(error)
|
|
||||||
this.onerror({ error })
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
send(text: string) {
|
send(text: string) {
|
||||||
|
if (this.readyState === WebSocket.CONNECTING) {
|
||||||
|
throw new Error('WebSocket is not open: readyState 0 (CONNECTING)');
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
this.doSend(text)
|
this.doSend(text)
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
@@ -49,19 +49,24 @@ export abstract class Transport extends EventEmitter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
close(code: number = 0, reason: string = '') {
|
close(code: number = 1000, reason: string = '', wasClean: boolean = false) {
|
||||||
if (this.readyStatus != WebSocket.CLOSING && this.readyStatus != WebSocket.CLOSED) {
|
if (this.readyState === WebSocket.CLOSED) return;
|
||||||
this.readyStatus = WebSocket.CLOSING
|
if (this.readyState === WebSocket.CONNECTING) {
|
||||||
try {
|
const msg = 'WebSocket was closed before the connection was established';
|
||||||
this.onclose({ code, reason })
|
this.abortHandshake(new Error(msg));
|
||||||
this.doClose(code, reason)
|
return;
|
||||||
} catch (error: any) {
|
}
|
||||||
this.onerror({ error })
|
if (this.readyState === WebSocket.CLOSING) {
|
||||||
} finally {
|
if (this._closeFrameSent && this._closeFrameReceived) {
|
||||||
this.removeAllListeners()
|
this.onclose({ code, reason });
|
||||||
}
|
}
|
||||||
} else {
|
return;
|
||||||
console.debug(`${this.id} call close but state is ${this.readyStatus}`)
|
}
|
||||||
|
this.readyState = WebSocket.CLOSING
|
||||||
|
try {
|
||||||
|
this.doClose(code, reason, wasClean)
|
||||||
|
} catch (error: any) {
|
||||||
|
this.onerror({ error })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,33 +76,41 @@ export abstract class Transport extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onconnect(event: Event) {
|
onconnect(event: Event) {
|
||||||
if (this.readyStatus != WebSocket.OPEN) {
|
if (this.readyState != WebSocket.OPEN) {
|
||||||
this.readyStatus = WebSocket.OPEN
|
this.readyState = WebSocket.OPEN
|
||||||
this.emit('open', event)
|
this.emit(ClientEvent.open, event)
|
||||||
} else {
|
} else {
|
||||||
console.debug(`${this.id} call onconnect but state is ${this.readyStatus}`)
|
console.debug(`WebSocket Transport ${this.id} call onconnect but state is ${this.readyState}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onmessage(event: MessageEvent) {
|
onmessage(event: MessageEvent) {
|
||||||
this.emit('message', event)
|
this.emit(ClientEvent.message, event)
|
||||||
}
|
}
|
||||||
|
|
||||||
onerror(event: ErrorEvent) {
|
onerror(event: ErrorEvent) {
|
||||||
this.emit('error', event)
|
this.emit(ClientEvent.error, event)
|
||||||
}
|
}
|
||||||
|
|
||||||
onclose(event: CloseEvent) {
|
onclose(event: CloseEvent) {
|
||||||
if (this.readyStatus != WebSocket.CLOSED) {
|
console.debug(`WebSocket Transport ${this.id} call onclose CloseEvent[code: ${event.code}, reason: ${event.reason}]`)
|
||||||
this.readyStatus = WebSocket.CLOSED
|
if (this.readyState != WebSocket.CLOSED) {
|
||||||
this.emit('close', event)
|
this.readyState = WebSocket.CLOSED
|
||||||
this.removeAllListeners()
|
this.emit(ClientEvent.close, event)
|
||||||
} else {
|
} else {
|
||||||
console.debug(`${this.id} call onclose but state is ${this.readyStatus} CloseEvent[code: ${event.code}, reason: ${event.reason}]`)
|
console.debug(`WebSocket Transport ${this.id} call onclose but state is ${this.readyState} CloseEvent[code: ${event.code}, reason: ${event.reason}]`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
abstract getId()
|
|
||||||
abstract doConnect()
|
receiverClose(code: number, reason: string) {
|
||||||
abstract doSend(text: string)
|
console.debug(`Netty Handler receeve close code: ${code} reason: ${reason}`)
|
||||||
abstract doClose(code: number, reason: string)
|
this._closeFrameReceived = true;
|
||||||
|
this.close(code, reason)
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract getId(): string
|
||||||
|
abstract doConnect(): void
|
||||||
|
abstract doSend(text: string): void
|
||||||
|
abstract doClose(code: number, reason: string, wasClean?: boolean): void
|
||||||
|
abstract abortHandshake(reason: Error): void
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/// <reference types="@ccms/nashorn" />
|
/// <reference types="@ccms/nashorn" />
|
||||||
/// <reference types="@javatypes/tomcat-websocket-api" />
|
/// <reference types="@javatypes/tomcat-websocket-api" />
|
||||||
|
|
||||||
import * as server from './server'
|
import { WebSocketServer } from './server'
|
||||||
import { Server, ServerOptions } from './socket.io'
|
import { Server, ServerOptions } from './socket.io'
|
||||||
|
|
||||||
interface SocketIOStatic {
|
interface SocketIOStatic {
|
||||||
@@ -45,7 +45,7 @@ let singletonServer: Server
|
|||||||
let io: SocketStatic = function io(pipeline: any, options: Partial<JavaServerOptions>, singleton = true) {
|
let io: SocketStatic = function io(pipeline: any, options: Partial<JavaServerOptions>, singleton = true) {
|
||||||
if (singleton) {
|
if (singleton) {
|
||||||
if (!singletonServer) {
|
if (!singletonServer) {
|
||||||
singletonServer = new Server(server.attach(pipeline, options), options)
|
singletonServer = new Server(WebSocketServer.attach(pipeline, options), options)
|
||||||
process.emit('websocket.create', singletonServer)
|
process.emit('websocket.create', singletonServer)
|
||||||
process.on('exit', () => {
|
process.on('exit', () => {
|
||||||
singletonServer.close()
|
singletonServer.close()
|
||||||
@@ -53,7 +53,7 @@ let io: SocketStatic = function io(pipeline: any, options: Partial<JavaServerOpt
|
|||||||
}
|
}
|
||||||
return singletonServer
|
return singletonServer
|
||||||
}
|
}
|
||||||
return new Server(server.attach(pipeline, options), options)
|
return new Server(WebSocketServer.attach(pipeline, options), options)
|
||||||
}
|
}
|
||||||
io.Instance = Symbol("@ccms/websocket")
|
io.Instance = Symbol("@ccms/websocket")
|
||||||
export default io
|
export default io
|
||||||
|
|||||||
@@ -26,6 +26,24 @@ export abstract class WebSocketServer extends EventEmitter {
|
|||||||
protected instance: any
|
protected instance: any
|
||||||
protected options: JavaServerOptions
|
protected options: JavaServerOptions
|
||||||
private clients: Map<string, WebSocketClient>
|
private clients: Map<string, WebSocketClient>
|
||||||
|
|
||||||
|
public static attach(instance, options) {
|
||||||
|
if (!instance) { throw new Error('instance can\'t be undefiend!') }
|
||||||
|
options = Object.assign({
|
||||||
|
event: new EventEmitter(),
|
||||||
|
path: '/ws',
|
||||||
|
root: root + Java.type("java.io.File").separatorChar + 'wwwroot',
|
||||||
|
}, options)
|
||||||
|
let WebSocketServerImpl = undefined
|
||||||
|
if (instance.class.name.startsWith('io.netty.channel')) {
|
||||||
|
WebSocketServerImpl = require("./netty").NettyWebSocketServer
|
||||||
|
} else {
|
||||||
|
WebSocketServerImpl = require("./tomcat").TomcatWebSocketServer
|
||||||
|
}
|
||||||
|
console.debug('create websocket server from ' + WebSocketServerImpl.name)
|
||||||
|
return new WebSocketServerImpl(instance, options)
|
||||||
|
}
|
||||||
|
|
||||||
constructor(instance: any, options: JavaServerOptions) {
|
constructor(instance: any, options: JavaServerOptions) {
|
||||||
super()
|
super()
|
||||||
this.instance = instance
|
this.instance = instance
|
||||||
@@ -69,20 +87,3 @@ export abstract class WebSocketServer extends EventEmitter {
|
|||||||
protected abstract getSocket(handler: any): WebSocketClient
|
protected abstract getSocket(handler: any): WebSocketClient
|
||||||
protected abstract doClose(): void
|
protected abstract doClose(): void
|
||||||
}
|
}
|
||||||
|
|
||||||
export const attach = (instance, options) => {
|
|
||||||
if (!instance) { throw new Error('instance can\'t be undefiend!') }
|
|
||||||
options = Object.assign({
|
|
||||||
event: new EventEmitter(),
|
|
||||||
path: '/ws',
|
|
||||||
root: root + Java.type("java.io.File").separatorChar + 'wwwroot',
|
|
||||||
}, options)
|
|
||||||
let WebSocketServerImpl = undefined
|
|
||||||
if (instance.class.name.startsWith('io.netty.channel')) {
|
|
||||||
WebSocketServerImpl = require("./netty").NettyWebSocketServer
|
|
||||||
} else {
|
|
||||||
WebSocketServerImpl = require("./tomcat").TomcatWebSocketServer
|
|
||||||
}
|
|
||||||
console.debug('create websocket server from ' + WebSocketServerImpl.name)
|
|
||||||
return new WebSocketServerImpl(instance, options)
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
DISTTAG=${1:latest}
|
||||||
for package in `ls packages`; do
|
for package in `ls packages`; do
|
||||||
echo $package
|
echo $package
|
||||||
pushd packages/$package
|
pushd packages/$package
|
||||||
npm publish --access=public --registry https://registry.npmjs.org
|
npm publish --tag ${DISTTAG} --access=public --registry https://registry.npmjs.org
|
||||||
popd
|
popd
|
||||||
done
|
done
|
||||||
|
|||||||
4
script/sync.sh
Executable file
4
script/sync.sh
Executable file
@@ -0,0 +1,4 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
for PACKAGE in `ls packages`;do
|
||||||
|
echo "${PACKAGE} $(curl -s "https://registry-direct.npmmirror.com/@ccms/${PACKAGE}/sync?sync_upstream=true" -X 'PUT')"
|
||||||
|
done
|
||||||
Reference in New Issue
Block a user