Coder Social home page Coder Social logo

chuckt's Introduction

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>

chuckt's People

Contributors

epixa avatar manuelstofer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

chuckt's Issues

Tests

ChuckT needs them.

CommonJS support

It would be great if ChuckT could get loaded as CommonJS module. This could allow to use ChuckT with ws or other websocket libraries for evented server-server communication on node.js.

And it would also allow to use ChuckT with component or browserify.
What do you think?

an example

I was using socket.io for few months but after facing firewalls and AV problems I decided to switch to sockjs and chuckt ,but in my application chuck event is sent to the same client not to all clients ,can you provide me with an example with sockjs

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.