0.8.3 • Published 12 years ago

transmit v0.8.3

Weekly downloads
196
License
-
Repository
github
Last release
12 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

12 years ago

0.8.2

12 years ago

0.8.1

12 years ago

0.8.0

12 years ago

0.7.5

12 years ago

0.7.4

12 years ago

0.7.3

12 years ago

0.7.2

12 years ago

0.7.1

12 years ago

0.7.0

12 years ago

0.6.11

12 years ago

0.6.10

12 years ago

0.6.9

12 years ago

0.6.8

12 years ago

0.6.7

12 years ago

0.6.6

12 years ago

0.6.5

12 years ago

0.6.3

12 years ago

0.6.2

12 years ago

0.6.1

12 years ago

0.6.0

12 years ago

0.5.5

12 years ago

0.5.4

12 years ago

0.5.3

12 years ago

0.5.2

12 years ago

0.5.0

12 years ago

0.4.8

12 years ago

0.4.5

12 years ago

0.4.4

12 years ago

0.4.2

12 years ago

0.4.0

12 years ago

0.3.4

12 years ago

0.3.2

12 years ago

0.3.0

12 years ago

0.2.5

12 years ago

0.2.4

12 years ago

0.2.2

12 years ago

0.2.0

12 years ago

0.1.4

12 years ago