Mercurial > pub > ImplabJs
diff src/implab/messaging/Destination.js @ 0:fc2517695ee1
Initial commit, draft import of existing work
author | cin |
---|---|
date | Thu, 01 Jun 2017 13:20:03 +0300 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/implab/messaging/Destination.js Thu Jun 01 13:20:03 2017 +0300 @@ -0,0 +1,34 @@ +define([ "dojo/_base/declare", "./Listener" ], + +function(declare, Listener) { + return declare(null, { + _session : null, + _destination : null, + _listenerClass : null, + + constructor : function(session, destination, options) { + if (!session) + throw new Error("A session is required"); + if (!destination) + throw new Error("A destination is required"); + + this._session = session; + this._destination = destination; + if (options) { + if (options.listenerClass) + this._listenerClass = options.listenerClass; + } + }, + + listen : function(callback) { + var factory = this._listenerClass || Listener; + var listener = new factory(this._session, this._destination, { + listener : callback + }); + listener.start(); + + return listener; + } + + }); +});