joewalnes / reconnecting-websocket

A small decorator for the JavaScript WebSocket API that automatically reconnects
MIT License
4.24k stars 967 forks source link

Error when loaded via RequireJS #24

Open yokujin opened 10 years ago

yokujin commented 10 years ago

When loaded via RequireJS I get the following error: ReconnectingWebSocket is not defined

When I commented out if branch which checks for define and define.amd it started work like a charm.

fdurden commented 9 years ago

For me the 1.0.0 works fine. You have to use the amd dependency injected object as the ReconnectingWebSocket constructor. So if you define the requireJs dependency as:

'reconnecting-websocket': ['lib/reconnecting-websocket/reconnecting-websocket'],

and then wherever you need it use the name you used as alias:

(function(){
  'use strict';
  define('ngservices', ['angular', 'reconnecting-websocket'], function(angular, InjectedReconnectingWs){
...

// var ws = new ReconnectingWebSocket('ws://...') // WRONG
var ws = new InjectedReconnectingWs('ws://...') // RIGHT