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
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.
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
||The instance has been fully initialized.|
||Last chance to modify the URL before it a string.|
||Complete URL that we're about to request.|
||Register a new event in our timeline.|
||Debug/log message from the framework.|
||Specifically listen to certain log messages.|
Implementing a transport
Before we're going to get started we going to assume that you've already
transport-layer as following:
'use strict';var TL = ;
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 the
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;