| 64 | } |
| 65 | |
| 66 | private _dispatchEvent(channel:string, data:OOAPIMessage):void { |
| 67 | if (channel in this._channels) { |
| 68 | if (this._channels[channel].length === 0) { |
| 69 | if (typeof this._defaultChannelListener === 'function') { |
| 70 | this._defaultChannelListener(data); |
| 71 | } else { |
| 72 | throw new NoHandlerError(data); |
| 73 | } |
| 74 | return; |
| 75 | } |
| 76 | for (var i = 0; i < this._channels[channel].length; i++) { |
| 77 | this._channels[channel][i](data); |
| 78 | } |
| 79 | } else { |
| 80 | if (typeof this._defaultChannelListener === 'function') { |
| 81 | this._defaultChannelListener(data); |
| 82 | } else { |
| 83 | throw new NoHandlerError(data); |
| 84 | } |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | public send(message:OOAPIMessage):void { |
| 89 | this._worker.postMessage(JSON.stringify(message)); |