1.1.1 • Published 5 years ago

fpm-plugin-socket v1.1.1

Weekly downloads
-
License
MIT
Repository
-
Last release
5 years ago

fpm-plugin-socket

A plugin for Socket, It's only for a few datas( Normally < 20 bytes ).

We use it to build IOT project.

Transform with byte array like hex.

~Support CRC16 data compare.~

Basic Info

  • Run Action Hook Name: BEFORE_SERVER_START
  • ExtendModule Name: socket
  • Exception
    • Nope
  • getDependencies()
    • []
  • The Reference Of The Bind() Method An BizModule Object Contains those Functions
    • broadcast
    • send
    • getOnlineDevice
    • isOnline

Usage

  • SetEncoder/SetDecoder

    • setDataDecoder it must be return a Object{id, data}, and some crc16 compare, return undefined if crc16 error

      socketServer.setDataDecoder((src) => {
        // the last 2 bytes is the crc16 data
        let data = _.dropRight(src, 2)
        data = Buffer.from(data, 'hex')
      
        let id = Buffer.from(_.take(data, 2), 'hex').toString('hex')
        return {id, data}
      })
    • setDataEncoder

      Make sure return an Buffer Object

  • Broadcast message

    fpm.execute('socket.broadcast', message!Object, channel?Array, ids?Array) => Array

    • it always return a resolved Promise with the counter of success broadcast messages
  • Send message to The client

    fpm.execute('socket.send', id!String, message!HexString) => Promise

    • it return an reject if send error
  • Add channel for clients

    fpm.execute('socket.addChannel', channel!String, ids!Array) => Array

    • it return an array of addChannel success ok.
  • getOnlineDevice

    fpm.execute('socket.getOnlineDevice', message!Object) => Object

    • it returns the online devices
  • isOnline

    fpm.execute('socket.isOnline', id!String) => Number!0/1

    • it returns 1 which use the id is online
  • getClient

    fpm.execute('socket.getClient', id!String) => SocketClient

    • it returns socketClient of the online device with id
  • Subscribe Event To Receive Message

    • ##socket/receive
      			fpm.subscribe('#socket/receive', (topic, message) => {
      				console.info(message)
      			})
      			```
    • #socket/connect
      		fpm.subscribe('#socket/connect', (topic, message) => {
      			console.info(message);
      })
      /*
      { id: '0102',
      ip: '127.0.0.1',
      port: 41510,
      channel: [],
      tag: 'UN_TAGED',
      alias: 'UN_ALIAS',
      extend: {} }
      */
      		```
    • #socket/decode/error
      			fpm.subscribe('#socket/decode/error', (topic, data) => {
      				console.info(data)
      			})
      			```
    • #socket/close
      			fpm.subscribe('#socket/close', (topic, client) => {
      				console.info(client)
      			})
      			```
    • #socket/error
      			fpm.subscribe('#socket/error', (topic, error) => {
      				console.info(error)
      			})
      			``` 
1.1.1

5 years ago

1.1.0

5 years ago

1.0.10

5 years ago

1.0.9

5 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

0.0.12

6 years ago

0.0.11

6 years ago

0.0.10

6 years ago

0.0.9

6 years ago

0.0.8

6 years ago

0.0.7

6 years ago

0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago