floating-live 0.15.0-beta.4 → 0.15.0-beta.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node" />
2
2
  import { EventEmitter } from "events";
3
- import { RoomStatus } from "../enums";
3
+ import { ConnectStatus, RoomStatus } from "../enums";
4
4
  import { RoomDetail, RoomInfo, RoomStatsInfo } from "../types";
5
5
  import { Message, UserInfo } from "../types/message";
6
6
  export declare abstract class LiveRoom extends EventEmitter implements RoomInfo {
@@ -22,11 +22,11 @@ export declare abstract class LiveRoom extends EventEmitter implements RoomInfo
22
22
  /** 当前直播id */
23
23
  liveId?: string;
24
24
  /** 房间是否打开 */
25
- opened: boolean;
25
+ get opened(): boolean;
26
+ /** 是否连接上房间 */
27
+ connection: ConnectStatus;
26
28
  /** 房间是否可用 */
27
29
  abstract available: boolean;
28
- /** 是否连接上房间 */
29
- abstract connected: boolean;
30
30
  /** 打开连接 */
31
31
  abstract open(): void;
32
32
  /** 关闭连接 */
@@ -34,7 +34,7 @@ export declare abstract class LiveRoom extends EventEmitter implements RoomInfo
34
34
  /** 从服务器获取信息 */
35
35
  abstract getInfo(): Promise<void>;
36
36
  /** 销毁事件 */
37
- protected onDestory?(): void;
37
+ protected onDestroy?(): void;
38
38
  /** 销毁 */
39
39
  destroy(): void;
40
40
  protected emitMsg(msg: Message.All): void;
@@ -10,14 +10,18 @@ class LiveRoom extends events_1.EventEmitter {
10
10
  this.status = enums_1.RoomStatus.off;
11
11
  /** 时间戳 */
12
12
  this.timestamp = 0;
13
- /** 房间是否打开 */
14
- this.opened = false;
13
+ /** 是否连接上房间 */
14
+ this.connection = enums_1.ConnectStatus.off;
15
+ }
16
+ /** 房间是否打开 */
17
+ get opened() {
18
+ return !!this.connection;
15
19
  }
16
20
  /** 销毁 */
17
21
  destroy() {
18
22
  this.close();
19
23
  this.removeAllListeners();
20
- this.onDestory?.();
24
+ this.onDestroy?.();
21
25
  }
22
26
  // 发送消息
23
27
  emitMsg(msg) {
@@ -42,9 +46,9 @@ class LiveRoom extends events_1.EventEmitter {
42
46
  break;
43
47
  case "live_end":
44
48
  case "live_cut":
45
- this.emit("msg", msg);
46
49
  this.status = msg.status || enums_1.RoomStatus.off;
47
50
  this.timestamp = msg.timestamp;
51
+ this.emit("msg", msg);
48
52
  this.emit("status", msg.status || enums_1.RoomStatus.off, {
49
53
  timestamp: msg.timestamp,
50
54
  });
@@ -68,7 +72,7 @@ class LiveRoom extends events_1.EventEmitter {
68
72
  liveId: this.liveId,
69
73
  available: this.available,
70
74
  opened: this.opened,
71
- connected: this.connected,
75
+ connection: this.connection,
72
76
  key: this.key,
73
77
  };
74
78
  }
package/dist/enums.d.ts CHANGED
@@ -11,6 +11,19 @@ export declare enum RoomStatus {
11
11
  /** 已上锁 */
12
12
  locked = -2
13
13
  }
14
+ /** 直播间状态 */
15
+ export declare enum ConnectStatus {
16
+ /** 未连接 */
17
+ off = 0,
18
+ /** 连接中 */
19
+ connecting = 1,
20
+ /** 连接到服务器 */
21
+ connected = 2,
22
+ /** 连接到房间 */
23
+ entered = 3,
24
+ /** 连接失败或断开 */
25
+ disconnected = -1
26
+ }
14
27
  /** 图片大小 */
15
28
  export declare enum ImageSize {
16
29
  /** 自定义大小 */
package/dist/enums.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.UserType = exports.DanmakuMode = exports.ImageSize = exports.RoomStatus = void 0;
3
+ exports.UserType = exports.DanmakuMode = exports.ImageSize = exports.ConnectStatus = exports.RoomStatus = void 0;
4
4
  /** 直播间状态 */
5
5
  var RoomStatus;
6
6
  (function (RoomStatus) {
@@ -15,6 +15,20 @@ var RoomStatus;
15
15
  /** 已上锁 */
16
16
  RoomStatus[RoomStatus["locked"] = -2] = "locked";
17
17
  })(RoomStatus = exports.RoomStatus || (exports.RoomStatus = {}));
18
+ /** 直播间状态 */
19
+ var ConnectStatus;
20
+ (function (ConnectStatus) {
21
+ /** 未连接 */
22
+ ConnectStatus[ConnectStatus["off"] = 0] = "off";
23
+ /** 连接中 */
24
+ ConnectStatus[ConnectStatus["connecting"] = 1] = "connecting";
25
+ /** 连接到服务器 */
26
+ ConnectStatus[ConnectStatus["connected"] = 2] = "connected";
27
+ /** 连接到房间 */
28
+ ConnectStatus[ConnectStatus["entered"] = 3] = "entered";
29
+ /** 连接失败或断开 */
30
+ ConnectStatus[ConnectStatus["disconnected"] = -1] = "disconnected";
31
+ })(ConnectStatus = exports.ConnectStatus || (exports.ConnectStatus = {}));
18
32
  /** 图片大小 */
19
33
  var ImageSize;
20
34
  (function (ImageSize) {
package/dist/live.d.ts CHANGED
@@ -2,9 +2,9 @@
2
2
  import { EventEmitter } from "events";
3
3
  import { ModPlugin } from "./module/plugin";
4
4
  import { ModRoom } from "./module/room";
5
- import { ModStore } from "./module/store";
6
- import ModCommand from "./module/command";
7
- import { ModValues } from "./module/values";
5
+ import { ModManifest } from "./module/manifest";
6
+ import { ModCommand } from "./module/command";
7
+ import { ModValue } from "./module/value";
8
8
  import { ModHook } from "./module/hook";
9
9
  import { FloatingEventMap } from "./types/events";
10
10
  import { FloatingCommandMap } from "./types";
@@ -15,10 +15,10 @@ export declare class FloatingLive extends EventEmitter {
15
15
  plugin: ModPlugin;
16
16
  /** 命令模块 */
17
17
  command: ModCommand;
18
- /** 状态模块 */
19
- store: ModStore;
18
+ /** Manifest模块 */
19
+ manifest: ModManifest;
20
20
  /** 数值模块 */
21
- values: ModValues;
21
+ value: ModValue;
22
22
  /** 钩子模块 */
23
23
  hook: ModHook;
24
24
  constructor();
@@ -26,10 +26,10 @@ export declare class FloatingLive extends EventEmitter {
26
26
  on<T extends keyof FloatingEventMap>(eventName: T, listener: FloatingEventMap[T]): this;
27
27
  emit<T extends keyof FloatingEventMap>(eventName: T, ...args: Parameters<FloatingEventMap[T]>): boolean;
28
28
  throw(err: Error): void;
29
- snapshot(): {
29
+ getSnapshot(): {
30
30
  room: import("./types").RoomInfo[];
31
- values: Record<string, any>;
32
- store: Record<string, Record<string, any>>;
31
+ value: Record<string, any>;
32
+ manifest: Record<string, Record<string, any>>;
33
33
  command: string[];
34
34
  };
35
35
  }
package/dist/live.js CHANGED
@@ -1,24 +1,21 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.FloatingLive = void 0;
7
4
  const events_1 = require("events");
8
5
  const plugin_1 = require("./module/plugin");
9
6
  const room_1 = require("./module/room");
10
- const store_1 = require("./module/store");
11
- const command_1 = __importDefault(require("./module/command"));
12
- const values_1 = require("./module/values");
7
+ const manifest_1 = require("./module/manifest");
8
+ const command_1 = require("./module/command");
9
+ const value_1 = require("./module/value");
13
10
  const hook_1 = require("./module/hook");
14
11
  class FloatingLive extends events_1.EventEmitter {
15
12
  constructor() {
16
13
  super();
17
- this.command = new command_1.default(this);
18
- this.store = new store_1.ModStore(this);
14
+ this.command = new command_1.ModCommand(this);
15
+ this.manifest = new manifest_1.ModManifest(this);
19
16
  this.plugin = new plugin_1.ModPlugin(this);
20
17
  this.room = new room_1.ModRoom(this);
21
- this.values = new values_1.ModValues(this);
18
+ this.value = new value_1.ModValue(this);
22
19
  this.hook = new hook_1.ModHook(this);
23
20
  }
24
21
  call(name, ...args) {
@@ -33,12 +30,12 @@ class FloatingLive extends events_1.EventEmitter {
33
30
  throw(err) {
34
31
  this.emit("error", err);
35
32
  }
36
- snapshot() {
33
+ getSnapshot() {
37
34
  return {
38
- room: this.room.snapshot(),
39
- values: this.values.snapshot(),
40
- store: this.store.snapshot(),
41
- command: this.command.snapshot(),
35
+ room: this.room.getSnapshot(),
36
+ value: this.value.getSnapshot(),
37
+ manifest: this.manifest.getSnapshot(),
38
+ command: this.command.getSnapshot(),
42
39
  };
43
40
  }
44
41
  }
@@ -1,6 +1,6 @@
1
1
  import { FloatingLive } from "../live";
2
2
  import { FloatingCommandMap } from "../types";
3
- export default class ModCommand {
3
+ export declare class ModCommand {
4
4
  /** 功能列表 */
5
5
  private readonly list;
6
6
  protected readonly main: FloatingLive;
@@ -12,5 +12,5 @@ export default class ModCommand {
12
12
  /** 调用命令 */
13
13
  call<T extends keyof FloatingCommandMap>(name: T, ...args: Parameters<FloatingCommandMap[T]>): any;
14
14
  /** 获取快照 */
15
- snapshot(): string[];
15
+ getSnapshot(): string[];
16
16
  }
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ModCommand = void 0;
3
4
  class ModCommand {
4
5
  constructor(main) {
5
6
  /** 功能列表 */
@@ -21,8 +22,8 @@ class ModCommand {
21
22
  return this.list.get(name)?.(...args);
22
23
  }
23
24
  /** 获取快照 */
24
- snapshot() {
25
+ getSnapshot() {
25
26
  return [...this.list].map(([key]) => key);
26
27
  }
27
28
  }
28
- exports.default = ModCommand;
29
+ exports.ModCommand = ModCommand;
@@ -0,0 +1,15 @@
1
+ import { FloatingLive } from "../live";
2
+ import { FloatingManifestMap } from "../types/manifest";
3
+ export declare class ModManifest {
4
+ private list;
5
+ protected readonly main: FloatingLive;
6
+ constructor(main: FloatingLive);
7
+ /** 注册manifest */
8
+ register<T extends keyof FloatingManifestMap>(name: T, id: string, value: FloatingManifestMap[T]): void;
9
+ /** 取消注册manifest */
10
+ unregister<T extends keyof FloatingManifestMap>(name: T, id: string): void;
11
+ /** 获取值 */
12
+ get(name: string): Map<string, any> | undefined;
13
+ /** 获取快照 */
14
+ getSnapshot(): Record<string, Record<string, any>>;
15
+ }
@@ -1,12 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ModStore = void 0;
4
- class ModStore {
3
+ exports.ModManifest = void 0;
4
+ class ModManifest {
5
5
  constructor(main) {
6
6
  this.list = new Map();
7
7
  this.main = main;
8
8
  }
9
- /** 注册store */
9
+ /** 注册manifest */
10
10
  register(name, id, value) {
11
11
  let store = this.list.get(name);
12
12
  if (!store) {
@@ -14,14 +14,14 @@ class ModStore {
14
14
  this.list.set(name, store);
15
15
  }
16
16
  store.set(id, value);
17
- this.main.emit("store:add", name, id, value);
17
+ this.main.emit("manifest:add", name, id, value);
18
18
  }
19
- /** 取消注册store */
19
+ /** 取消注册manifest */
20
20
  unregister(name, id) {
21
21
  let store = this.list.get(name);
22
22
  if (store) {
23
23
  store.delete(id);
24
- this.main.emit("store:remove", name, id);
24
+ this.main.emit("manifest:remove", name, id);
25
25
  }
26
26
  }
27
27
  /** 获取值 */
@@ -29,7 +29,7 @@ class ModStore {
29
29
  return this.list.get(name);
30
30
  }
31
31
  /** 获取快照 */
32
- snapshot() {
32
+ getSnapshot() {
33
33
  const map = {};
34
34
  this.list.forEach((store, name) => {
35
35
  const part = {};
@@ -41,4 +41,4 @@ class ModStore {
41
41
  return map;
42
42
  }
43
43
  }
44
- exports.ModStore = ModStore;
44
+ exports.ModManifest = ModManifest;
@@ -27,5 +27,5 @@ export declare class ModRoom {
27
27
  /** 更改某个房间的顺序 */
28
28
  move(roomKey: string, position: number): void;
29
29
  /** 获取快照 */
30
- snapshot(): RoomInfo[];
30
+ getSnapshot(): RoomInfo[];
31
31
  }
@@ -35,14 +35,18 @@ class ModRoom {
35
35
  room.on("raw", (data, { platform, room }) => {
36
36
  this.main.emit("live:raw", data, { platform, room });
37
37
  });
38
- // 连接到直播间
38
+ // 连接到服务器
39
39
  room.on("connect", () => {
40
40
  this.main.emit("room:connect", key);
41
41
  });
42
- // 与直播间的连接已断开
42
+ // 与服务器的连接已断开
43
43
  room.on("disconnect", () => {
44
44
  this.main.emit("room:disconnect", key);
45
45
  });
46
+ // 连接到直播间
47
+ room.on("enter", () => {
48
+ this.main.emit("room:enter", key);
49
+ });
46
50
  // 获取房间信息
47
51
  room.on("info", () => {
48
52
  this.main.emit("room:info", key, room.info);
@@ -77,7 +81,7 @@ class ModRoom {
77
81
  if (typeof config == "boolean") {
78
82
  config = { open: config };
79
83
  }
80
- const room = this.main.call(`room.create.${platform}`, id, config);
84
+ const room = this.main.call(`${platform}.room.create`, id, config);
81
85
  room && this.addRoom(room);
82
86
  }
83
87
  /** 移除房间 */
@@ -132,7 +136,7 @@ class ModRoom {
132
136
  this.list = new Map(arr);
133
137
  }
134
138
  /** 获取快照 */
135
- snapshot() {
139
+ getSnapshot() {
136
140
  return [...this.list].map(([key, room]) => room.info);
137
141
  }
138
142
  }
@@ -1,10 +1,10 @@
1
1
  import { FloatingLive } from "../live";
2
- import { FloatingValueMap } from "../types/values";
2
+ import { FloatingValueMap } from "../types/value";
3
3
  interface ValueConfig<T> {
4
4
  get: () => T;
5
5
  set?: (value: T) => void;
6
6
  }
7
- export declare class ModValues {
7
+ export declare class ModValue {
8
8
  private list;
9
9
  protected readonly main: FloatingLive;
10
10
  constructor(main: FloatingLive);
@@ -17,7 +17,7 @@ export declare class ModValues {
17
17
  /** 设置值 */
18
18
  set(name: string, value: any): boolean;
19
19
  /** 获取注册的所有值 */
20
- snapshot(): Record<string, any>;
20
+ getSnapshot(): Record<string, any>;
21
21
  emit<T extends keyof FloatingValueMap>(name: T, value: FloatingValueMap[T]): void;
22
22
  watch<T extends keyof FloatingValueMap>(name: T, listener: (value: FloatingValueMap[T]) => void): void;
23
23
  unwatch<T extends keyof FloatingValueMap>(name: T, listener: (value: FloatingValueMap[T]) => void): void;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ModValues = void 0;
4
- class ModValues {
3
+ exports.ModValue = void 0;
4
+ class ModValue {
5
5
  constructor(main) {
6
6
  this.list = new Map();
7
7
  this.main = main;
@@ -9,10 +9,12 @@ class ModValues {
9
9
  /** 注册值 */
10
10
  register(name, config) {
11
11
  this.list.set(name, config);
12
+ this.main.emit("value:add", name);
12
13
  }
13
14
  /** 取消注册 */
14
15
  unregister(name) {
15
16
  this.list.delete(name);
17
+ this.main.emit("value:remove", name);
16
18
  }
17
19
  /** 获取值 */
18
20
  get(name) {
@@ -30,7 +32,7 @@ class ModValues {
30
32
  }
31
33
  }
32
34
  /** 获取注册的所有值 */
33
- snapshot() {
35
+ getSnapshot() {
34
36
  const map = {};
35
37
  this.list.forEach((config, name) => {
36
38
  map[name] = config.get();
@@ -38,8 +40,8 @@ class ModValues {
38
40
  return map;
39
41
  }
40
42
  emit(name, value) {
41
- this.main.emit("values:change", name, value);
42
43
  this.main.emit(`change:${name}`, value);
44
+ this.main.emit("value:change", name, value);
43
45
  }
44
46
  watch(name, listener) {
45
47
  this.main.on(`change:${name}`, listener);
@@ -48,4 +50,4 @@ class ModValues {
48
50
  this.main.off(`change:${name}`, listener);
49
51
  }
50
52
  }
51
- exports.ModValues = ModValues;
53
+ exports.ModValue = ModValue;
@@ -5,5 +5,5 @@ export interface FloatingCommandMap {
5
5
  open: (key: string) => void;
6
6
  close: (key: string) => void;
7
7
  update: (key: string) => void;
8
- [name: `room.create.${string}`]: (id: string | number, config?: Record<string, any>) => LiveRoom;
8
+ [name: `${string}.room.create`]: (id: string | number, config?: Record<string, any>) => LiveRoom;
9
9
  }
@@ -8,6 +8,7 @@ export interface FloatingEventMap {
8
8
  room: string | number;
9
9
  }) => void;
10
10
  "room:connect": (key: string) => void;
11
+ "room:enter": (key: string) => void;
11
12
  "room:disconnect": (key: string) => void;
12
13
  "room:info": (key: string, info: RoomInfo) => void;
13
14
  "room:detail": (key: string, info: RoomDetail) => void;
@@ -25,10 +26,11 @@ export interface FloatingEventMap {
25
26
  "plugin:remove": (name: string) => void;
26
27
  "command:add": (name: string) => void;
27
28
  "command:remove": (name: string) => void;
28
- "store:add": (name: string, id: string, value: any) => void;
29
- "store:remove": (name: string, id: string) => void;
30
- "values:register": (name: string) => void;
31
- "values:change": (name: string, value: any) => void;
29
+ "manifest:add": (name: string, id: string, value: any) => void;
30
+ "manifest:remove": (name: string, id: string) => void;
31
+ "value:add": (name: string) => void;
32
+ "value:remove": (name: string) => void;
33
+ "value:change": (name: string, value: any) => void;
32
34
  [name: `change:${string}`]: (value: any) => void;
33
35
  error: (err: Error) => void;
34
36
  }
@@ -3,3 +3,6 @@ export * from "./plugin";
3
3
  export * from "./room";
4
4
  export * from "./command";
5
5
  export * from "./events";
6
+ export * from "./manifest";
7
+ export * from "./hook";
8
+ export * from "./value";
@@ -19,3 +19,6 @@ __exportStar(require("./plugin"), exports);
19
19
  __exportStar(require("./room"), exports);
20
20
  __exportStar(require("./command"), exports);
21
21
  __exportStar(require("./events"), exports);
22
+ __exportStar(require("./manifest"), exports);
23
+ __exportStar(require("./hook"), exports);
24
+ __exportStar(require("./value"), exports);
@@ -1,4 +1,4 @@
1
1
  import { PlatformInfo } from "./room";
2
- export interface FloatingStoreMap {
2
+ export interface FloatingManifestMap {
3
3
  platform: PlatformInfo;
4
4
  }
@@ -1,4 +1,4 @@
1
- import { RoomStatus } from "../enums";
1
+ import { ConnectStatus, RoomStatus } from "../enums";
2
2
  import { UserInfo } from "./message";
3
3
  /** 房间配置 */
4
4
  export interface RoomConfig {
@@ -33,8 +33,8 @@ export interface RoomInfo {
33
33
  available: boolean;
34
34
  /** 房间监听是否打开 */
35
35
  opened: boolean;
36
- /** 是否连接到房间 */
37
- connected: boolean;
36
+ /** 房间连接状态 */
37
+ connection: ConnectStatus;
38
38
  }
39
39
  /** 房间展示信息 */
40
40
  export interface RoomDetail {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "floating-live",
3
- "version": "0.15.0-beta.4",
3
+ "version": "0.15.0-beta.6",
4
4
  "type": "commonjs",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,15 +0,0 @@
1
- import { FloatingLive } from "../live";
2
- import { FloatingStoreMap } from "../types/store";
3
- export declare class ModStore {
4
- private list;
5
- protected readonly main: FloatingLive;
6
- constructor(main: FloatingLive);
7
- /** 注册store */
8
- register<T extends keyof FloatingStoreMap>(name: T, id: string, value: FloatingStoreMap[T]): void;
9
- /** 取消注册store */
10
- unregister<T extends keyof FloatingStoreMap>(name: T, id: string): void;
11
- /** 获取值 */
12
- get(name: string): Map<string, any> | undefined;
13
- /** 获取快照 */
14
- snapshot(): Record<string, Record<string, any>>;
15
- }
File without changes
File without changes
File without changes