The wwWebSocket class provides basic helpers to Web Connection's Web Socket implementation.
This class can:
- Create an instance of Web Socket Message object
- Ability to Send a Web Socket Message
This class can be used in two ways:
- As incoming Message object in
wwProcess::OnWebSocket(loSocket)
- Standalone for sending a message outside of Web Connection
OnWebSocket Usage
FUNCTION OnWebSocket
************************************************************************
* OnWebSocket
****************************************
*** Function: Fired when a Web Socket request comes in.
*** Assume: loMsg.Message, loMsg.UserId, loMsg.GroupId
*** Pass: loMsg - Incoming (loMsg.Message) from Socket
*** loSocketBroadcast - Use to broadcast message to others
*** Return: nothing
************************************************************************
LPARAMETERS loSocket as wwWebSocketMessage
LOCAL lcMarkdown, loSocketMsg, loMsg
*** This is the Socket Payload object
loMsg = loSocket.oMessage
DO CASE
CASE loMsg.action == "broadcastchatmessage"
loSocket.AddRecipient(loMsg.GroupId, "group")
*** Parse incoming message as Markdown
lcMarkdown = Markdown(loMsg.message)
lcMarkdown = ALLTRIM(lcMarkdown) && RTRIM(LTRIM(lcMarkdown,0,"<p>"),"</p>")
*** Change incoming message with updated HTML
loMsg.message = lcMarkdown
*** Broadcast the message
loSocket.BroadcastMessage(loMsg)
ENDCASE
ENDFUNC
* OnWebSocket
Standalone Usage
DO wwWebSockets
loSocket = CREATEOBJECT("wwWebSockets")
loSocket.cBaseUrl = "http://localhost:5200/"
loMsg = loSocket.GetMessageObject()
loMsg.userId = "RickFox"
loMsg.Message = "Hello from FoxPro " + TIME()
loMsg.action = "broadcastchatmessage" && send to everybody
loSocket.BroadcastMessage(loMsg)
Class Members
Member | Description | |
---|---|---|
AddRecipient |
The wwWebSocket class provides basic helpers to Web Connection's Web Socket implementation. o.AddRecipient(lcUserOrGroup,lcType) |
|
BroadcastMessage |
This method allows you to broadcast a message to connected Web Socket clients at the server you are targeting. o.BroadcastMessage(loMsg) |
|
CreateMessageObject |
Creates a Web Socket message object the structure that is used to broadcast messages to all connected recipients. o.CreateMessageObject(llDontAssign) |
|
cBaseUrl |
The base URL to the Web Site to send to. Needs to be set when sending outside of Web Connection. Inside of Web Connection this value is automatically set based on the incoming request of the Web site. | |
oMessage |
An instance of a Message object created with CreateMessageObject() . |
See also:
Class wwWebSocket© West Wind Technologies, 1996-2024 • Updated: 03/10/21
Comment or report problem with topic