0.8.3 • Published 8 years ago

transmit v0.8.3

Weekly downloads
40
License
-
Repository
github
Last release
8 years ago

Transmit

npm install transmit

Transmit is two things:

  • Abstractions on top of the ws library
  • A similar set of abstractions for the client, automatically exposed

The server

var express = require('express')
,   app = express.createServer()

var lactate = require('lactate').Lactate({
    expires:'two days'
})

app.get('/', function(req, res) {
  return lactate.serve('index.html', req, res)
})

app.listen(8080)

var transmit = require('transmit')()

transmit.on('connection', function(socket) {

  socket.on('someEvent', function(data) {

    socket.send('someResponseEvent', {
        success:true
    })

  })

})

transmit.listen(app)

The client

<!doctype html>

<html>

  <head>

    <title>Transmit example</title>
    <script src='/transmit'></script>

  </head>

  <body>

    <script>

      transmit.once('open', function() {

          transmit.on('someResponseEvent', function(data) {
            console.log('someResponseEvent!', data)
            //{success:true}
          })

          transmit.send('someEvent', ':|')
      })

      transmit.connect('localhost:8080')

    </script>

  </body>

</html>

Options

To set ws options, you may pass them to the initialization function like so

var transmit = require('transmit')({port:2112})

You can find all of the available options here along with one exception: client_script. This option represents the name with which to expose the client script, by default, as shown in the above example, transmit.

var id = 'to_defy_the_laws_of_tradition_is_a_crusade_only_of_the_brave'

var transmit = require('transmit')({
    'client_script':id
})

/*
    The script can now be accessed from 
    /to_defy_the_laws_of_tradition_is_a_crusade_only_of_the_brave
*/
0.8.3

8 years ago

0.8.2

8 years ago

0.8.1

8 years ago

0.8.0

8 years ago

0.7.5

8 years ago

0.7.4

8 years ago

0.7.3

8 years ago

0.7.2

9 years ago

0.7.1

9 years ago

0.7.0

9 years ago

0.6.11

9 years ago

0.6.10

9 years ago

0.6.9

9 years ago

0.6.8

9 years ago

0.6.7

9 years ago

0.6.6

9 years ago

0.6.5

9 years ago

0.6.3

9 years ago

0.6.2

9 years ago

0.6.1

9 years ago

0.6.0

9 years ago

0.5.5

9 years ago

0.5.4

9 years ago

0.5.3

9 years ago

0.5.2

9 years ago

0.5.0

9 years ago

0.4.8

9 years ago

0.4.5

9 years ago

0.4.4

9 years ago

0.4.2

9 years ago

0.4.0

9 years ago

0.3.4

9 years ago

0.3.2

9 years ago

0.3.0

9 years ago

0.2.5

9 years ago

0.2.4

9 years ago

0.2.2

9 years ago

0.2.0

9 years ago

0.1.4

9 years ago