jquery-simple-websocket

WebJar for jquery-simple-websocket

License

License

MIT
Categories

Categories

Github Development Tools Version Controls
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

github-com-jbloemendal-jquery-simple-websocket
Last Version

Last Version

1.1.2
Release Date

Release Date

Type

Type

jar
Description

Description

jquery-simple-websocket
WebJar for jquery-simple-websocket
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/jbloemendal/jquery-simple-websocket

Download github-com-jbloemendal-jquery-simple-websocket

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/github-com-jbloemendal-jquery-simple-websocket/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>github-com-jbloemendal-jquery-simple-websocket</artifactId>
    <version>1.1.2</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/github-com-jbloemendal-jquery-simple-websocket/
implementation 'org.webjars.npm:github-com-jbloemendal-jquery-simple-websocket:1.1.2'
// https://jarcasting.com/artifacts/org.webjars.npm/github-com-jbloemendal-jquery-simple-websocket/
implementation ("org.webjars.npm:github-com-jbloemendal-jquery-simple-websocket:1.1.2")
'org.webjars.npm:github-com-jbloemendal-jquery-simple-websocket:jar:1.1.2'
<dependency org="org.webjars.npm" name="github-com-jbloemendal-jquery-simple-websocket" rev="1.1.2">
  <artifact name="github-com-jbloemendal-jquery-simple-websocket" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='github-com-jbloemendal-jquery-simple-websocket', version='1.1.2')
)
libraryDependencies += "org.webjars.npm" % "github-com-jbloemendal-jquery-simple-websocket" % "1.1.2"
[org.webjars.npm/github-com-jbloemendal-jquery-simple-websocket "1.1.2"]

Dependencies

compile (1)

Group / Artifact Type Version
org.webjars.npm : jquery jar 3.2.0

Project Modules

There are no modules declared in this project.

npm version travis

jQuery Simple WebSocket

Send and receive data through a fluent interface, reconnect automatically.

Example

<script type="text/javascript" src="https://code.jquery.com/jquery-3.2.0.min.js"></script>
<script type="text/javascript" src="jquery.simple.websocket.js"></script>
<script type="text/javascript">
    var webSocket = $.simpleWebSocket({ url: 'ws://127.0.0.1:3000/' });

    // reconnected listening
    webSocket.listen(function(message) {
        console.log(message.text);
    });

    webSocket.send({ 'text': 'hello' }).done(function() {
        // message send
    }).fail(function(e) {
        // error sending
    });
</script>

fluent:

var webSocket = $.simpleWebSocket({ url: 'ws://127.0.0.1:3000/' })
.listen(function(message) { console.log('listener1: '+message.text); })
.listen(function(message) { console.log('listener2: '+message.text); })
.listen(function(message) { console.log('listener3: '+message.text); })
.send({'text': 'hello'});

Usage

var socket = $.simpleWebSocket(
    {
        url: 'ws://127.0.0.1:3000/',
        protocols: 'your_protocol', // optional
        timeout: 20000, // optional, default timeout between connection attempts
        attempts: 60, // optional, default attempts until closing connection
        dataType: 'json', // optional (xml, json, text), default json
        onOpen: function(event) {}, // optional event listener
        onClose: function(event) {}, // optional event listener
        onError: function(event) {}, // optional event listener
    }
);

socket.connect();

socket.isConnected(); // or: socket.isConnected(function(connected) {});

socket.send({'foo': 'bar'});

socket.listen(function(data) {});

socket.remove(listenerCallback);

socket.removeAll();

socket.close();

Web Chat Example

  • start nodejs websocket server:
$ node src/server.js
  • open example/example.html

History

Versions

Version
1.1.2