Skip to content

Commit 3a52149

Browse files
intel352claude
andcommitted
fix: export public API, use config params in all steps
- Add public NewWebSocketPlugin() constructor - Export GetHub() and BroadcastToRoom on hub - All step types read from config (template-resolved) instead of current - Add HTTPPath() to wsServerModule for adapter route registration Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 986ad53 commit 3a52149

7 files changed

Lines changed: 53 additions & 11 deletions

File tree

internal/hub.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,30 @@ func (h *hub) broadcastToRoom(room string, msg []byte, exclude string) {
157157
}
158158
}
159159

160+
// BroadcastToRoom sends msg to all connections in room, returning the recipient count.
161+
// This satisfies the gameserver plugin's ws_bridge.WSHub interface.
162+
func (h *hub) BroadcastToRoom(room string, msg []byte) int {
163+
h.mu.RLock()
164+
members, ok := h.rooms[room]
165+
if !ok {
166+
h.mu.RUnlock()
167+
return 0
168+
}
169+
ids := make([]string, 0, len(members))
170+
for id := range members {
171+
ids = append(ids, id)
172+
}
173+
h.mu.RUnlock()
174+
175+
count := 0
176+
for _, id := range ids {
177+
if h.sendTo(id, msg) {
178+
count++
179+
}
180+
}
181+
return count
182+
}
183+
160184
func (h *hub) broadcastAll(msg []byte, exclude string) {
161185
h.mu.RLock()
162186
ids := make([]string, 0, len(h.connections))

internal/module_ws_server.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ func (m *wsServerModule) Stop(ctx context.Context) error {
110110
return nil
111111
}
112112

113+
// HTTPPath returns the path this module wants to handle.
114+
func (m *wsServerModule) HTTPPath() string { return m.path }
115+
113116
// ServeHTTP handles WebSocket upgrade requests.
114117
// The host workflow engine routes HTTP requests to this handler.
115118
func (m *wsServerModule) ServeHTTP(w http.ResponseWriter, r *http.Request) {

internal/step_ws_broadcast.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ func (s *wsBroadcastStep) Execute(ctx context.Context, triggerData map[string]an
2323
return &sdk.StepResult{Output: map[string]any{"error": "ws.server not initialized", "recipients": 0}}, nil
2424
}
2525

26-
room, _ := current["room"].(string)
27-
message, _ := current["message"].(string)
28-
exclude, _ := current["exclude"].(string)
26+
room, _ := config["room"].(string)
27+
message, _ := config["message"].(string)
28+
exclude, _ := config["exclude"].(string)
2929

3030
msg := []byte(message)
3131
var count int

internal/step_ws_close.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func (s *wsCloseStep) Execute(ctx context.Context, triggerData map[string]any,
2121
return &sdk.StepResult{Output: map[string]any{"error": "ws.server not initialized", "closed": false}}, nil
2222
}
2323

24-
connID, _ := current["connectionId"].(string)
24+
connID, _ := config["connectionId"].(string)
2525

2626
closed := h.closeConnection(connID)
2727
return &sdk.StepResult{Output: map[string]any{"closed": closed}}, nil

internal/step_ws_room.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ func (s *wsRoomJoinStep) Execute(ctx context.Context, triggerData map[string]any
2323
return &sdk.StepResult{Output: map[string]any{"error": "ws.server not initialized", "joined": false}}, nil
2424
}
2525

26-
connID, _ := current["connectionId"].(string)
27-
room, _ := current["room"].(string)
26+
connID, _ := config["connectionId"].(string)
27+
room, _ := config["room"].(string)
2828

2929
if connID == "" || room == "" {
3030
return &sdk.StepResult{Output: map[string]any{"error": "connectionId and room are required", "joined": false}}, nil
@@ -54,8 +54,8 @@ func (s *wsRoomLeaveStep) Execute(ctx context.Context, triggerData map[string]an
5454
return &sdk.StepResult{Output: map[string]any{"error": "ws.server not initialized", "left": false}}, nil
5555
}
5656

57-
connID, _ := current["connectionId"].(string)
58-
room, _ := current["room"].(string)
57+
connID, _ := config["connectionId"].(string)
58+
room, _ := config["room"].(string)
5959

6060
if connID == "" || room == "" {
6161
return &sdk.StepResult{Output: map[string]any{"error": "connectionId and room are required", "left": false}}, nil
@@ -82,7 +82,7 @@ func (s *wsRoomListStep) Execute(ctx context.Context, triggerData map[string]any
8282
return &sdk.StepResult{Output: map[string]any{"error": "ws.server not initialized", "connections": []string{}}}, nil
8383
}
8484

85-
room, _ := current["room"].(string)
85+
room, _ := config["room"].(string)
8686
members := h.roomMembers(room)
8787
if members == nil {
8888
members = []string{}

internal/step_ws_send.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ func (s *wsSendStep) Execute(ctx context.Context, triggerData map[string]any,
2323
return &sdk.StepResult{Output: map[string]any{"error": "ws.server not initialized", "sent": false}}, nil
2424
}
2525

26-
connID, _ := current["connectionId"].(string)
27-
message, _ := current["message"].(string)
26+
connID, _ := config["connectionId"].(string)
27+
message, _ := config["message"].(string)
2828

2929
if connID == "" {
3030
return &sdk.StepResult{Output: map[string]any{"error": "connectionId required", "sent": false}}, nil

plugin.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,18 @@ import (
1010
func NewWebSocketPlugin() sdk.PluginProvider {
1111
return internal.NewWebSocketPlugin()
1212
}
13+
14+
// Hub is an exported interface for the WebSocket hub's broadcast capabilities.
15+
// Satisfied by the internal hub after the ws.server module is initialized.
16+
type Hub interface {
17+
BroadcastToRoom(room string, msg []byte) int
18+
}
19+
20+
// GetHub returns the global WebSocket hub once the ws.server module has been
21+
// initialized. Returns nil if the module has not started yet.
22+
func GetHub() Hub {
23+
if h := internal.GetHub(); h != nil {
24+
return h
25+
}
26+
return nil
27+
}

0 commit comments

Comments
 (0)