This is Server Presence Protocol Component, you need to drop this component in the form and select a TsgcWebSocketServer Component using Server Property.
All methods are handled internally by the server in response to client requests.
You must link this component to a Server or to a Broker if you are using more than one protocol.
EncodeBase64: by default is disabled, string values are encoded in base64 to avoid problems with JSON encoding.
Acknowledgment: if enabled, every time a server sends a message to client assign an ID to this message and queues in a list. When the client receives a message, if detect it has an ID, it sends an Acknowledgment to the server, which means the client has processed message and server can delete from the queue.
Interval: interval in seconds where server checks if there are messages not processed by client.
Timeout: maximum wait time before the server sends the message again.
There are several events to handle actions like: a new member request to join a channel, a new channel is created by a member, a member unsubscribes from a channel...
New Member
// When a new client connects to a server, first sends member data to the server to request a new member.
// Following events can be called:
// OnBeforeNewMember:
// Server receives a request from the client to join and the server accepts or not this member.
// Use Accept parameter to allow or not this member. By default all members are accepted.
void OnBeforeNewMember(TsgcWSConnection *aConnection, const TsgcWSPresenceMember *aMember, ref bool Accept)
{
if (aMember->Name == "Spam"
{
Accept = false;
}
}
// OnNewMember:
// After a new member is accepted, then this event is called and means this member has join member list.
// You can use aMember. Data property to store objects in memory like database access, session objects...
void OnNewMember(TsgcWSConnection *aConnection, const TsgcWSPresenceMember *aMember)
{
}
Subscriptions
// When a client has joined as a member, can subscribe to new channels, if a channel not exists,
// the following events can be called:
// OnBeforeNewChannel:
// Server receives a subscription request from the client to join this channel but the channel doesn't exist,
// the server can accept or not to create this channel. Use Accept parameter to allow or not this channel.
// By default, all channels are accepted.
void OnBeforeNewChannelBeforeNewChannel(TsgcWSConnection *Connection, const TsgcWSPresenceChannel *aChannel,
const TsgcWSPresenceMember *aMember, ref bool Accept)
begin
if (aChannel->Name == "Spam")
{
Accept = false;
}
end;
// OnNewChannel: After a new channel is accepted, then this event is called and means a new channel has been created.
// Channel properties can be customized in this event.
void OnNewChannel(TsgcWSConnection *Connection, ref TsgcWSPresenceChannel *aChannel)
{
}
// If the channel already exists or has been created, the server can accept or no new subscriptions.
// OnBeforeNewChannelMembers:
// Server receives a subscription request from a client to join this channel, the server can accept
// or not a member join. Use Accept parameter to allow or not this member. By default, all members are accepted.
void OnBeforeNewChannelMember(TsgcWSConnection *Connection, const TsgcWSPresenceChannel *aChannel,
const TsgcWSPresenceMember *aMember, ref bool Accept)
{
if (aMember->Name == "John")
{
Accept = true
}
else
{
if (aMember->Name = "Spam")
{
Accept = false;
}
}
}
// OnNewChannelMember:
// After a new member is accepted, then this event is called and means a new member has joined the channel.
// All subscribers to this channel, will be notified about new members.
void OnNewChannelMember(TsgcWSConnection *Connection, const TsgcWSPresenceChannel *aChannel,
const TsgcWSPresenceMember *aMember)
{
}
UnSubscriptions
// Every time a member unjoin a channel or disconnects, the server is notified by following events:
// OnRemoveChannelMember:
// Server receives a subscription request from a client to join this channel but the channel doesn't exist,
// the server can accept or not to create this channel. Use Accept parameter to allow or not this channel.
// By default all channels are accepted.
void OnRemoveChannelMember(TsgcWSConnection *Connection, const TsgcWSPresenceChannel *aChannel,
const TsgcWSPresenceMember *aMember)
{
Log("Member: " + aMember->Name + " unjoin channel: " + aChannel->Name);
}
// When a member disconnects, automatically server is notified:
// OnRemoveMember: when the client disconnects from protocol, this event is called and server is notified of
// which never has disconnected.
void OnRemoveMember(TsgcWSConnection *Connection, TsgcWSPresenceMember *aMember)
{
Log("Member: " + aMember->Name);
};
Errors
// Every time there is an error, these events are called, example: server has denied a member
// to subscribe to a channel, a member try to subscribe to an already subscribed channel...
//OnErrorMemberChannel: this event is called every time there is an error trying to create a new channel,
// join a new member, subscribe to a channel...
void OnErrorMemberChannel(TsgcWSConnection *Connection, const TsgcWSPresenceError *aError,
const TsgcWSPresenceChannel *aChannel, const TsgcWSPresenceMember *aMember)
{
Log("#Error: " + aError->Text);
}
// When a member disconnects, automatically server is notified:
// OnErrorPublishMsg: when a client publish a message and this is denied by the server, this event is raised.
void OnErrorPublishMsg(TsgcWSConnection *Connection, const TsgcWSPresenceError *aError, const TsgcWSPresenceMsg *aMsg,
const TsgcWSPresenceChannel *aChannel; const TsgcWSPresenceMember *aMember)
{
Log("#Error: " + aError->Text);
}