Socket - AppDaddy-Software-Solutions-Inc/framework-markup-language GitHub Wiki

<SOCKET/> : DataSource

The SOCKET opens a websocket between the application and an API that can both send and receive calls continuously.

Restrictions:

  • A SOCKET should only be used when interactive communication is needed between the server and client. For fewer calls or pollable options, try GET and POST datasources.

Attributes :: datasource

Name Type Default Description Req
id string null The id of the widget used for databinding.
url string null The url that opens the socket.
root string transparent The root tag that the broker will look in data returned. This can be a nested field
body string null The outer wrapper of the posting document tags. Used as an XML tag when defining a document manually, or attribute when creating the body automatically via a FORM
autoexecute bool true If the widget will fire when the template is first opened or on url change
autoquery int(s,m,h) null If set the broker fires on a timer set by the autoquery
tti int(s,m,h) 5s The time the Datasources status will stay as anything but idle.

Attributes (Data Specific)

Name Type Default Description Req
data List of item where item is a Map<String, String> or another List of item If the response is encoded as valid json or xml it is deserialized and addressable using DOTNOTATION
queueType string replace replace, lifo, fifo, append, prepend. Defines the data aggregation strategy for data returned from initial and subsequent calls. replace (default) replaces all data after each subsequent call. lifo (last in first out), fifo (first in first out), append and prepend are all used in conjunction with the maxrecords attribute
maxrecords int 10000 The maximum size data can grow to. This works in concert with type
root string The root tag that defines the repeatable items in data. This can be a nested field. If not specified, the list is segmented by the first repeatable element found in the data set
ttl int(s,m,h) 0s Time to Live caches data in the local persistent HIVE database for the period specified. This saves requerying data that changes infrequently
rowcount int 0 The number of records in data

Methods (Data Specific)

Name Type Description
clear() Clears data. Invoked in any EVENT string using <id>.clear()
add(jsonOrXml, index) string, int Deserializes the jsonOrXml string and adds it to the end of data or at position index if specified. Invoked in any EVENT string using <id>.add(jsonOrXml, index)
remove(index) int Removes the last item from data or from position index if specified. Invoked in any EVENT string using <id>.remove(index)
reverse() Reverses data. Invoked in any EVENT string using <id>.reverse()

Methods :: datasource

Name Type Description
start() Opens the SOCKET. Invoked in any EVENT string using <id>.start()
connect() Opens the SOCKET. Invoked in any EVENT string using <id>.connect()
write(message) string Writes the message to the SOCKET. If the message is null, the SOCKET body is used. Invoked in any EVENT string using <id>.write('some text to write')
disconnect() Closes the SOCKET. Invoked in any EVENT string using <id>.disconnect()
stop() Closes the SOCKET. Invoked in any EVENT string using <id>.close()
clear() Clears the data bindable. Invoked in any EVENT string using <id>.clear()
rowcount int 0

Events :: datasource

Name Type Default Description Req
onmessage string null The string of events the broker will execute on each and every message received
onsuccess string null The string of events the broker will execute when the socket is closed and the close code is 1000.
onfail string null The string of events the broker will execute when the socket is closed and the close code is not 1000.
onconnected string null The string of events the broker will execute when the connection is successfully opened
ondisconnected string null The string of events the broker will execute when the connection is successfully closed
onerror string null The string of events the broker will execute when a connection error is detected

Headers

Web sockets do not allow for HTTP <HEADERS>. <HEADERS> tags are ignored. If data needs to be passed to the endpoint when the SOCKET connection is first established, use standard uri parameters in the url attribute.

Example #1

This example demonstrates how to omit all headers.

<HEADERS/>

Examples

Example #1 (Sending and Receiving Messages)
<SOCKET id="ds1" url="wss://fml.appdaddy.co/api/demo/socket/echo" autoexecute="true"/>  
<VAR id="mycolor" value="={ds1.connected} ? 'green' : 'red'"/> 

<TEXT id="inbox" value="Messages # **{ds1.received}** "/>	  
<TEXT id="inbox" value="Message # **{ds1.message}** " />	  

<INPUT id="msgtosend" hint="enter your message .."/>
<BUTTON onclick="ds1.send('{msgtosend}')" label="SEND" type="elevated" enabled="={ds1.connected} &amp;&amp; !noe({msg})"/>

<ICON icon="={ds1.connected} ? 'wifi' : 'signal_wifi_bad'" color="{mycolor}"/>	 

<BUTTON onclick="ds1.connect()"    label="Connect"    type="elevated" enabled="=!{ds1.connected}"/>
<BUTTON onclick="ds1.disconnect()" label="Disconnect" type="elevated" enabled="{ds1.connected}"/>		

logo See it in Action

Example #2 (Uploading a file with progress)
<SOCKET id="ds1" url="wss://fml.appdaddy.co/api/demo/socket/stream?bytes={fp1.data.size}" autoexecute="true"/>
<FILEPICKER id="fp1" allow=".jpg,.png"/>

<IMAGE url="{fp1.data.file}"/>

<TEXT size="10" label="**file** : {fp1.data.name}"/>
<TEXT size="10" label="**size** : {fp1.data.size} bytes"/>
<TEXT size="10" label="**uploaded** : {ds1.data.message} bytes"/>

<LINK onclick="fp1.start()"><ICON icon="add_a_photo"/></LINK>		
<BUSY visible="{ds1.busy}" size="50"/>

<BUTTON onclick="ds1.send('{fp1.data.file}');" label="UPLOAD the IMAGE!" type="elevated" enabled="=!{ds1.busy}"/>		

logo See it in Action

Other Widgets You May Find Useful

⚠️ **GitHub.com Fallback** ⚠️