fix(ImClient): make sendSync/scheduleReconnect safe when SDK not initialized
ImClient.sendSync() called getConfig() which throws when init() hasn't been called, breaking headless usage (e.g. platform event listeners). Now wraps the call in a try-catch and skips the sync frame if appKey is unavailable. Same fix for scheduleReconnect's debug log. Also: add vite-plugin-dts to generate TypeScript declarations on every build, fixing the missing dist/index.d.ts that broke IDE type resolution. Bump to 0.2.3. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
这个提交包含在:
父节点
a68550e576
当前提交
df7557b77f
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@xuqm/vue3-sdk",
|
"name": "@xuqm/vue3-sdk",
|
||||||
"version": "0.2.2",
|
"version": "0.2.3",
|
||||||
"description": "XuqmGroup Vue3 SDK — IM & platform integration for web",
|
"description": "XuqmGroup Vue3 SDK — IM & platform integration for web",
|
||||||
"private": false,
|
"private": false,
|
||||||
"publishConfig": {
|
"publishConfig": {
|
||||||
@ -21,7 +21,7 @@
|
|||||||
],
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite build --watch",
|
"dev": "vite build --watch",
|
||||||
"build": "tsc --emitDeclarationOnly && vite build",
|
"build": "vite build",
|
||||||
"type-check": "tsc --noEmit",
|
"type-check": "tsc --noEmit",
|
||||||
"test": "vitest run",
|
"test": "vitest run",
|
||||||
"test:watch": "vitest",
|
"test:watch": "vitest",
|
||||||
|
|||||||
@ -227,7 +227,8 @@ export class ImClient {
|
|||||||
|
|
||||||
private sendSync(): void {
|
private sendSync(): void {
|
||||||
if (this.ws?.readyState !== WebSocket.OPEN) return
|
if (this.ws?.readyState !== WebSocket.OPEN) return
|
||||||
const config = getConfig()
|
const config = (() => { try { return getConfig() } catch { return null } })()
|
||||||
|
if (!config?.appKey) return
|
||||||
this.ws.send(
|
this.ws.send(
|
||||||
buildStompFrame(
|
buildStompFrame(
|
||||||
'SEND',
|
'SEND',
|
||||||
@ -261,7 +262,8 @@ export class ImClient {
|
|||||||
|
|
||||||
private scheduleReconnect(): void {
|
private scheduleReconnect(): void {
|
||||||
if (this.destroyed) return
|
if (this.destroyed) return
|
||||||
if (getConfig().debug) {
|
const debug = (() => { try { return getConfig().debug } catch { return false } })()
|
||||||
|
if (debug) {
|
||||||
console.log(`[ImClient] reconnect in ${this.reconnectDelay}ms`)
|
console.log(`[ImClient] reconnect in ${this.reconnectDelay}ms`)
|
||||||
}
|
}
|
||||||
this.reconnectTimer = setTimeout(() => {
|
this.reconnectTimer = setTimeout(() => {
|
||||||
|
|||||||
@ -1,10 +1,12 @@
|
|||||||
import { defineConfig } from 'vite'
|
import { defineConfig } from 'vite'
|
||||||
import vue from '@vitejs/plugin-vue'
|
import vue from '@vitejs/plugin-vue'
|
||||||
|
import dts from 'vite-plugin-dts'
|
||||||
import { resolve } from 'path'
|
import { resolve } from 'path'
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [
|
plugins: [
|
||||||
vue(),
|
vue(),
|
||||||
|
dts({ include: ['src'], insertTypesEntry: true }),
|
||||||
],
|
],
|
||||||
build: {
|
build: {
|
||||||
lib: {
|
lib: {
|
||||||
|
|||||||
正在加载...
在新工单中引用
屏蔽一个用户