Meteor

An HTTP server for the 2.0 web

Welcome to Meteor - you're a star! (Learn more)
How to use the Meteor Javascript client to connect to a Meteor server

Dependencies

Before you can use Meteor in your page, you need to include the object library in the header of your HTML files. Meteor server hosts the Javascript client on its own host, and serves it directly, so there is no need to include any Meteor files in your web application.

Meteor presents itself to your application as a javascript object, so there is no need to instantiate it.

Properties

channelcount
Number of channels currently subscribed. Format: Integer, cannot set, read anytime
debugmode
Puts Meteor client in debug mode. If the console object exists, it writes to console, otherwise it looks for a DOM element with the ID 'meteorlogoutput' and appends to that. Format: Boolean, set anytime, read anytime
host
The host on which the Meteor server is listening for connections. Format: String, set before connect(), read anytime
port
The port on which the Meteor server is listening for connections. Format: String, Default: 80, set before connect(), read anytime
lastpingtime
Millisecond timestamp (ie. value of Date.getTime()) of the last ping received from the server. Format: integer, cannot set, read anytime
hostid
Unique identifier for this client, to prevent multiple Meteor connections being made from the same client to the same server (which would saturate the 2-connection limit in most browsers). It is normally sensible to generate this within the web application server-side, and to store it in the user's session. Format: integer, set before connect(), read anytime
minpollfreq
Absolute minimum number of milliseconds between polling requests, when Meteor is in polling mode and smart polling is enabled. Format: Integer, Default: 2000, set anytime, read anytime
maxpollfreq
Absolute maximum number of milliseconds between polling requests, when Meteor is in polling mode and smart polling is enabled. Format: Integer, Default: 60000, set anytime, read anytime
mode
Set to stream, simplepoll, smartpoll or longpoll. Meteor will auto-select the appropriate streaming transport for streaming connections, but you can override this by setting mode to iframe or xhrinteractive. If started in streaming mode, Meteor may fall back to smart polling mode if the stream is interrupted. Options: [stream|simplepoll|smartpoll|longpoll|xhrinteractive|iframe], Default: stream, set before connect(), read anytime
pingtimeout
Number of milliseconds to allow between pings before reverting a streaming connection to polling mode. Should be set to at least three times the ping interval defined in the Meteor server config. Format: integer, Default: 0, set anytime, read anytime
pollfreq
Number of milliseconds between polling requests, when Meteor is in polling mode. Will gradually drift from this starting value if in smartpoll mode. Format: Integer, Default: 2000, set anytime, read anytime
polltimeout
Number of milliseconds to allow for a polling request to return a response from Meteor server. In the case of long polling connections, this may be a long time so the value should be set high, whereas short polling connections will want a short timeout. Format: integer, Default: 30000, set anytime, read anytime
status
Current status of the client. Possible values are: 0 = Uninitialised, 1 = Loading stream, 2 = Loading controller frame, 3 = Controller frame timeout, 4 = Controller frame loaded and ready, 5 = Receiving data Format: integer, Default: 0, cannot set, read anytime

Methods

joinChannel(channelname, backtrack)
Adds channel channelname to the list of subscribed channels. If streaming has begun, this method will trigger a disconnect/reconnect to pick up the new channel. Will throw an error if the channel is already subscribed. backtrack is the number of previous messages to load when Meteor initially subscribes to the channel. Set to a non-numeric value to load all known events on the channel. Note: backtracking a new channel will not affect any ongoing subscriptions to other channels: the backtrack value is channel specific.
leaveChannel(channelname)
Drops channel channelname from the current Meteor channel list, and triggers a disconnect/reconnect to update the stream. Will throw an error if channelname is not in the channel list.
connect()
Establishes or re-establishes a connection with the Meteor server and begins streaming or polling, as appropriate.
disconnect()
Terminates streaming. Channel list is maintained and streaming will resume at the point it left off when connect() is next called.
registerEventCallback(evt, funcRef)
Maps a local function to a Meteor event. See below for details.

Events

process
Fired when an event message arrives. Arguments returned: data (String)

reset
Fired when Meteor reconnects a dropped stream. Arguments returned: none

eof
Fired when Meteor receives an end-of-file notification from the server (normally happens when the user opens a new window which initiates its own stream. Meteor will not allow any one user to have more than one active stream, so will send an eof() to the old one). Arguments returned: none

changemode
Fired when the interaction mode changes (currently only from stream to poll). Arguments returned: newmode (String)

Example