New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

slimp3-server

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

slimp3-server

implements the slimp3 client protocol in nodejs

latest
Source
npmnpm
Version
1.0.1
Version published
Weekly downloads
3
50%
Maintainers
1
Weekly downloads
 
Created
Source

SliMP3-Server

slimp3-server implements the SliMP3 Client Protocol in NodeJS. The package was designed to reflect the structure of the standard tcp socket server.

Picture of slimp3 device

This server only supprots the orinigal SliMP3 Client Protocol, meaning it only supports a limited number of devices. It has only been tested with the device pictured above.

Quick Start

This section will show you how to install, and provide basic usage for slimp3-server

Install:

npm install slimp3-server

Require:

const slimp3 = require('slimp3-server')

Creating a server

// create an instance of the server class
var server = new slimp3.Server()

// setup listening event
server.on('listening', function(){
  console.log(`listening on ${server.address().address}:${server.address().port}`)
})

// setup error event
server.on('error', function(err){
  console.error(err)
})

// event for new clients
// the callback for this event should accept an instance of the Client class
server.on('connection', async function(client){
  console.log('new connection')
  client.send('hi!')
})

// start listening on the server
server.bind() // Server.bind() accepts a port and address to listen on, if none is give it will default to 3483

Reciving IR Remote Data

client.get_ir() returns a promise fufilled by the next IR Code

client.setIrRepeatRate(<rate in ms>) sets the number of milliseconds that must pass between button presses

eg:

/// ... create a server ...

server.on('connection', async function(client){
  // this sets the number of milliseconds that must pass since the last button was pressed
  client.setIrRepeatRate(250) // (this is defualt value)
  // this function will return a promise that will be fulfilled when the next IR Code is recived
  // in practice you would probably want to wrap this in a try-catch statement
  console.log('Recived IR Code', await client.get_ir())
})

Mapping Ir Codes

Client.mapper allows you to map ir codes to key strings.

Default Sony Universal Remote (With JVC Codes)

The remote included with slimp3 is a sony universal remote, slimp3 uses the JVC mode that can be set by pressing:

  • S
  • DVD
  • 0 0 7
  • ENT
  • DVD
  • By default clients will map ir codes for the included remote.
server.on('connection', async function(client){
  // this function will return a promise that will be fulfilled when the next IR Code is recived
  var code = await client.get_ir()

  // if the code is unknown this will return 'unmapped'
  var key = client.mapper.map(code)

  // test if the key is in a group
  var bool = client.mapper.group('enter', key)
})
Non-Standard Remote

Create a mapper:

const mapper = new slimp3.Mapper({
  // key mapping
  <ir_code>: '<key string>',
}, {
  // key groups
  yes: ['<key_string>'],
  no: ['<key_string>'],
  enter: ['<key_string>'],
  // ect...
})

Attach a mapper to a client:

server.on('connection', async function(client){
  client.mapper = mapper
})

IR Callback

You can also recive ir codes via callback:

server.on('connection', async function(client){
  client.irCallback = function(code){
    // if the function returns false, the code will be ignored, and will not fufill the ir promise
    // this can be usefull for catching specific ir codes like `power` and `sleep`
    return true
  }

Menu Building

Pause

server.on('connection', async function(client){
  // pauses on any mapped key
  await client.pauseAny()

  // pauses on a key in a group
  await client.pauseGroup('yes')
})

Read A Digit Key

server.on('connection', async function(client){
  const digit = client.readDigit()
  client.send('you pressed: ', digit)
})

Menu

const menu = ['Item1', 'Item2', 'Item 3', 'Fourth Item']

server.on('connection', async function(client){
  const index = await client.menu(menu, 'Choose an item')
  const item = menu[index]
  client.send('you chose: ' + item)
})

Further Reading

  • SliMP3 Protocol Page
  • Wireshark Protocol Page
  • Slimp3 Instructions

Data Sheets

VFD-Codes

Keywords

slimp3

FAQs

Package last updated on 16 Feb 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts