Compare commits
4 Commits
v0.27.6
...
v0.28.0-be
| Author | SHA1 | Date | |
|---|---|---|---|
| 9126ec8035 | |||
| 23bc6068b5 | |||
| 27b428fbe2 | |||
| c07f1131c4 |
@@ -1,6 +1,5 @@
|
||||
{
|
||||
"version": "0.27.6",
|
||||
"useWorkspaces": true,
|
||||
"version": "0.28.0-beta.1",
|
||||
"npmClient": "yarn",
|
||||
"packages": [
|
||||
"packages/*"
|
||||
|
||||
13
package.json
13
package.json
@@ -10,18 +10,19 @@
|
||||
"clean": "lerna run clean",
|
||||
"watch": "lerna run watch --parallel",
|
||||
"build": "lerna run build",
|
||||
"ug": "yarn upgrade-interactive --latest",
|
||||
"ug": "yarn upgrade-interactive",
|
||||
"np": "./script/push.sh",
|
||||
"lsp": "npm login -scope=@ccms",
|
||||
"lp": "lerna publish --verify-access --force-publish",
|
||||
"lpb": "lerna publish --preid beta --dist-tag beta --verify-access --force-publish",
|
||||
"lpc": "lerna publish --canary --preid beta --pre-dist-tag beta --verify-access --force-publish",
|
||||
"lpf": "lerna publish from-package --yes"
|
||||
"lp": "lerna publish --force-publish",
|
||||
"lpb": "lerna publish --preid beta --dist-tag beta --force-publish",
|
||||
"lpc": "lerna publish --canary --preid beta --pre-dist-tag beta --force-publish",
|
||||
"lpf": "lerna publish from-package --yes",
|
||||
"sync": "./script/sync.sh"
|
||||
},
|
||||
"workspaces": [
|
||||
"packages/*"
|
||||
],
|
||||
"devDependencies": {
|
||||
"lerna": "^6.4.1"
|
||||
"lerna": "^7.1.4"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ccms/amqp",
|
||||
"version": "0.27.6",
|
||||
"version": "0.28.0-beta.1",
|
||||
"description": "MiaoScript amqp package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
@@ -19,12 +19,12 @@
|
||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ccms/api": "^0.27.6",
|
||||
"@ccms/common": "^0.27.6",
|
||||
"@ccms/container": "^0.27.6"
|
||||
"@ccms/api": "^0.28.0-beta.1",
|
||||
"@ccms/common": "^0.28.0-beta.1",
|
||||
"@ccms/container": "^0.28.0-beta.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@ccms/nashorn": "^0.27.6",
|
||||
"@ccms/nashorn": "^0.28.0-beta.1",
|
||||
"@javatypes/amqp-client": "^0.0.3",
|
||||
"@javatypes/spring-amqp": "^0.0.3",
|
||||
"@javatypes/spring-rabbit": "^0.0.3",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ccms/api",
|
||||
"version": "0.27.6",
|
||||
"version": "0.28.0-beta.1",
|
||||
"description": "MiaoScript api package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
@@ -19,9 +19,9 @@
|
||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ccms/common": "^0.27.6",
|
||||
"@ccms/container": "^0.27.6",
|
||||
"@ccms/polyfill": "^0.27.6",
|
||||
"@ccms/common": "^0.28.0-beta.1",
|
||||
"@ccms/container": "^0.28.0-beta.1",
|
||||
"@ccms/polyfill": "^0.28.0-beta.1",
|
||||
"base64-js": "^1.5.1",
|
||||
"source-map-builder": "^0.0.7"
|
||||
},
|
||||
|
||||
@@ -25,7 +25,7 @@ export namespace event {
|
||||
public EventPriority = EventPriority;
|
||||
|
||||
private mapEvent = [];
|
||||
private listenerMap = [];
|
||||
private pluginEventMap = [];
|
||||
private cacheSlowEventKey = {};
|
||||
|
||||
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"))
|
||||
var name = plugin.description.name
|
||||
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') {
|
||||
ignoreCancel = priority
|
||||
priority = EventPriority.NORMAL
|
||||
@@ -140,16 +140,15 @@ export namespace event {
|
||||
// @ts-ignore
|
||||
let executor = exec.name || exec.executor || '[anonymous]'
|
||||
// noinspection JSUnusedGlobalSymbols
|
||||
var listener = this.register(
|
||||
let listener = this.register(
|
||||
eventCls,
|
||||
this.createExecute(name, exec, eventCls),
|
||||
priority,
|
||||
ignoreCancel
|
||||
)
|
||||
var listenerMap = this.listenerMap
|
||||
// add to cache Be used for close plugin to close event
|
||||
if (!listenerMap[name]) listenerMap[name] = []
|
||||
var off = () => {
|
||||
if (!this.pluginEventMap[name]) this.pluginEventMap[name] = []
|
||||
let off = () => {
|
||||
if (off['offed']) return
|
||||
off['offed'] = true
|
||||
this.unregister(eventCls, listener)
|
||||
@@ -159,7 +158,7 @@ export namespace event {
|
||||
exec: executor
|
||||
}))
|
||||
}
|
||||
listenerMap[name].push(off)
|
||||
this.pluginEventMap[name].push(off)
|
||||
// noinspection JSUnresolvedVariable
|
||||
console.debug(i18n.translate("ms.api.event.register", {
|
||||
name,
|
||||
@@ -176,10 +175,10 @@ export namespace event {
|
||||
* @param plugin 插件
|
||||
*/
|
||||
disable(plugin: any) {
|
||||
var eventCache = this.listenerMap[plugin.description.name]
|
||||
var eventCache = this.pluginEventMap[plugin.description.name]
|
||||
if (eventCache) {
|
||||
eventCache.forEach((off: () => any) => off())
|
||||
delete this.listenerMap[plugin.description.name]
|
||||
delete this.pluginEventMap[plugin.description.name]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ export namespace particle {
|
||||
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 { plugin } from './index'
|
||||
|
||||
const AtomicInteger = Java.type("java.util.concurrent.atomic.AtomicInteger")
|
||||
|
||||
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 isAsync: boolean = false;
|
||||
protected laterTime: number = 0;
|
||||
@@ -88,7 +90,10 @@ export namespace task {
|
||||
protected taskId: number
|
||||
protected innerTask: any
|
||||
|
||||
private cancelled: boolean = false
|
||||
|
||||
constructor(owner: plugin.Plugin, func: Function, id: number) {
|
||||
super()
|
||||
this.owner = owner
|
||||
this.func = func
|
||||
this.taskId = id
|
||||
@@ -134,20 +139,35 @@ export namespace task {
|
||||
*/
|
||||
cancel(): boolean {
|
||||
let result = this.cancel0()
|
||||
process.emit('task.finish', this)
|
||||
this.finish()
|
||||
this.cancelled = true
|
||||
return result
|
||||
}
|
||||
|
||||
protected run(...args: any[]): void {
|
||||
try {
|
||||
this.emit('before', this)
|
||||
if (this.cancelled) { return }
|
||||
this.func(...args)
|
||||
!this.interval && process.emit('task.finish', this)
|
||||
} catch (ex: any) {
|
||||
console.console('§4插件执行任务时发生错误', ex)
|
||||
console.ex(ex)
|
||||
this.emit('after', this)
|
||||
} catch (error: any) {
|
||||
this.emit('error', error)
|
||||
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 任务参数
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ccms/bukkit",
|
||||
"version": "0.27.6",
|
||||
"version": "0.28.0-beta.1",
|
||||
"description": "MiaoScript bukkit package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
@@ -25,8 +25,8 @@
|
||||
"typescript": "^4.9.5"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ccms/api": "^0.27.6",
|
||||
"@ccms/common": "^0.27.6",
|
||||
"@ccms/container": "^0.27.6"
|
||||
"@ccms/api": "^0.28.0-beta.1",
|
||||
"@ccms/common": "^0.28.0-beta.1",
|
||||
"@ccms/container": "^0.28.0-beta.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ccms/bungee",
|
||||
"version": "0.27.6",
|
||||
"version": "0.28.0-beta.1",
|
||||
"description": "MiaoScript bungee package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
@@ -25,8 +25,8 @@
|
||||
"typescript": "^4.9.5"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ccms/api": "^0.27.6",
|
||||
"@ccms/common": "^0.27.6",
|
||||
"@ccms/container": "^0.27.6"
|
||||
"@ccms/api": "^0.28.0-beta.1",
|
||||
"@ccms/common": "^0.28.0-beta.1",
|
||||
"@ccms/container": "^0.28.0-beta.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ccms/common",
|
||||
"version": "0.27.6",
|
||||
"version": "0.28.0-beta.1",
|
||||
"description": "MiaoScript common package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
@@ -19,7 +19,7 @@
|
||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@ccms/nashorn": "^0.27.6",
|
||||
"@ccms/nashorn": "^0.28.0-beta.1",
|
||||
"@javatypes/jdk": "^0.0.3",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rimraf": "^4.1.2",
|
||||
|
||||
@@ -137,7 +137,7 @@ function declaredField(clazz: java.lang.Class<any>, name: string | java.lang.Str
|
||||
} catch (error: any) {
|
||||
if (target === undefined) { break }
|
||||
target = target.getSuperclass()
|
||||
console.debug(`切换到超类: ${target.getName()}`)
|
||||
console.debug(`switch to super class: ${target.getName()}`)
|
||||
}
|
||||
}
|
||||
if (field === null) {
|
||||
@@ -174,7 +174,7 @@ function declaredMethod(clazz: java.lang.Class<any>, nameOrIndex: string | numbe
|
||||
} catch (error) {
|
||||
if (target === undefined) { break }
|
||||
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) {
|
||||
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, {
|
||||
apply: (target, name, args) => { return args ? javaObj[name](args) : javaObj[name]() }
|
||||
})
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ccms/compile",
|
||||
"version": "0.27.6",
|
||||
"version": "0.28.0-beta.1",
|
||||
"description": "MiaoScript compile package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ccms/container",
|
||||
"version": "0.27.6",
|
||||
"version": "0.28.0-beta.1",
|
||||
"description": "MiaoScript container package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
@@ -19,7 +19,7 @@
|
||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@ccms/nashorn": "^0.27.6",
|
||||
"@ccms/nashorn": "^0.28.0-beta.1",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rimraf": "^4.1.2",
|
||||
"typescript": "^4.9.5"
|
||||
|
||||
@@ -154,8 +154,10 @@ export const reduceMetadata = (ctx: interfaces.Context): any => {
|
||||
function initAutowired(container: Container) {
|
||||
container.bind(ioc.Autowired).toDynamicValue((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) }
|
||||
console.warn('container Autowired', metadata.named, 'failed. Error: illegal serviceIdentifier type', key)
|
||||
console.debug(metadata.named, 'metadata', JSON.stringify(metadata))
|
||||
return undefined
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ccms/core",
|
||||
"version": "0.27.6",
|
||||
"version": "0.28.0-beta.1",
|
||||
"description": "MiaoScript core package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
@@ -24,8 +24,8 @@
|
||||
"typescript": "^4.9.5"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ccms/api": "^0.27.6",
|
||||
"@ccms/container": "^0.27.6"
|
||||
"@ccms/api": "^0.28.0-beta.1",
|
||||
"@ccms/container": "^0.28.0-beta.1"
|
||||
},
|
||||
"gitHead": "781524f83e52cad26d7c480513e3c525df867121"
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ccms/database",
|
||||
"version": "0.27.6",
|
||||
"version": "0.28.0-beta.1",
|
||||
"description": "MiaoScript database package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
@@ -25,7 +25,7 @@
|
||||
"typescript": "^4.9.5"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ccms/api": "^0.27.6",
|
||||
"@ccms/container": "^0.27.6"
|
||||
"@ccms/api": "^0.28.0-beta.1",
|
||||
"@ccms/container": "^0.28.0-beta.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ccms/i18n",
|
||||
"version": "0.27.6",
|
||||
"version": "0.28.0-beta.1",
|
||||
"description": "MiaoScript i18n package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
@@ -19,7 +19,7 @@
|
||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@ccms/nashorn": "^0.27.6",
|
||||
"@ccms/nashorn": "^0.28.0-beta.1",
|
||||
"@types/js-yaml": "^4.0.5",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rimraf": "^4.1.2",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ccms/keyvalue",
|
||||
"version": "0.27.6",
|
||||
"version": "0.28.0-beta.1",
|
||||
"description": "MiaoScript keyvalue package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
@@ -19,12 +19,12 @@
|
||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ccms/api": "^0.27.6",
|
||||
"@ccms/common": "^0.27.6",
|
||||
"@ccms/container": "^0.27.6"
|
||||
"@ccms/api": "^0.28.0-beta.1",
|
||||
"@ccms/common": "^0.28.0-beta.1",
|
||||
"@ccms/container": "^0.28.0-beta.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@ccms/nashorn": "^0.27.6",
|
||||
"@ccms/nashorn": "^0.28.0-beta.1",
|
||||
"@javatypes/amqp-client": "^0.0.3",
|
||||
"@javatypes/spring-amqp": "^0.0.3",
|
||||
"@javatypes/spring-rabbit": "^0.0.3",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ccms/molang",
|
||||
"version": "0.27.6",
|
||||
"version": "0.28.0-beta.1",
|
||||
"description": "A fast parser for Minecraft's MoLang",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ccms/nashorn",
|
||||
"version": "0.27.6",
|
||||
"version": "0.28.0-beta.1",
|
||||
"description": "MiaoScript nashorn package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ccms/nodejs",
|
||||
"version": "0.27.6",
|
||||
"version": "0.28.0-beta.1",
|
||||
"description": "MiaoScript nodejs package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
@@ -19,7 +19,7 @@
|
||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@ccms/nashorn": "^0.27.6",
|
||||
"@ccms/nashorn": "^0.28.0-beta.1",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rimraf": "^4.1.2",
|
||||
"tslib": "^2.5.0",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ccms/nukkit",
|
||||
"version": "0.27.6",
|
||||
"version": "0.28.0-beta.1",
|
||||
"description": "MiaoScript nukkit package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
@@ -25,8 +25,8 @@
|
||||
"typescript": "^4.9.5"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ccms/api": "^0.27.6",
|
||||
"@ccms/common": "^0.27.6",
|
||||
"@ccms/container": "^0.27.6"
|
||||
"@ccms/api": "^0.28.0-beta.1",
|
||||
"@ccms/common": "^0.28.0-beta.1",
|
||||
"@ccms/container": "^0.28.0-beta.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ccms/plugin",
|
||||
"version": "0.27.6",
|
||||
"version": "0.28.0-beta.1",
|
||||
"description": "MiaoScript plugin package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
@@ -26,10 +26,10 @@
|
||||
"typescript": "^4.9.5"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ccms/api": "^0.27.6",
|
||||
"@ccms/common": "^0.27.6",
|
||||
"@ccms/container": "^0.27.6",
|
||||
"@ccms/i18n": "^0.27.6",
|
||||
"@ccms/api": "^0.28.0-beta.1",
|
||||
"@ccms/common": "^0.28.0-beta.1",
|
||||
"@ccms/container": "^0.28.0-beta.1",
|
||||
"@ccms/i18n": "^0.28.0-beta.1",
|
||||
"@ccms/verify": "^0.25.1",
|
||||
"crypto-js": "^4.1.1",
|
||||
"js-yaml": "^4.1.0"
|
||||
|
||||
@@ -15,51 +15,51 @@ export class PluginCommandManager {
|
||||
process.on('plugin.after.disable', this.unregistryCommand.bind(this))
|
||||
}
|
||||
|
||||
private registryCommand(pluginInstance: plugin.Plugin) {
|
||||
let cmds = getPluginCommandMetadata(pluginInstance)
|
||||
let tabs = getPluginTabCompleterMetadata(pluginInstance)
|
||||
public registryCommand(pluginInstance: plugin.Plugin, executor: any = pluginInstance) {
|
||||
let cmds = getPluginCommandMetadata(executor)
|
||||
let tabs = getPluginTabCompleterMetadata(executor)
|
||||
for (const cmd of cmds) {
|
||||
if (!this.ServerChecker.check(cmd.servers)) {
|
||||
console.debug(`[${pluginInstance.description.name}] ${cmd.target.constructor.name} incompatible command ${cmd.name} server(${cmd.servers}) ignore.`)
|
||||
continue
|
||||
}
|
||||
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, {
|
||||
cmd: cmdExecutor.bind(pluginInstance),
|
||||
tab: cmdCompleter?.bind(pluginInstance)
|
||||
cmd: cmdExecutor.bind(executor),
|
||||
tab: cmdCompleter?.bind(executor)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private unregistryCommand(pluginInstance: plugin.Plugin) {
|
||||
let cmds = getPluginCommandMetadata(pluginInstance)
|
||||
public unregistryCommand(pluginInstance: plugin.Plugin, executor: any = pluginInstance) {
|
||||
let cmds = getPluginCommandMetadata(executor)
|
||||
for (const cmd of cmds) {
|
||||
if (!this.ServerChecker.check(cmd.servers)) {
|
||||
console.debug(`[${pluginInstance.description.name}] ${cmd.target.constructor.name} incompatible command ${cmd.name} server(${cmd.servers}) ignore.`)
|
||||
continue
|
||||
}
|
||||
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) {
|
||||
let cmdExecutor = pluginInstance[cmd.executor]
|
||||
let cmdCompleter = tab ? pluginInstance[tab.executor] : undefined
|
||||
let cmdSubCache = Object.keys(pluginInstance.constructor.prototype).filter(s => s.startsWith('cmd')).map(s => s.substring(3))
|
||||
private generateAutoMainCommand(pluginInstance: plugin.Plugin, executor: any, cmd: interfaces.CommandMetadata, tab: interfaces.CommandMetadata) {
|
||||
let cmdExecutor = executor[cmd.executor]
|
||||
let cmdCompleter = tab ? executor[tab.executor] : undefined
|
||||
let cmdSubCache = Object.keys(executor.constructor.prototype).filter(s => s.startsWith('cmd')).map(s => s.substring(3))
|
||||
if (cmd.autoMain) {
|
||||
cmdExecutor = (sender: any, command: string, args: string[]) => {
|
||||
let subcommand = args[0]
|
||||
let cmdKey = 'cmd' + 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}`)
|
||||
pluginInstance.logger.sender(
|
||||
sender,
|
||||
pluginInstance['cmdhelp'] ?
|
||||
executor['cmdhelp'] ?
|
||||
`§6请执行 §b/${command} §ahelp §6查看帮助!` :
|
||||
[
|
||||
`§6插件: §b${pluginInstance.description.name}`,
|
||||
@@ -69,7 +69,7 @@ export class PluginCommandManager {
|
||||
}
|
||||
return
|
||||
}
|
||||
let subcommandexec = pluginInstance[cmdKey]
|
||||
let subcommandexec = executor[cmdKey]
|
||||
let permission: string
|
||||
if (cmd.permission && sender.hasPermission) {
|
||||
if (typeof cmd.permission == "string") {
|
||||
@@ -82,7 +82,7 @@ export class PluginCommandManager {
|
||||
}
|
||||
}
|
||||
args.shift()
|
||||
return subcommandexec.apply(pluginInstance, [sender, ...args])
|
||||
return subcommandexec.apply(executor, [sender, ...args])
|
||||
}
|
||||
let originCompleter = cmdCompleter
|
||||
cmdCompleter = (sender: any, command: string, args: string[]) => {
|
||||
@@ -95,7 +95,7 @@ export class PluginCommandManager {
|
||||
}
|
||||
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`) }
|
||||
|
||||
@@ -11,6 +11,8 @@ export class PluginEventManager {
|
||||
@Autowired()
|
||||
private nativePluginChecker: server.NativePluginChecker
|
||||
|
||||
private listenerMap = [];
|
||||
|
||||
constructor() {
|
||||
process.on('plugin.before.enable', this.registryListener.bind(this))
|
||||
process.on('plugin.after.disable', this.unregistryListener.bind(this))
|
||||
@@ -20,8 +22,9 @@ export class PluginEventManager {
|
||||
return this.eventManager.mapEventName().toFixed(0)
|
||||
}
|
||||
|
||||
private registryListener(pluginInstance: plugin.Plugin) {
|
||||
let events = getPluginListenerMetadata(pluginInstance)
|
||||
public registryListener(pluginInstance: plugin.Plugin, listener: any = pluginInstance) {
|
||||
let events = getPluginListenerMetadata(listener)
|
||||
let execes = []
|
||||
for (const event of events) {
|
||||
// ignore space listener
|
||||
if (!this.serverChecker.check(event.servers)) {
|
||||
@@ -35,13 +38,25 @@ export class PluginEventManager {
|
||||
}
|
||||
// here must bind this to pluginInstance
|
||||
let exec = event.target[event.executor]
|
||||
let execBinded = exec.bind(pluginInstance)
|
||||
let execBinded = exec.bind(listener)
|
||||
execBinded.executor = event.executor
|
||||
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) {
|
||||
this.eventManager.disable(pluginInstance)
|
||||
private unregistryListener(pluginInstance: plugin.Plugin, listener: any = 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 './interfaces'
|
||||
|
||||
export * from './event'
|
||||
export * from './command'
|
||||
|
||||
export {
|
||||
plugin as JSPlugin,
|
||||
cmd as Cmd,
|
||||
|
||||
@@ -8,7 +8,7 @@ export namespace interfaces {
|
||||
@injectable()
|
||||
export abstract class Plugin implements plugin.Plugin {
|
||||
public description: plugin.PluginMetadata
|
||||
public logger: Console
|
||||
public logger: MiaoScriptConsole
|
||||
@inject(server.Console)
|
||||
private Console: MiaoScriptConsole
|
||||
|
||||
@@ -28,6 +28,11 @@ export namespace interfaces {
|
||||
return dataFolder.getAbsolutePath()
|
||||
}
|
||||
|
||||
public registryCommand(executor: any) { }
|
||||
public unregistryCommand(executor: any) { }
|
||||
public registryListener(listener: any) { }
|
||||
public unregistryListener(listener: any) { }
|
||||
|
||||
public load() { }
|
||||
public enable() { }
|
||||
public disable() { }
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ccms/polyfill",
|
||||
"version": "0.27.6",
|
||||
"version": "0.28.0-beta.1",
|
||||
"description": "MiaoScript polyfill package",
|
||||
"author": "MiaoWoo <admin@yumc.pw>",
|
||||
"homepage": "https://github.com/circlecloud/ms.git",
|
||||
@@ -14,12 +14,12 @@
|
||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ccms/i18n": "^0.27.6",
|
||||
"@ccms/nodejs": "^0.27.6",
|
||||
"@ccms/i18n": "^0.28.0-beta.1",
|
||||
"@ccms/nodejs": "^0.28.0-beta.1",
|
||||
"core-js": "^3.27.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@ccms/nashorn": "^0.27.6",
|
||||
"@ccms/nashorn": "^0.28.0-beta.1",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rimraf": "^4.1.2",
|
||||
"typescript": "^4.9.5"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ccms/protocol",
|
||||
"version": "0.27.6",
|
||||
"version": "0.28.0-beta.1",
|
||||
"description": "MiaoScript protocol package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ccms/qrcode",
|
||||
"version": "0.27.6",
|
||||
"version": "0.28.0-beta.1",
|
||||
"description": "MiaoScript qrcode package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ccms/sponge",
|
||||
"version": "0.27.6",
|
||||
"version": "0.28.0-beta.1",
|
||||
"description": "MiaoScript sponge package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
@@ -25,8 +25,8 @@
|
||||
"typescript": "^4.9.5"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ccms/api": "^0.27.6",
|
||||
"@ccms/common": "^0.27.6",
|
||||
"@ccms/container": "^0.27.6"
|
||||
"@ccms/api": "^0.28.0-beta.1",
|
||||
"@ccms/common": "^0.28.0-beta.1",
|
||||
"@ccms/container": "^0.28.0-beta.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ccms/spring",
|
||||
"version": "0.27.6",
|
||||
"version": "0.28.0-beta.1",
|
||||
"description": "MiaoScript spring package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
@@ -24,9 +24,9 @@
|
||||
"typescript": "^4.9.5"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ccms/api": "^0.27.6",
|
||||
"@ccms/common": "^0.27.6",
|
||||
"@ccms/container": "^0.27.6",
|
||||
"@ccms/database": "^0.27.6"
|
||||
"@ccms/api": "^0.28.0-beta.1",
|
||||
"@ccms/common": "^0.28.0-beta.1",
|
||||
"@ccms/container": "^0.28.0-beta.1",
|
||||
"@ccms/database": "^0.28.0-beta.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ccms/web",
|
||||
"version": "0.27.6",
|
||||
"version": "0.28.0-beta.1",
|
||||
"description": "MiaoScript web package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
@@ -29,7 +29,7 @@
|
||||
"typescript": "^4.9.5"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ccms/api": "^0.27.6",
|
||||
"@ccms/container": "^0.27.6"
|
||||
"@ccms/api": "^0.28.0-beta.1",
|
||||
"@ccms/container": "^0.28.0-beta.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ccms/websocket",
|
||||
"version": "0.27.6",
|
||||
"version": "0.28.0-beta.1",
|
||||
"description": "MiaoScript websocket package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
@@ -24,7 +24,7 @@
|
||||
"parseuri": "^0.0.6"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@ccms/nashorn": "^0.27.6",
|
||||
"@ccms/nashorn": "^0.28.0-beta.1",
|
||||
"@javatypes/tomcat-websocket-api": "^0.0.3",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rimraf": "^4.1.2",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
import { EventEmitter } from 'events'
|
||||
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 {
|
||||
private clients = new Map<string, WebSocket>()
|
||||
@@ -18,7 +18,9 @@ export class WebSocketManager {
|
||||
add(client: WebSocket) {
|
||||
this.clients.set(client.id, client)
|
||||
}
|
||||
|
||||
del(client: WebSocket) {
|
||||
client.removeAllListeners()
|
||||
this.clients.delete(client.id)
|
||||
}
|
||||
}
|
||||
@@ -52,16 +54,7 @@ export class WebSocket extends EventEmitter {
|
||||
console.ex(error)
|
||||
return
|
||||
}
|
||||
this.client.on('open', (event) => {
|
||||
this.onopen?.(event)
|
||||
manager.add(this)
|
||||
})
|
||||
this.client.on('message', (event) => this.onmessage?.(event))
|
||||
this.client.on('close', (event) => {
|
||||
this.onclose?.(event)
|
||||
manager.del(this)
|
||||
})
|
||||
this.client.on('error', (event) => this.onerror?.(event))
|
||||
manager.add(this)
|
||||
setTimeout(() => this.client.connect(), 20)
|
||||
}
|
||||
get id() {
|
||||
@@ -82,21 +75,25 @@ export class WebSocket extends EventEmitter {
|
||||
get url() {
|
||||
return this._url
|
||||
}
|
||||
public onopen: (event: Event) => void
|
||||
public onmessage: (event: MessageEvent) => void
|
||||
public onclose: (event: CloseEvent) => void
|
||||
public onerror: (event: ErrorEvent) => void
|
||||
|
||||
addEventListener(event: EventType, callback: () => void) {
|
||||
this[`on${event.toLowerCase()}`] = callback
|
||||
this.client.on(event, callback)
|
||||
set onopen(func: (event: Event) => void) {
|
||||
this.client.on(ClientEvent.open, func)
|
||||
}
|
||||
set onmessage(func: (event: MessageEvent) => void) {
|
||||
this.client.on(ClientEvent.message, func)
|
||||
}
|
||||
set onclose(func: (event: CloseEvent) => void) {
|
||||
this.client.on(ClientEvent.close, func)
|
||||
manager.del(this)
|
||||
}
|
||||
set onerror(func: (event: ErrorEvent) => void) {
|
||||
this.client.on(ClientEvent.error, func)
|
||||
}
|
||||
public send(data: any) {
|
||||
this.client.send(data)
|
||||
}
|
||||
public close(code?: number, reason?: string) {
|
||||
this.client.close(code, reason)
|
||||
this.removeAllListeners()
|
||||
manager.del(this)
|
||||
}
|
||||
}
|
||||
global.setGlobal('WebSocket', WebSocket)
|
||||
|
||||
@@ -4,10 +4,18 @@ export interface WebSocketHeader {
|
||||
}
|
||||
|
||||
export type EventType =
|
||||
| 'close'
|
||||
| 'error'
|
||||
| 'message'
|
||||
| 'open'
|
||||
| ClientEvent.open
|
||||
| ClientEvent.message
|
||||
| ClientEvent.close
|
||||
| ClientEvent.error
|
||||
|
||||
export enum ClientEvent {
|
||||
open = 'open',
|
||||
message = 'message',
|
||||
close = 'close',
|
||||
error = 'error',
|
||||
}
|
||||
|
||||
export interface Event {
|
||||
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ export class WebSocketClientHandler extends WebSocketClientHandlerAdapter {
|
||||
return true
|
||||
}
|
||||
handlerAdded(ctx: any) {
|
||||
console.debug(`${ctx} handlerAdded`)
|
||||
if (ctx.newPromise) {
|
||||
this.handshakeFuture = ctx.newPromise()
|
||||
} else {
|
||||
@@ -28,15 +27,14 @@ export class WebSocketClientHandler extends WebSocketClientHandlerAdapter {
|
||||
}
|
||||
}
|
||||
channelActive(ctx: any) {
|
||||
console.debug(`${ctx} channelActive`)
|
||||
this.handshaker.handshake(ctx.channel())
|
||||
}
|
||||
channelInactive(ctx: any) {
|
||||
console.debug(`${ctx} channelInactive`)
|
||||
this.client.onclose({ code: 0, reason: 'client connection channel inactive!' })
|
||||
if (this.client.readyStatus != WebSocket.CLOSED) {
|
||||
this.client.onclose({ code: 1006, reason: 'client connection channel inactive.' })
|
||||
}
|
||||
}
|
||||
channelRead0(ctx: any, msg: any) {
|
||||
console.trace(`${ctx} channelRead0 ${msg}`)
|
||||
let ch = ctx.channel()
|
||||
if (!this.handshaker.isHandshakeComplete()) {
|
||||
// web socket client connected
|
||||
@@ -54,7 +52,7 @@ export class WebSocketClientHandler extends WebSocketClientHandlerAdapter {
|
||||
if (frame instanceof TextWebSocketFrame) {
|
||||
this.client.onmessage({ data: frame.text() })
|
||||
} else if (frame instanceof CloseWebSocketFrame) {
|
||||
this.client.onclose({ code: 0, reason: 'server close connection!' })
|
||||
this.client.close(1000, 'server close connection.')
|
||||
}
|
||||
}
|
||||
exceptionCaught(ctx: any, cause: Error) {
|
||||
|
||||
@@ -85,10 +85,7 @@ export class NettyWebSocket extends Transport {
|
||||
console.debug(`constructor NettyWebSocket url: ${url} scheme: ${this._schema} host: ${this._host} port: ${this._port} header: ${JSON.stringify(headers)}`)
|
||||
}
|
||||
getId() {
|
||||
if (this.channel?.id) {
|
||||
return this.channel?.id() + ''
|
||||
}
|
||||
return 'NettyWebSocket#' + channelCount.incrementAndGet()
|
||||
return `${this.channel?.id()}` || `NettyWebSocket#${channelCount.incrementAndGet()}`
|
||||
}
|
||||
doConnect() {
|
||||
console.debug('client NettyWebSocket doConnect', this._url)
|
||||
@@ -147,8 +144,9 @@ export class NettyWebSocket extends Transport {
|
||||
}
|
||||
doClose(code: number, reason: string) {
|
||||
this.channel.writeAndFlush(new CloseWebSocketFrame())
|
||||
this.channel.close()
|
||||
this.channel.closeFuture().addListener(new ChannelFutureListener(() => console.debug(`NettyWebSocket close code: ${code} reason: ${reason}`)))
|
||||
this.channel.closeFuture().addListener(new ChannelFutureListener(() => {
|
||||
this.onclose({ code, reason })
|
||||
}))
|
||||
}
|
||||
getChannel() {
|
||||
return this.channel
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { EventEmitter } from 'events'
|
||||
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 {
|
||||
protected _url: string
|
||||
@@ -32,7 +32,6 @@ export abstract class Transport extends EventEmitter {
|
||||
}
|
||||
|
||||
connect() {
|
||||
console.debug(`client Transport connect`)
|
||||
try {
|
||||
this.doConnect()
|
||||
} catch (error: any) {
|
||||
@@ -49,19 +48,16 @@ export abstract class Transport extends EventEmitter {
|
||||
}
|
||||
}
|
||||
|
||||
close(code: number = 0, reason: string = '') {
|
||||
if (this.readyStatus != WebSocket.CLOSING && this.readyStatus != WebSocket.CLOSED) {
|
||||
close(code: number = 1000, reason: string = '') {
|
||||
if (this.readyStatus < WebSocket.CLOSING) {
|
||||
this.readyStatus = WebSocket.CLOSING
|
||||
try {
|
||||
this.onclose({ code, reason })
|
||||
this.doClose(code, reason)
|
||||
} catch (error: any) {
|
||||
this.onerror({ error })
|
||||
} finally {
|
||||
this.removeAllListeners()
|
||||
}
|
||||
} else {
|
||||
console.debug(`${this.id} call close but state is ${this.readyStatus}`)
|
||||
console.debug(`WebSocket Transport ${this.id} call close code ${code} reason ${reason} but state is ${this.readyStatus}`)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,31 +69,31 @@ export abstract class Transport extends EventEmitter {
|
||||
onconnect(event: Event) {
|
||||
if (this.readyStatus != WebSocket.OPEN) {
|
||||
this.readyStatus = WebSocket.OPEN
|
||||
this.emit('open', event)
|
||||
this.emit(ClientEvent.open, event)
|
||||
} else {
|
||||
console.debug(`${this.id} call onconnect but state is ${this.readyStatus}`)
|
||||
console.debug(`WebSocket Transport ${this.id} call onconnect but state is ${this.readyStatus}`)
|
||||
}
|
||||
}
|
||||
|
||||
onmessage(event: MessageEvent) {
|
||||
this.emit('message', event)
|
||||
this.emit(ClientEvent.message, event)
|
||||
}
|
||||
|
||||
onerror(event: ErrorEvent) {
|
||||
this.emit('error', event)
|
||||
this.emit(ClientEvent.error, event)
|
||||
}
|
||||
|
||||
onclose(event: CloseEvent) {
|
||||
if (this.readyStatus != WebSocket.CLOSED) {
|
||||
this.readyStatus = WebSocket.CLOSED
|
||||
this.emit('close', event)
|
||||
this.removeAllListeners()
|
||||
this.emit(ClientEvent.close, event)
|
||||
} 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.readyStatus} CloseEvent[code: ${event.code}, reason: ${event.reason}]`)
|
||||
}
|
||||
}
|
||||
abstract getId()
|
||||
abstract doConnect()
|
||||
abstract doSend(text: string)
|
||||
abstract doClose(code: number, reason: string)
|
||||
|
||||
abstract getId(): string
|
||||
abstract doConnect(): void
|
||||
abstract doSend(text: string): void
|
||||
abstract doClose(code: number, reason: string): void
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/// <reference types="@ccms/nashorn" />
|
||||
/// <reference types="@javatypes/tomcat-websocket-api" />
|
||||
|
||||
import * as server from './server'
|
||||
import { WebSocketServer } from './server'
|
||||
import { Server, ServerOptions } from './socket.io'
|
||||
|
||||
interface SocketIOStatic {
|
||||
@@ -45,7 +45,7 @@ let singletonServer: Server
|
||||
let io: SocketStatic = function io(pipeline: any, options: Partial<JavaServerOptions>, singleton = true) {
|
||||
if (singleton) {
|
||||
if (!singletonServer) {
|
||||
singletonServer = new Server(server.attach(pipeline, options), options)
|
||||
singletonServer = new Server(WebSocketServer.attach(pipeline, options), options)
|
||||
process.emit('websocket.create', singletonServer)
|
||||
process.on('exit', () => {
|
||||
singletonServer.close()
|
||||
@@ -53,7 +53,7 @@ let io: SocketStatic = function io(pipeline: any, options: Partial<JavaServerOpt
|
||||
}
|
||||
return singletonServer
|
||||
}
|
||||
return new Server(server.attach(pipeline, options), options)
|
||||
return new Server(WebSocketServer.attach(pipeline, options), options)
|
||||
}
|
||||
io.Instance = Symbol("@ccms/websocket")
|
||||
export default io
|
||||
|
||||
@@ -26,6 +26,24 @@ export abstract class WebSocketServer extends EventEmitter {
|
||||
protected instance: any
|
||||
protected options: JavaServerOptions
|
||||
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) {
|
||||
super()
|
||||
this.instance = instance
|
||||
@@ -69,20 +87,3 @@ export abstract class WebSocketServer extends EventEmitter {
|
||||
protected abstract getSocket(handler: any): WebSocketClient
|
||||
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
|
||||
echo $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
|
||||
done
|
||||
|
||||
1
script/sync.sh
Normal file → Executable file
1
script/sync.sh
Normal file → Executable file
@@ -1,3 +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