1.1.0 • Published 1 month ago

@sqwad/direct-flow v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 month ago

Sqwad DirectFlow Client Javascript / Typescript library

Instant bidirectional interactions made easy !

Note: we use socket.io library for client layer with auto-reconnect and WebSocket / Long polling usage.

The library is coded on typescript so all types are defined, except for custom ones.

CDN Use

<script src="https://cdn.jsdelivr.net/npm/@sqwad/direct-flow" crossorigin="anonymous"></script>
<script>
  const d = new DirectFlow('your-uuid', 'client-key')

  d.broadcast('Hello world')

  d.onMessage((message) => {
    console.log(message)
  })
</script>

Installation

yarn add @sqwad/direct-flow

or

npm install @sqwad/direct-flow

Javascript Usage

<script type="module">
    import {DirectFlow} from '@sqwad/direct-flow'

    const d = new DirectFlow('your-uuid', 'client-key')

    d.broadcast('Hello world')

    d.onMessage((message) => {
        console.log(message)
    })
</script>

Event driven usage

<script type="module">
    import {DirectFlow} from '@sqwad/direct-flow'

    const d = new DirectFlow('your-uuid', 'client-key')

    d.broadcast('Hello world')

    // Instantiate all event dispatchers
    d.onMessage()

    addEventListener(DirectFlowEventType.GLOBAL, (message) => console.log(message))
</script>

Methods

  • connect: connect to server (not needed, connected in constructor)
  • release: disconnect from server
  • broadcast: send message to anyone except us (can be string or object)
  • send: broadcast alias
  • sendTo: send to specific client
  • sendToChannel: send to channel on server (can be string or object)
  • rawSend: send any data to server, but need to be an object
  • subscribe: listen to one or more specific channel (string or object)
  • unsubscribe: stop listening for one or more specific channel (string or object)
  • onMessage: action to do when receiving message, parameter is optional and instantiate event dispatchers, you should call once only.
1.1.0

1 month ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago