angular-ws

WebJar for angular-ws

Лицензия

Лицензия

MIT
Категории

Категории

Angular Взаимодействие с пользователем Веб-фреймворки
Группа

Группа

org.webjars.bower
Идентификатор

Идентификатор

angular-ws
Последняя версия

Последняя версия

1.1.0
Дата

Дата

Тип

Тип

jar
Описание

Описание

angular-ws
WebJar for angular-ws
Ссылка на сайт

Ссылка на сайт

http://webjars.org
Система контроля версий

Система контроля версий

https://github.com/neoziro/angular-ws

Скачать angular-ws

Как подключить последнюю версию

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

Зависимости

compile (1)

Идентификатор библиотеки Тип Версия
org.webjars.bower : angular jar [1.2.23,1.3)

Модули Проекта

Данный проект не имеет модулей.

angular-ws

This plugin is no longer actively maintained, you can still use it but issues will not be resolved. If you want the npm name, you can contact me by email.

Build Status Dependency Status devDependency Status

WebSocket service for Angular.js.

Install

bower install angular-ws

Usage

angular.module('app', ['ws'])
.config(function (wsProvider) {
  wsProvider.setUrl('ws://echo.websocket.org');
})
.controller('WebSocketCtrl', function ($scope, ws, $log) {
  ws.on('message', function (event) {
    $log.info('New message', event.data);
  });

  ws.send('custom message');
});

Provider

wsProvider.setUrl(url)

Set the url of the WebSocket.

wsProvider.setUrl('ws://echo.websocket.org');

wsProvider.setProtocols(protocols)

Set the protocols used by the WebSocket.

wsProvider.setProtocols(['protocol']);

wsProvider.setTransport(transport)

Set a custom transport (example: ReconnectingWebSocket).

wsProvider.setTransport(ReconnectingWebSocket);

Service

ws.connect([config])

Connect the WebSocket, you can provide a custom config.

Note that if you use ws.on or ws.send the connection is automatic.

ws.connect({
  url: 'ws://echo.websocket.org',
  protocols: ['protocol']
})
.then(function () {
  $log.debug('WebSocket is connected.');
}, function () {
  $log.debug('An error occurs during WebSocket connection.');
});

ws.baseSocket

The base socket object.

ws.baseSocket.onmessage = function (event) {
  // event.data ...
}

ws.getReadyState()

Get the ready state of the WebSocket.

ws.getReadyState() // WebSocket.CLOSED, WebSocket.OPEN...

ws.on(event, listener)

Listen an event on the WebSocket, the function is already wrapped in $rootScope.$apply().

ws.on('message', function (event) {
  $log.info('New message', event.data);
});

ws.close()

Close the connection of the WebSocket.

ws.close();

Testing

To be able to test WebSocket in the good way, the module angular-ws-mock will provide you a transparent mock.

License

MIT

Версии библиотеки

Версия
1.1.0