Skip to content

lelylan/websockets

Repository files navigation

Lelylan Websockets

Lelylan full-duplex communication over TCP

Requirements

Lelylan Websockets is tested against Node 0.10.36.

Installation

$ git clone [email protected]:lelylan/websockets.git && cd websockets
$ npm install && npm install -g foreman
$ nf start

Install with docker

Badges

Docker image: lelylanlab/websockets

Use docker hub image

$ docker run -d -it --name websockets lelylanlab/websockets

Generate local image

$ docker build --tag=websockets .
$ docker run -d -it --name websockets websockets

When installing the service in production set lelylan environment variables.

Resources

The basic logic behind the websocket microservcie is that when a physical device is updated, changes are broadcasted to all clients who registered to the service with a valid access token.

Tutorial

The realtime service can be integrated in any client who has access to a valid access token.

Install the socket.io library.

  <script src="socket.io/socket.io.js"></script>

Connect to the realtime server and sync the device component.

function DashboardCtrl($scope, AccessToken) {
  var authorized = (!!AccessToken.get().access_token);

  if (authorized) {
    // connect to the Websocket service
    var socket = io.connect('http://localhost');

    socket.on(AccessToken.get().access_token, function (event) {
      $scope.fire(event.data);
      $scope.$apply(); // needed to refresh the page changes
    });

    $scope.fire = function(device) {
      $rootScope.$broadcast('lelylan:device:request:end', device);
    };

    socket.on('connected', function (event) {
      $scope.connected = true;
      $scope.$apply();
    })

    socket.on('disconnected', function (event) {
      $scope.connected = false;
      $scope.$apply();
    })
  }
}

DashboardCtrl.$inject = ['$scope', 'AccessToken'];

See Lelylan Dashboard code for a working implementation.

Contributing

Fork the repo on github and send a pull requests with topic branches. Do not forget to provide specs to your contribution.

Running specs

npm install
npm test

Coding guidelines

Follow Felix guidelines.

Feedback

Use the issue tracker for bugs or stack overflow for questions. Mail or Tweet us for any idea that can improve the project.

Links

Authors

Andrea Reginato

Contributors

Special thanks to all contributors for submitting patches.

Changelog

See CHANGELOG

License

Lelylan is licensed under the Apache License, Version 2.0.

About

Full-duplex communication over TCP

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages