Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.
/ chuckt Public archive

Client library for ChuckT events over SockJS websocket API.

License

Notifications You must be signed in to change notification settings

epixa/chuckt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ChuckT client

ChuckT is a client (browser) JavaScript library for triggering and/or listening to events over the SockJS websocket API. This client is intended to be used in conjunction with a server-side implementation:

ChuckT is inspired in part by both the socket-io event system as well as the core EventEmitter in node.js.

Usage:

Initialization

Include the chuckjs client library:

<script src="chuckt.js"></script>

Make your SockJS socket communicate in chuckt:

<script>
  var sock = new SockJS('http://example.com/socket');
  var chuckt = epixa.chucktify(sock);
</script>

If you intend to receive non-chuckt messages through your socket, then instantiate ChuckT directly:

<script>
  var sock = new SockJS('http://example.com/socket');
  var chuckt = new epixa.ChuckT(sock);
  sock.onmessage = function(e) {
    chuckt.process(e.data); // will ignore the message if not chuckt
    // .. your own message handling here
  };
</script>

Listen to events fired from the backend

<script>
  chuckt.on('some-event', function(foo) {
    console.log(foo);
  });
</script>

Note: A backend event may pass any number of arguments to frontend listeners.

Emit an event to the backend

You can pass any number of arguments as well as a callback function:

<script>
  chuckt.emit('another-event', 'arg1', 'arg2', function() {
    console.log('backend acknowledged event receipt');
  });
</script>

You can also emit events without any arguments at all:

<script>
  chuckt.emit('another-event-2', function() {
    console.log('backend acknowledged event receipt');
  });
</script>

The backend can pass arguments to the callback too:

<script>
  chuckt.emit('another-event-3', function(foo, bar) {
    console.log(foo, bar); // will exist if the backend passes them
  });
</script>

Of course you can also just fire off an event and forget it:

<script>
  chuckt.emit('another-event-4');
</script>

About

Client library for ChuckT events over SockJS websocket API.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published