Commit Graph

26 Commits

Author SHA1 Message Date
Stein Magnus Jodal
d15c7d0797 js: Log warning if calling convention is not explicitly set 2014-06-20 11:16:46 +02:00
Stein Magnus Jodal
c5028a8576 js: Fix console setup, allow mocking of the console 2014-06-20 11:16:15 +02:00
Stein Magnus Jodal
225f41f999 js: Add by-position-or-by-name calling convention
Fixes #699
2014-06-18 23:27:07 +02:00
Stein Magnus Jodal
149287c06a js: Don't include params if method is called without arguments 2014-06-18 22:22:42 +02:00
Stein Magnus Jodal
858a6977df js: Add callingConvention setting
For now it defaults to the existing behavior "by-position-only" and changing it
has no effect.
2014-06-17 20:57:55 +02:00
Stein Magnus Jodal
198bd8af6c js: Use .catch() to simplify error handling 2014-06-17 20:41:35 +02:00
Stein Magnus Jodal
13205bee5f js: Connect to /mopidy/ws without trailing slash
This is the recommended URL since the switch to Tornado as web server.
2014-06-15 23:43:44 +02:00
Stein Magnus Jodal
30471bab74 js: Add ServerError and ConnectionError types 2014-06-15 23:43:43 +02:00
Stein Magnus Jodal
026fdb38a3 js: Reject promises using Error objects
This is recommended to get proper stack traces, according to
https://github.com/cujojs/when/blob/master/docs/api.md#a-note-on-javascript-errors.

The new Error objects has the exact same properties as the objects we used to
reject promises previously, thus this should be fully backwards compatible, but
improve debuggability.
2014-06-15 23:43:39 +02:00
Stein Magnus Jodal
4a609ce95d js: Add TODOs for rejecting promises with Error
This is recommended to get proper stack traces, according to
https://github.com/cujojs/when/blob/master/docs/api.md#a-note-on-javascript-errors
2014-06-15 12:31:52 +02:00
Stein Magnus Jodal
cb04b81bf4 js: Simplify _send() rejections 2014-06-15 12:16:39 +02:00
Paul Connolley
418e5689dc Preliminary commit for browserify compatibility
This is the first stage of my commits for issue #609 that will make the
npm module browserify friendly and browser friendly.

The grunt-browserify module has been introduced to replace
grunt-contrib-concat. Browserify automatically concatenates files and so
there is no need for a concat step.

The faye-websocket module was problematic so I moved the require out to
a separate module within the lib directory. The websocket module is a
folder containing a package.json, directing library consumers to the
entry point that is appropriate for their environment. Browserify picks
browser.js (which simply returns an object holding window.WebSocket)
while everyone else gets the faye-websocket module.

In addition, as browserify handles all the requires, there's no need to
detect the environment or include any pre-built modules. I've removed
the pre-built when and faye-websocket files in favour of letting
browserify use the modules within node_modules. This should make it
easier to maintain dependencies in future versions of this library.

One side effect of this browserify compatibility is that, in order to
allow the library to be globally available in the browser as `Mopidy`,
I've had to set Mopidy as the exported object instead of as a key of the
exported object. To elaborate further, the current API would be like the
following:

    var Mopidy = require('mopidy').Mopidy;

However, with this change, the API would be like this:

    var Mopidy = require('mopidy');

I'm not sure whether this would be an issue and so I think it's worth
discussing further. It's possible that node developers won't have a
problem but, if they did, a potential workaround within the mopidy.js
file would be:

   Mopidy.Mopidy = Mopidy;

This would allow developers to choose either of the following:

    var Mopidy = require('mopidy');
    var Mopidy = require('mopidy').Mopidy;

Could be a little odd to do this though

When testing the browserify build, I noticed a strange error thrown when
making the initial websocket connection. I managed to track it down to
an IE 'feature' that crops up when you alias in-built functions. In
particular, the when module was aliasing setImmediate to an internal
function (nextTick.) In a newer version of when, the function is
instead aliased to the browserify process.nextTick. This works well
because substack already had that covered.

With when@2.7.0, IE11 appears to be working well. IE10 is still pending
a test.
2013-12-15 01:52:24 +00:00
Stein Magnus Jodal
bc78a65fff js: Upgrade when.js from 1.8.1 to 2.0.0 2013-03-31 14:09:32 +02:00
Stein Magnus Jodal
74b4fdc7ee js: Make test suite run on Node.js using faye-websocket 2013-03-29 13:51:28 +01:00
Stein Magnus Jodal
a032e45c35 js: Make 'Mopidy()' work without 'new' 2013-01-16 22:55:21 +01:00
Stein Magnus Jodal
b14c89dbf1 js: Make connect() public, and document autoConnect/connect() 2012-12-04 13:23:43 +01:00
Stein Magnus Jodal
8d3fd46808 js: Add close() method to close WebSocket without reconnecting 2012-12-04 09:18:34 +01:00
Stein Magnus Jodal
7f570de239 js: Polyfill console inside our own namespace 2012-12-01 17:18:06 +01:00
Stein Magnus Jodal
3c56f6cbce js: Use and all over 2012-11-30 12:04:47 +01:00
Stein Magnus Jodal
0e799c2795 js: Formatting 2012-11-30 11:23:48 +01:00
Stein Magnus Jodal
cb9b0f6ba1 js: Simplify configure function 2012-11-30 11:22:13 +01:00
Stein Magnus Jodal
08dcfd56b1 js: Extract configuration function 2012-11-30 11:16:42 +01:00
Stein Magnus Jodal
3045ac0158 js: Add description and params list to API functions 2012-11-30 02:41:39 +01:00
Stein Magnus Jodal
fc9ab6053a js: Make backoff delay limits settings 2012-11-30 02:18:08 +01:00
Stein Magnus Jodal
12f60f3a52 js: Add fully working core API in JavaScript 2012-11-30 02:05:40 +01:00
Stein Magnus Jodal
defc44b747 js: Add empty source and test files 2012-11-29 00:21:16 +01:00