feat(broadcasting): add ActionCable adapter + fix model broadcast anti-pattern
- Add Mozo::Broadcaster::ActionCable as drop-in Faye replacement - Fix model_broadcast.rb: delegate to Mozo directly instead of ApplicationController.new (memory-unsafe anti-pattern) - Add Broadcastable concern for clean model-side broadcasting - ActionCable config: async adapter, cable.yml, WebSocket endpoint - MozoChannel with per-entity authorization (user/supplier/employee) - Connection auth via auth_token (matches existing auth pattern) - Mount /cable WebSocket in routes - Add broadcasting-migration.md with Faye→ActionCable guide
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# Include this in any model that needs to broadcast events to users/suppliers.
|
||||
#
|
||||
# Replaces the old model_broadcast.rb initializer which monkey-patched
|
||||
# SimplyStored::Couch and created ApplicationController.new per broadcast
|
||||
# (memory-unsafe, no request context, to be removed once all callers migrate).
|
||||
#
|
||||
# Usage:
|
||||
# class List < ApplicationRecord
|
||||
# include Broadcastable
|
||||
#
|
||||
# def close!
|
||||
# broadcast_user(user.id, 'list_closed', { id: id })
|
||||
# broadcast_supplier(supplier_id, 'list_closed', { id: id })
|
||||
# end
|
||||
# end
|
||||
#
|
||||
module Broadcastable
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
def broadcast_supplier(sid, event, data = {})
|
||||
Mozo.broadcast_supplier(sid, event, data)
|
||||
end
|
||||
|
||||
def broadcast_user(uid, event, data = {})
|
||||
Mozo.broadcast_user(uid, event, data)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user