angular-sockjs-mit

WebJar for angular-sockjs-mit

License

License

MIT
Categories

Categories

JavaScript Languages Angular User Interface Web Frameworks
GroupId

GroupId

org.webjars.bower
ArtifactId

ArtifactId

angular-sockjs-mit
Last Version

Last Version

0.1.0
Release Date

Release Date

Type

Type

jar
Description

Description

angular-sockjs-mit
WebJar for angular-sockjs-mit
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/Stummi/angular-sockjs

Download angular-sockjs-mit

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.bower/angular-sockjs-mit/ -->
<dependency>
    <groupId>org.webjars.bower</groupId>
    <artifactId>angular-sockjs-mit</artifactId>
    <version>0.1.0</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.bower/angular-sockjs-mit/
implementation 'org.webjars.bower:angular-sockjs-mit:0.1.0'
// https://jarcasting.com/artifacts/org.webjars.bower/angular-sockjs-mit/
implementation ("org.webjars.bower:angular-sockjs-mit:0.1.0")
'org.webjars.bower:angular-sockjs-mit:jar:0.1.0'
<dependency org="org.webjars.bower" name="angular-sockjs-mit" rev="0.1.0">
  <artifact name="angular-sockjs-mit" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.bower', module='angular-sockjs-mit', version='0.1.0')
)
libraryDependencies += "org.webjars.bower" % "angular-sockjs-mit" % "0.1.0"
[org.webjars.bower/angular-sockjs-mit "0.1.0"]

Dependencies

compile (1)

Group / Artifact Type Version
org.webjars.bower : angular jar [1,2)

Project Modules

There are no modules declared in this project.

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

Versions

Version
0.1.0