transport-layer
v0.0.1transport-layer
The transport-layer
module is a base class or common layer for real-time
transports. Having a shared layer makes it easier for people to create custom
transports which can be used by frameworks that depend on transports with this
base layer.
Please note that is module is designed to be a dependency of a transport not as transport it self.
We have some specific goals we're trying to figure out:
- Know if a transport can be used in a cross domain/port/protocol environment
- If the transport is supported by the by the current environment (browser/node/js-engine)
- Know the capabilities of the transport can it write/receive data and does it support binary.
- At what state of the environment is it save to use this transport.
Installation
This module is intended to be used on the browser using Browserify and Node.js and distributed in the public npm registry. It can be installed by running:
npm install --save transport-layer
Events
Event | Description |
---|---|
initialize |
The instance has been fully initialized. |
url:modify |
Last chance to modify the URL before it a string. |
url |
Complete URL that we're about to request. |
timeline |
Register a new event in our timeline. |
log |
Debug/log message from the framework. |
log:<severity> |
Specifically listen to certain log messages. |
Implementing a transport
Before we're going to get started we going to assume that you've already
required the transport-layer
as following:
'use strict';
var TL = require('transport-layer');
We're just going to call it TL
as it's shorter and easier to write then
TransportLayer
every single time. In this example we're going to implement a
WebSocket based transport.
To implement your own real-time transport you need to extend the
transport-layer
instance. We follow the same pattern as you might have used in
Backbone.js which is a special .extend
function which allows you to create a
class of your own which correctly inherits all properties and prototypes from
the transport-layer class. The extend method requires 2 arguments:
object
, Properties and methods that need to be added on theprototype
of yourtransport-layer
instance.object
, Properties that need to be added to the constructor of your instance. There are a few mandatory properties that need to be set in order for people to figure out if they can use your instance to communicate.
var WebRocket = TL.extend({}, {
crossdomain: true, // Cross domain enabled.
supported: 'WebSocket' in window, // Supported in this browser.
writable: true, // Transport can send data to server.
readable: true, // Transport can receive data from server.
binary: true // We can tranfer binary data.
});
License
MIT
Metadata
- MIT
- Whatever
- Arnout Kazemier
- released 11/17/2014