Giter Club home page Giter Club logo

core-websocket's Introduction

#core-websocket

A polymer websocket adapter that provides a declarative way to drop reconnecting websockets onto a page. If multiple URLs are provided, the socket will automatically connect to the fastest and roll through them in the event that a connection is lost.

##Events ####data Emits data as it's retreived, with the detail containing the data received and the source (assuming one was provided in the data request)

####serverChange If servers are changed for any reason this event is fired

##Attributes ####json Specifies whether the adapter will automatically attempt to json serialize/deserialize messages. Defaults to true. ####urls As urls change, the socket reinitializes with the new target servers. In process messages could be lost during the switch to a new set of servers.

##Methods ####send Sends the provided message via the websocket. Optional callback parameter can be provided will be called with the response, or you can listen for the data event. The send call returns a queryId or messageId that will be included in the response assuming the responding server includes it. The callback will only function if this is the case.

####handleData As request data is returned, we bubble a data event but also if possible associate it with the proper callback and fire that as well.

##Event Handlers

This socket is powerful. So powerful that it will try forever to reconnect to all the specified servers until you call close. It will not give up. It will not relent.

OK -- so this socket, on send, will roll through all connected sockets, and the first one that does a successful transport wins. All connected sockets are possible sources for incoming messages.

Oh -- and this is a client side WebSocket, and is set up to work with Browserify. Client side matters since it initiates the WebSocket connection, so is the only side in a place to reconnect.

If you explicitly call close(), then this socket will really close, otherwise it will work to automatically reconnect onerror and onclose from the underlying WebSocket.

#Events ##onserver(event) This is fired when the active server changes, this will be after a send as that is the only time the socket has activity to 'know' it switched servers.

Event relay. Maybe I should call it baton not evt. Anyhow, the ReconnectingWebSocket handles the underlying WebSocket so we don't need to hookup each time we reopen.

Send, hunting through every socket until one goes.

This is a very simple form of stick preference for the last socket that worked.

Close all the sockets.

Empty shims for the event handlers. These are just here for discovery via the debugger.

Publish this object for browserify.

This has the exact same API as WebSocket. So you get going with:

ReconnectingWebSocket = require(reconnecting-websocket)
ws = new ReconnectingWebSocket('ws://...');

#Events ##onreconnect(event) This callback is fired when the socket reconnects. This is separated from the onconnect(event) callback so that you can have different behavior on the first time connection from subsequent connections. ##onsend(event) Fired after a message has gone out the socket. ##ws A reference to the contained WebSocket in case you need to poke under the hood.

This may work on the client or the server. Because we love you.

The all powerful connect function, sets up events and error handling.

Empty shims for the event handlers. These are just here for discovery via the debugger.

Publish this object for browserify.

core-websocket's People

Contributors

nandrews0424 avatar

Watchers

James Cloos avatar Luis Roberto Perez Rios avatar

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.