1k-adding-socket-events

Adds new WebSocket event subscriptions to OneKey. Use when implementing new socket events, handling server push messages, or adding real-time data subscriptions. Socket, WebSocket, event, subscription, push, real-time.

16 stars

Best use case

1k-adding-socket-events is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

Adds new WebSocket event subscriptions to OneKey. Use when implementing new socket events, handling server push messages, or adding real-time data subscriptions. Socket, WebSocket, event, subscription, push, real-time.

Teams using 1k-adding-socket-events should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/1k-adding-socket-events/SKILL.md --create-dirs "https://raw.githubusercontent.com/diegosouzapw/awesome-omni-skill/main/skills/development/1k-adding-socket-events/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/1k-adding-socket-events/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How 1k-adding-socket-events Compares

Feature / Agent1k-adding-socket-eventsStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

Adds new WebSocket event subscriptions to OneKey. Use when implementing new socket events, handling server push messages, or adding real-time data subscriptions. Socket, WebSocket, event, subscription, push, real-time.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

# Adding WebSocket Event Subscriptions

This skill documents how to add new WebSocket event subscriptions in the OneKey app.

## Overview

WebSocket events enable real-time server-to-client communication. The pattern involves:
1. Define the event name in `EAppSocketEventNames` enum
2. Define the payload type interface
3. Add the event handler in `PushProviderWebSocket`

## Key Files

| Purpose | Location |
|---------|----------|
| Event names & payload types | `packages/shared/types/socket.ts` |
| WebSocket event handlers | `packages/kit-bg/src/services/ServiceNotification/PushProvider/PushProviderWebSocket.ts` |

## Step-by-Step Guide

### Step 1: Define Event Name

Add the new event name to `EAppSocketEventNames` in `packages/shared/types/socket.ts`:

```typescript
export enum EAppSocketEventNames {
  notification = 'notification',
  ping = 'ping',
  pong = 'pong',
  ack = 'ack',
  market = 'market',
  primeConfigChanged = 'CONFIG_CHANGE',
  // ... existing events
  myNewEvent = 'MY_NEW_EVENT',  // Add your new event
}
```

**Convention**: Use camelCase for the enum key, SCREAMING_SNAKE_CASE for the string value.

### Step 2: Define Payload Type

Add the payload interface in `packages/shared/types/socket.ts`:

```typescript
export interface IMyNewEventPayload {
  msgId: string;  // Required for acknowledgment
  // Add other fields as needed
  someData?: string;
  someNumber?: number;
}
```

**Important**: Always include `msgId: string` for message acknowledgment.

### Step 3: Add Event Handler

In `packages/kit-bg/src/services/ServiceNotification/PushProvider/PushProviderWebSocket.ts`:

1. Import the new payload type:

```typescript
import type {
  // ... existing imports
  IMyNewEventPayload,
} from '@onekeyhq/shared/types/socket';
```

2. Add the event handler in `initWebSocket()` method:

```typescript
this.socket.on(EAppSocketEventNames.myNewEvent, (payload: IMyNewEventPayload) => {
  // 1. Acknowledge receipt (required for most events)
  void this.backgroundApi.serviceNotification.ackNotificationMessage({
    msgId: payload.msgId,
    action: ENotificationPushMessageAckAction.arrived,
  });

  // 2. Handle the event (call appropriate service method)
  void this.backgroundApi.someService.handleMyNewEvent(payload);
});
```

## Complete Example: userInfoUpdated Event

Here's a real example from the codebase:

### 1. Event Name (socket.ts)

```typescript
export enum EAppSocketEventNames {
  // ... other events
  userInfoUpdated = 'USER_INFO_UPDATED',
}
```

### 2. Payload Type (socket.ts)

```typescript
export interface IUserInfoUpdatedPayload {
  msgId: string;
}
```

### 3. Event Handler (PushProviderWebSocket.ts)

```typescript
this.socket.on(EAppSocketEventNames.userInfoUpdated, (payload: IUserInfoUpdatedPayload) => {
  void this.backgroundApi.serviceNotification.ackNotificationMessage({
    msgId: payload.msgId,
    action: ENotificationPushMessageAckAction.arrived,
  });
  void this.backgroundApi.servicePrime.apiFetchPrimeUserInfo();
});
```

## Event Handler Patterns

### Simple Acknowledgment + Action

```typescript
this.socket.on(EAppSocketEventNames.myEvent, (payload: IMyPayload) => {
  void this.backgroundApi.serviceNotification.ackNotificationMessage({
    msgId: payload.msgId,
    action: ENotificationPushMessageAckAction.arrived,
  });
  void this.backgroundApi.someService.doSomething();
});
```

### With Logging

```typescript
this.socket.on(EAppSocketEventNames.myEvent, (payload: IMyPayload) => {
  defaultLogger.notification.websocket.consoleLog(
    'WebSocket received myEvent:',
    payload,
  );
  void this.backgroundApi.serviceNotification.ackNotificationMessage({
    msgId: payload.msgId,
    action: ENotificationPushMessageAckAction.arrived,
  });
  void this.backgroundApi.someService.doSomething(payload);
});
```

### With Validation

```typescript
this.socket.on(EAppSocketEventNames.myEvent, async (payload: IMyPayload) => {
  if (!payload?.requiredField) {
    console.error('myEvent ERROR: requiredField is missing', payload);
    return;
  }
  void this.backgroundApi.serviceNotification.ackNotificationMessage({
    msgId: payload.msgId,
    action: ENotificationPushMessageAckAction.arrived,
  });
  await this.backgroundApi.someService.doSomething(payload);
});
```

### With EventBus Emission

```typescript
this.socket.on(EAppSocketEventNames.myEvent, (payload: IMyPayload) => {
  void this.backgroundApi.serviceNotification.ackNotificationMessage({
    msgId: payload.msgId,
    action: ENotificationPushMessageAckAction.arrived,
  });
  appEventBus.emit(EAppEventBusNames.MyEventReceived, payload);
});
```

## Important: Message Acknowledgment

**You MUST acknowledge messages via `serviceNotification.ackNotificationMessage`**. If you don't acknowledge the `msgId`, the server will assume the message was not delivered and will retry sending it repeatedly.

```typescript
void this.backgroundApi.serviceNotification.ackNotificationMessage({
  msgId: payload.msgId,
  action: ENotificationPushMessageAckAction.arrived,
});
```

This should be called as early as possible in your event handler to prevent duplicate message delivery.

## Acknowledgment Actions

Available actions in `ENotificationPushMessageAckAction`:
- `arrived` - Message was received (use this for most cases)
- `clicked` - User clicked the notification

## Checklist

- [ ] Event name added to `EAppSocketEventNames` enum
- [ ] Payload interface defined with `msgId: string`
- [ ] Payload type imported in `PushProviderWebSocket.ts`
- [ ] Event handler added in `initWebSocket()` method
- [ ] **Message acknowledged via `ackNotificationMessage`** (required to prevent server retries)
- [ ] Appropriate service method called to handle the event
- [ ] Logging added if needed for debugging

Related Skills

asyncredux-events

16
from diegosouzapw/awesome-omni-skill

Use the Event class to interact with Flutter's stateful widgets (TextField, ListView, etc.). Covers creating Event objects in state, consuming events with `context.event()`, scrolling lists, changing text fields, and the event lifecycle.

adding-animations

16
from diegosouzapw/awesome-omni-skill

Add micro-interactions and animations using Framer Motion. Use when user asks about animations, transitions, hover effects, or motion design. MANDATORY for every component.

analytics-events

16
from diegosouzapw/awesome-omni-skill

Add product analytics events to track user interactions in the Metabase frontend

adding-todos

16
from diegosouzapw/awesome-omni-skill

Use this skill to capture an idea, task, or issue that surfaces during a Kata session as a structured todo for later work. This skill creates markdown todo files in the .planning/todos/pending directory with relevant metadata and content extracted from the conversation. Triggers include "add todo", "capture todo", "new todo", and "create todo".

adding-markdown-highlighted-comments

16
from diegosouzapw/awesome-omni-skill

Use when adding responses to markdown documents with user-highlighted comments, encountering markup errors, or unsure about mark tag placement - ensures proper model-highlight formatting with required attributes and correct placement within markdown elements

1k-adding-chains

16
from diegosouzapw/awesome-omni-skill

Guide for adding new blockchain chains to OneKey. Use when implementing new chain support, adding blockchain protocols, or understanding chain architecture. Triggers on chain, blockchain, protocol, network, coin, token, add chain, new chain.

adding-notes

16
from diegosouzapw/awesome-omni-skill

Add new notes to the Second Brain knowledge base. Use when the user provides a resource (URL, book, podcast, article, GitHub repo, Reddit thread) and asks to "add a note", "create a note", "save this", "add to my notes", "take notes on", or "capture this".

events-webinars

16
from diegosouzapw/awesome-omni-skill

Use this skill when a VP of Events or field marketing leader needs to plan and execute the full events program — including webinars, technology workshops, solution workshops, global speaking engagements, conferences, and community events — capturing leads, filling the sales calendar post-event, and building market presence with investors, enterprise buyers, and practitioners.

Websocket Patterns

16
from diegosouzapw/awesome-omni-skill

WebSocket is a communication protocol that provides full-duplex communication channels over a single TCP connection. It enables real-time, event-driven communication between clients and servers, makin

websocket-engineer

16
from diegosouzapw/awesome-omni-skill

Use when building real-time communication systems with WebSockets or Socket.IO. Invoke for bidirectional messaging, horizontal scaling with Redis, presence tracking, room management.

solidstart-websocket

16
from diegosouzapw/awesome-omni-skill

SolidStart WebSocket: experimental WebSocket endpoints, connection handling, message events, real-time communication, bidirectional data flow.

newsletter-events-write

16
from diegosouzapw/awesome-omni-skill

Generate markdown newsletters from stored events. Use when the user wants to create, write, or generate a newsletter from scraped events.