Skip to content

Instantly share code, notes, and snippets.

@lholmquist
Created April 9, 2013 17:44
Show Gist options
  • Save lholmquist/5347771 to your computer and use it in GitHub Desktop.
Save lholmquist/5347771 to your computer and use it in GitHub Desktop.
notifier connect/disconnect

HMM

//create a basic notifier with some settings

AeroGear.Notifier({
name: "notifications",
settings: {
    connectURL:  "/eventbus",
    autoConnect: true,
    onConnect: function() {
        console.log( "connected" );
    },
    onDisconnect: function() {
        console.log('Disconnected');
    },
    onConnectError: function() {
        console.log('Connect Error');
    },
    channels:[
        {
            address: "channel.io",
            callback: function( msg ){
                console.log( "Woo Hoo" );
            }
        }
    ]
}
})

so since this is an autoconnect, if the connect is successful, then "connected" is logged out,

//using dev tools for these next parts when discconnect is the called, "disconnected" is logged out.

now i want to reconnect, so i do

AerGearBlah.notifications.connect();

connection is successful, but no callbacks triggered since i didn't specify any, but would it make sense to call the callbacks that were specified during the inital setup only if nothing is passed in during the second connect

i guess the user could keep track of this, but would be a nice feature?

Use case is that the user is showing some identifier that you are connected, you can disconnect yourself and reconnect yourself. the same things should happen during onConnect, onDisconnect .....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment