ServerEvent

ServerEvent

new ServerEvent(url)

Description:
  • Implements a mechanism to react to events from the server.

    • This is the client side of a simple client/server mechanism.

    • The interface is used in HTML page, using a construct of the form:

    <script type='text/javascript' src='.../aideweb.js'></script>
    <script type='text/javascript'>
     var serverEvent = New ServerEvent("http://localhost:8080/_event_name"); 
    
     serverEvent.onEvent(function(value) {
       console.log("Got this event value: '" + value + "'");
     });
    
Parameters:
Name Type Description
url string

The service URL.

Methods

onEvent(callback, timeout, maxcount)

Description:
  • Registers and attachs a callback to recieve and process the server events.

Parameters:
Name Type Description
callback callback

The callback that handles the events when emitted.

  • Runs the callback(value: string) function with the event string value, when the event is recieved.
timeout unit

The maximal waiting time in millisecond, 0 means no timeout.

  • On timeout the event receptions stops.
maxcount unit

The maximal number of event to be recieved, 0 means no bound.

  • On event bound count the event receptions stops.

isPending()

Description:
  • Returns true if an event is pending.

clear()

Description:
  • Stops the process and purges the event queue.

    • A pending event will still treated.

addClock(period, count)

Description:
  • Generates a periodic event (mainly for debugging purpose).

    • The event value writes $index, the occurence index, starting from 0.
Parameters:
Name Type Description
period uint

The clock period in millisecond, 0 to stop the clock.

count uint

The maximal number of event, 0 if no bound.