Giter Club home page Giter Club logo

angular-sockjs's Introduction

angular-sockjs Build Status

SockJS provider for AngularJS.

Based on Brian Ford's angular-socket-io.

Install

  1. bower install angular-sockjs
  2. Made sure the SockJS client library is loaded.
  3. Include the socket.js script provided by this component into your app.
  4. Add bd.sockjs as a module dependency to your app.

Usage

This module exposes a socketFactory, which is an API for instantiating sockets that are integrated with Angular's digest cycle.

Making a Socket Instance

// in the top-level module of the app
angular.module('myApp', [
  'bd.sockjs',
  'myApp.MyCtrl'
])
.factory('mySocket', function (socketFactory) {
  return socketFactory();
});

With that, you can inject your mySocket service into controllers and other serivices within your application!

Using Your Socket Instance

Building on the example above:

// in the top-level module of the app
angular.module('myApp', [
  'bd.sockjs',
  'myApp.MyCtrl'
])
.factory('mySocket', function (socketFactory) {
  return socketFactory({
    url: 'https://example.com'
  });
})
.controller('MyController', function (mySocket) {
  // ...
});

API

Since the SockJS API uses single event handlers rather than Socket.io's event emitter style, this library provides a lightweight wrapper around the handlers.

socket.setHandler(event, callback)

Accepts valid socket events: open, close, and message. Returns socket wrapper so multiple calls can be chained.

socket.removeHandler(event)

Handles the same events as socket.setHandler. Returns socket wrapper so multiple calls can be chained.

socket.send(message)

Sends a socket message.

socket.close([code], [reason])

Attempts to close the socket.


Options

socketFactory({socket: })

This option allows you to provide the socket service with a SockJS instance to be used internally. This is useful if you need to hold a reference to the sockjs object for use elsewhere.

angular.module('myApp', [
  'bd.sockjs'
])
.factory('mySocket', function (socketFactory) {
  var sockjs = new SockJS('http://host');

  mySocket = socketFactory({
    socket: sockjs
  });

  return mySocket;
});

socketFactory({url: })

This option allows you to provide a URL to pass through to the SockJS constructor.

License

MIT

angular-sockjs's People

Contributors

analogj avatar bendrucker avatar btford avatar jbpionnier avatar waqasajaz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

angular-sockjs's Issues

Action required: Greenkeeper could not be activated 🚨

🚨 You need to enable Continuous Integration on all branches of this repository. 🚨

To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because it uses your CI build statuses to figure out when to notify you about breaking changes.

Since we didn’t receive a CI status on the greenkeeper/initial branch, it’s possible that you don’t have CI set up yet. We recommend using Travis CI, but Greenkeeper will work with every other CI service as well.

If you have already set up a CI for this repository, you might need to check how it’s configured. Make sure it is set to run on all new branches. If you don’t want it to run on absolutely every branch, you can whitelist branches starting with greenkeeper/.

Once you have installed and configured CI on this repository correctly, you’ll need to re-trigger Greenkeeper’s initial pull request. To do this, please delete the greenkeeper/initial branch in this repository, and then remove and re-add this repository to the Greenkeeper App’s white list on Github. You'll find this list on your repo or organization’s settings page, under Installed GitHub Apps.

readme example duplication

In the readme, the second example code block ("Building on the example above...") is the same instead of actually building on the example above, which would be neat.

Bower not installing latest version

Hey @bendrucker, I had to run bower install angular-sockjs#v0.1 to actually install the latest version. Could you name the following versions tags only with numbers, without the 'v' prefix ('0.1' in this case), so bower could resolve the latest version automatically? (As of now, 0.0.1 is resolved as the latest version)

Bower install: ENORESTARGET No tag found that was able to satisfy ~0.0.1

Hi,

Previously installing from bower using ~0.0.1, but looks like you deleted the bower version or package?

Now, we get this from bower info angular-sockjs:

{
  name: 'angular-sockjs',
  main: 'socket.js',
  dependencies: {
    angular: '>= 1 < 2'
  },
  devDependencies: {
    'angular-mocks': '>= 1 < 2'
  },
  homepage: 'https://github.com/bendrucker/angular-sockjs'
}

Pass all options to sockjs constructor?

From the doc/src it seems url is the only option which gets passed to sockjs constructor. Can we specify other options such as protocol whitelist?

I'll follow up with a pull-request if you think this is worthwhile

"bower invalid-meta" error prevents any version except "*" in bower.json

Hey there,
Can't install specific versions of your package and getting an error from "bower info", see below:

$ bower info angular-sockjs
bower not-cached    git://github.com/bendrucker/angular-sockjs.git#*
bower resolve       git://github.com/bendrucker/angular-sockjs.git#*
bower checkout      angular-sockjs#master
bower invalid-meta  angular-sockjs is missing "ignore" entry in bower.json
bower resolved      git://github.com/bendrucker/angular-sockjs.git#c4d0630443

{
  name: 'angular-sockjs',
  main: 'socket.js',
  dependencies: {
    angular: '>= 1 < 2'
  },
  devDependencies: {
    'angular-mocks': '>= 1 < 2'
  },
  homepage: 'https://github.com/bendrucker/angular-sockjs'
}

No versions available.

Thanks

Stomp

Is there any demo for the usage of this plugin?

If I use socketJs I have this,

// create socketJS instance
var s = new SockJS("/stomp")
// use stomp over socketJS
var client = Stomp.over(s)
// subscribe to topic
client.subscribe topic, callbackfunction
// send to broker
client.send broker, {}, JSON.stringify(obj)

Will this plugin allow me to encapsulate this logic?

Reconnect if disconnected

Hello,

Thanks for the great module. Can you help in the following query? What to do if sockjs got disconnected due to network failure. How can I reconnect to sockjs if the network becomes avalable after some time.

I am using your module in an cordova mobile app. I is working great!

Thanks & regards,
Abhishek

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.