1.0.58 • Published 5 years ago

blacksocket.io v1.0.58

Weekly downloads
6
License
MIT
Repository
github
Last release
5 years ago

blacksocket.io

A websocket wrapper. Basically compatiable with socket.io.

Travis NPM version Coverage Status Gzip Size dependencies Status contributors GitHub license

  • Lightweight
  • Callback
  • Auto reconnection
  • Object sending
  • Binary sending (even in object) (even in callback)
  • Once
  • Promise

Install

Server

npm i -S blacksocket.io

Client

Install with npm
npm i -S blacksocket.io
Use script file directly

Just for testing

<script src="https://raw.githubusercontent.com/blackmiaool/blacksocket.io/master/client/blacksocket.min.js"></script>

Usage

I have no time for writing a whole documentation for it. If you want to use it, I personally recommend you to read the test/test.js file to get all the demos.

Server

// initialize with port and path
const io = require("blacksocket.io/server")(23033, {
    path: "/test"
});
io.on("connection", function(socket) {
    console.log("socket connection");
    // listen client event
    socket.on("client-event", function(params, cb) {
        console.log("client-event", params);
        cb({ a: "it's an object" });
    });
    setInterval(() => {
        // send event to client
        socket.emit("server-event", { a: "server params" }, function(params) {
            // receive a callback
            console.log("server-event cb", params);
        });
    }, 3000);
});

Client (nodejs or browser)

const io = require("blacksocket.io/client");
// initialize with port and path
const socket = io(`:23033/test`);

// first-connect: triggered on first connection
// connect: triggered on every successful connection(including reconnection)
// reconnection event: triggered on reconnection
socket.on("first-connect", function() {
    console.log("connected");
    setInterval(() => {
        // send event to server
        socket.emit("client-event", { a: "client params" }, function(cbParams) {
            // receive a callback
            console.log("client-event cb", cbParams);
        });
    }, 1000);
});

socket.on("server-event", function(params, cb) {
    console.log("server-event", params);
    // invoke the callback to return some data to server
    cb({ a: "server-event cb" });
});

Try it with docker

docker run -it --rm -p 23034:80 -p 23033:23033 blackmiaool/blacksocket.io

Open the website

About document

1.0.58

5 years ago

1.0.57

5 years ago

1.0.56

5 years ago

1.0.55

5 years ago

1.0.54

6 years ago

1.0.53

6 years ago

1.0.52

6 years ago

1.0.51

6 years ago

1.0.50

6 years ago

1.0.49

6 years ago

1.0.48

6 years ago

1.0.47

6 years ago

1.0.46

6 years ago

1.0.45

6 years ago

1.0.43

6 years ago

1.0.42

6 years ago

1.0.41

6 years ago

1.0.40

6 years ago

1.0.39

6 years ago

1.0.38

6 years ago

1.0.37

6 years ago

1.0.36

6 years ago

1.0.35

6 years ago

1.0.33

6 years ago

1.0.32

6 years ago

1.0.31

6 years ago

1.0.30

6 years ago

1.0.29

7 years ago

1.0.28

7 years ago

1.0.27

7 years ago

1.0.26

7 years ago

1.0.25

7 years ago

1.0.24

7 years ago

1.0.23

7 years ago

1.0.22

7 years ago

1.0.21

7 years ago

1.0.20

7 years ago

1.0.19

7 years ago

1.0.18

7 years ago

1.0.17

7 years ago

1.0.16

7 years ago

1.0.15

7 years ago

1.0.14

7 years ago

1.0.13

7 years ago

1.0.12

7 years ago

1.0.11

7 years ago

1.0.10

7 years ago

1.0.9

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago