Giter Site home page Giter Site logo

bugswarm-js's Introduction

BUGswarm Javascript Library

Connect your resources to BUGswarm and share their information with any web browser through our Javascript library. It is based on socket.io and supports a wide variety of browsers.

The library is distributed by our CDN and we really encourage you to use this version instead of linking it locally in your own application.

Link the library in your web application

<html>
    <head>
        <script type="text/javascript" src="http://cdn.buglabs.net/swarm/swarm-v0.4.0.js"></script>
    </head>
    <body>
        <script>
            /* Open this file twice or more with your browser and you should be able 
                to see your own presence messages in the developer 
                console of your browser. */
            function onPresence(presence) {
                console.log('presence -> ' + Date.now() + ':' + presence);
            }
        
            function onMessage(message) {
                console.log('message -> ' + Date.now() + ': ' + message);
            }

            //let's use information from our 'demo' account
            SWARM.connect({ apikey: '3e98ac6ca152f9bc279d0ef6e6bc9877e1508fd8', //participation key
                            resource: '0da7ce672f5a2e067ee8a0e050ca3e363283ea39', //your resource id that also is a member of your swarm
                            swarms: ['db07c1f9ff0628e33378cf39dc16df0755cdd3f0'], //your swarm
                            onmessage: onMessage, //your message function callback
                            onpresence: onPresence}); //our presence function callback
        </script>
    </body>
</html>

Fork it, improve it and send us pull requests.

git clone [email protected]:buglabs/bugswarm-api.git && cd bugswarm-api/javascript

License

(The MIT License)

Copyright 2011 BugLabs. All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

bugswarm-js's People

Contributors

barberdt avatar c4milo avatar chipkitreadonly avatar ckundo avatar santiago avatar theterg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bugswarm-js's Issues

Issues with private messaging in JavaScript API

In some instances, the sending a private message to another resource using the JavaScript API will cause that same message to come back to you, but sent from the resource you sent it to.

Known example: When you are send a private message to a resource that is connected to the swarm more than once (i.e. multiple instances of the webUI).

Node.js Participation library has issues processing multiple (~5+) connections at once.

In the process of developing stress tests for the BUGswarm platform, I discovered that when trying to create 5 or more connections to the same swarm essentially simultaneously using the participation library, I receive the following exception:

https://gist.github.com/44746ce80692d7c9f78e

The code I am using to test is below:
https://gist.github.com/b8dd9ab032fec3a7b876

Note that any less than 5 connections does not produce the exception.

Option "public: true" to replace resource "web"

The quickest setup for producing and consuming data is currently:

  1. Signup on bugswarm.net / community.buglabs.net
  2. Get an api key with your username/password
  3. Use api key to create a swarm
  4. Use api key to create a resource of type 'web'
  5. Use api key to add that resource web to that swarm
  6. Use library to join that swarm

To make this easier, I suggest the option 'public: true' to replace steps 4 and 5:

  1. Signup on bugswarm.net / community.buglabs.net
  2. Get an api key with your username/password
  3. Use api key to create a swarm, with "public: true"
  4. Use library to join that swarm

Correlation Between CDN and Github

Attempting to get started using the javascript library, i'm not seeing a correlation between the code in github and the code hosted on the CDN. It would be useful for these to be linked, so that we can update the example code and keep it up to date with the library.
@aturley @santiago

develop nodejs version of swarm client

I'm developing tests for the http streaming api and I'd like to develop the nodejs library for swarm to avoid re-doing the wheel every time I want to use the http streaming API.

support to send binary files

Request example made with Curl

camilo@buggersillo:~/Downloads> 
curl -vvv -H 'x-bugswarmapikey: 04ce03e9ae36cfae8c240ca4ead74412cd969c62' -F [email protected] \
-F resource_id='8f44aae9cc4494f8d07cf50769b59aa85b53d24c' http://api.dev.bugswarm.net/upload
* About to connect() to api.dev.bugswarm.net port 80 (#0)
*   Trying 127.0.0.1... connected
* Connected to api.dev.bugswarm.net (127.0.0.1) port 80 (#0)
> POST /upload HTTP/1.1
> User-Agent: curl/7.21.2 (x86_64-apple-darwin10.5.0) libcurl/7.21.2 OpenSSL/1.0.0d zlib/1.2.5 libidn/1.20
> Host: api.dev.bugswarm.net
> Accept: */*
> x-bugswarmapikey: 04ce03e9ae36cfae8c240ca4ead74412cd969c62
> Content-Length: 2036
> Expect: 100-continue
> Content-Type: multipart/form-data; boundary=----------------------------4a7e9cbbfd2d
> 
< HTTP/1.1 100 Continue
< HTTP/1.1 201 Created
< x-powered-by: BSS v1.0
< location: http://api.dev.bugswarm.net/files/key2.pem
< content-type: text/plain
< content-length: 7
< connection: close
< 
* Closing connection #0
Created

i can't join more than one Swarm using JS API

Here https://github.com/buglabs/bugswarm-webui/blob/0.2.1/public/javascripts/bugswarm.js#L76;
where I'm passing an Array with more than one (1) Swarm to SWARM.connect, it results in this error:

The Array of Swarms ...

["dbb78ebb437970291aef968803cc67ace9d7a742", "ff0121226c42869f08948098415be99382818d54",
"dc92b3405e4ad5dee9a35864583b2e768a85a3f7", "ebc7b30beac7e242a97b652eb88e27a8a11af3c2", 
"cde3c7ca4472e5a641487e31fd61a412a525b998", "4fee0b949c7e591b708a841ffceb72e5c33138af"]


The error ...

bugswarm.js:62error! -> [{"code":"028","description":"Swarm     
dbb78ebb437970291aef968803cc67ace9d7a742,ff0121226c42869f08948098415be99382818d54,dc92b3405e4ad5dee9a35
864583b2e768a85a3f7,ebc7b30beac7e242a97b652eb88e27a8a11af3c2,cde3c7ca4472e5a641487e31fd61a412a525b998,4f
ee0b949c7e591b708a841ffceb72e5c33138af does not exists or your resource is not allowed to participate in it."}]

Due to this failure, I tried using SWARM.connect passing only the first Swarm from the Array ...

https://github.com/buglabs/bugswarm-webui/blob/0.2.1/public/javascripts/bugswarm.js#L77

... and then, onConnect, I tried passing the same Array to SWARM.join

https://github.com/buglabs/bugswarm-webui/blob/0.2.1/public/javascripts/bugswarm.js#L45

... but it doesn't to appear be joining the passed Swarms because they don't get presence from resources connected to them.

Finally I tried joining Swarms one by one ...

https://github.com/buglabs/bugswarm-webui/blob/0.2.1/public/javascripts/bugswarm.js#L51

... which apparently joins the passed Swarm because I do get presence from the resources connected to it.

    function onConnect() {
        $(".loading").fadeOut();

        // SWARM.join(swarms);
        /*
            Passing an array to SWARM.join doesn't appear to be joining the passed 
            Swarms because they don't get presence from resources connected to them
        */

        swarms.forEach(function(s) {
                SWARM.join(s)
        });
        /*
            Passing only one Swarm to SWARM.join does appear to be joining the passed Swarm
            because I do get presence from the resources connected to it
        */
    }

However, and this is important, I'm only seeing messages sent to the first Swarm of the Array, that is, the one used in SWARM.connect

Wrap REST api in javascript

I propose methods (create, list, update, destroy, add, etc...) that take the same json as the REST api.

This will make it easy to stay with the same language instead of relying on external tools (bugswarm-tools, curl, bug management UI).

Create a swarm

SWARM.create({ "swarm": {
    "name": "My Swarm",
    "description": "My Swarm Description",
    "public": false
} })

Destroy a resource

SWARM.destroy({ "resource": {
    "id": "my unique resource id",
    "name": "My resource",
    "machine_type": "pc",
    "description": "My Resource description",
    "position": {
                    "longitude": 0,
                    "latitude": 0
    }
}})

Add a resource to a swarm

SWARM.add("$SWARM_ID", { "resource": {
     "user_id": "username",
     "resource": "My Resource id",
     "type": "consumer"
 }})

Not sure what the best mapping is from REST to the javascript api, but this is a start.

Reorganize bugswarm-api

Other services split each api by language/platform.

I suggest we do the same. Argue why its a bad idea.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.