Jump to content

Recommended Posts

Posted

Hi,

I am building a multi tenant solution and want to restrict traffic to specific clients. From what I understand we can only broadcast to everyone as of now?

Will there be an option to be able to send to a specific client? 

I can think of these alternatives:

  • Wait for implementation in Unigui
  • Use javascript and a custom websocket solution
  • Use vcl websocket on mainmodule (one fore each) so that we get single user
  • Deploy once for every tenant
  • Other alternatives?

Regards, Fredrik.

Posted

I just discovered BroadcastMessageSessions and I guess it can be used with UniSession.SessionId

Anyone with samplecode/info? Nothing in the helpfile I am afraid.

  • Like 1
Posted

Off memory this is how I make sure my tables "tblVolunteers" and "tblVolunteerLkUp" are refreshed after another app has edited their data using the Broadcast feature to notify. I decided to force MainForm to send the Broadcast via MainModule Ajax Event.

MainForm receiving broadcast message

procedure TMainForm.MainFormBroadcastMessage(const Sender: TComponent; const Msg: string; const Params: TUniStrings);
var
  s: String;
begin
  //////////////////////////////////////////////////////////////////////////////
  if Msg = 'VolunteerUpdate' then begin
    if UniMainModule.tblVolunteers.Active = True then begin
      if UniMainModule.EditingVolunteerFlag = False then begin

        ////////////////////////////////////////////////////////////////////////
        s:= Params.Values['SID'];
        if UniSession.SessionID <> s then begin

          //////////////////////////////////////////////////////////////////////
          // Volunteers
          try
            UniMainModule.tblVolunteers.Refresh;        // REQUIRED FOR CALCULATED FIELDS
            UniMainModule.dsVolunteers.DataSet.Refresh; // REQUIRED FOR GRID
          except
          end;

          //////////////////////////////////////////////////////////////////////
          // Volunteer LookUp
          try
            if UniMainModule.tblVolunteerLkUp.Active = True then begin
              UniMainModule.tblVolunteerLkUp.Refresh;  // Sync
            end;
          except
          end;

        end; // SessionID

      end; // EditingVolunteerFlag
    end; // Active
  end; // VolunteerUpdate
end;

MainModule has tblVolunteers AfterDelete/AfterPost Events etc. to Notify MainForm

procedure TUniMainModule.tblVolunteersAfterPost(DataSet: TDataSet);
begin
  UniSession.AddJS('ajaxRequest('+MainForm.WebForm.JSName+', ''_VolunteerEdited_'', []);')
end;

MainForm AjaxEvent Send Broadcast

procedure TMainForm.MainFormAjaxEvent(Sender: TComponent; EventName: string; Params: TUniStrings);
begin

  ////////////////////////////////////////////////////////////////////
  if SameText('_VolunteerEdited_', EventName) then begin
    BroadcastMessage('VolunteerUpdate', ['SID', UniSession.SessionID]);
    Exit;
  end;
...

Of course there are many ways to do this.

  • Thanks 1
Posted

Hello,

17 hours ago, Larsson said:

Will there be an option to be able to send to a specific client? 

 

17 hours ago, Larsson said:

I just discovered BroadcastMessageSessions and I guess it can be used with UniSession.SessionId

Anyone with samplecode/info? Nothing in the helpfile I am afraid.

Yes, BroadcastMessageSessions allows you to target specific sessions by using their SessionId. However, it's important to keep in mind that a SessionId is only valid for the lifetime of the current user session — it's not a permanent identifier for a client or user.

If you're building a multi-tenant system and want to send messages to specific users or tenants consistently, you’ll need to maintain a mapping between your user IDs (or tenant IDs) and active SessionIds.
This way, you can use BroadcastMessageSessions dynamically by looking up the correct sessions at runtime.

Would you mind clarifying what you mean by “specific client”? Are you referring to a unique user, tenant, or something else? This would help suggest the most suitable approach.

  • Like 1
Posted
On 5/1/2025 at 8:12 AM, Larsson said:

Hi,

I am building a multi tenant solution and want to restrict traffic to specific clients. From what I understand we can only broadcast to everyone as of now?

Will there be an option to be able to send to a specific client? 

I can think of these alternatives:

  • Wait for implementation in Unigui
  • Use javascript and a custom websocket solution
  • Use vcl websocket on mainmodule (one fore each) so that we get single user
  • Deploy once for every tenant
  • Other alternatives?

Regards, Fredrik.

 

We will share the code soon

websocket.thumb.gif.48eb66009bd8a76d92c843d44eb1699a.gif

  • Like 4
  • Upvote 1
  • 3 months later...
Posted

I'm using Websocket, and I filter the message I send to all clients on the client side and display it to the relevant users. This isn't very efficient and consumes a lot of system resources. I need to send a message specifically to the relevant client. Can you share your code, Hayri?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...