Dear all,
We have to try out XPMobileSDK with mobile server.
The following is our code sample
test.js
function initialize() {
var url = milestoneLink;
if (!/^http/.test(url)) url = 'http://' + url;
var observer = {
connectionDidLogIn: connectionDidLogIn
};
XPMobileSDK.addObserver(observer);
XPMobileSDK.connect(url);
}
//
// Connection state observing.
//
function connectionDidLogIn() {
console.log('Login successsfully');
}
index.chtml
Question :
- Could SDK return any value of message that for login faailed?
- Does the trigger point to connect to milestone starting in index.chtml correctly ?
Please advance & thx.
KennethT
Hi Kenneth,
You could provide more events in the observers subscription.
Here is description of all the possible notifications that you can subscribe to :
/**
* Interface description for the observers of the Connection singleton.
*
* If an objects wants to be informed for a specific event (when connection is lost for example) they can register as an observer.
* Registering an object as an observer for the Connection singleton is simple as calling Connection.addObserver(object).
* Then, if the observer defines any of the methods described below, they will be called whenever it is appropriate.
*
* All methods are optional. Just implement those you need in your class and add it as observer.
*
* @class ConnectionObserverInterface
*/
XPMobileSDK.library.ConnectionObserverInterface = {
/**
* Sent to observers when the connection state changes in any way
*
* @method connectionStateChanged
*/
connectionStateChanged: function () {},
/**
* Sent to observers when connection has connected to the server and is about to send credentials
*
* @method connectionDidConnect
* @param parameters: object, the object containing the response parameters.
*/
connectionDidConnect: function (parameters) {},
/**
* Sent to observers when connection attempted to connect to the server but failed.
* Note that error may be a null object if we have failed to even parse the response from the server.
*
* @method connectionFailedToConnect
*/
connectionFailedToConnect: function (error) {},
/**
* Sent to observers when connecting with external connection ID has failed.
*
* @method connectionFailedToConnectWithId
*/
connectionFailedToConnectWithId: function (error) {},
/**
* Sent to observers when connection is in the process of logging in, but requires additional verification code.
*
* @method connectionRequiresCode
* @param provider: string, the provider used to send a verification code.
*/
connectionRequiresCode: function (provider) {},
/**
* Sent to observers when connection is in the process of logging in, a code has been sent to the server for verification, but this code is wrong.
*
* @method connectionCodeError
*/
connectionCodeError: function () {},
/**
* Sent to observers when connection has logged in.
*
* @method connectionDidLogIn
*/
connectionDidLogIn: function () {},
/**
* Sent to observers when connection has failed to log in. Check the error to determine if it was due to incorrect credentials!
* Note that error may be a null object if we have failed to even parse the response from the server.
*
* @method connectionFailedToLogIn
*/
connectionFailedToLogIn: function (error) {},
/**
* Sent to observers when connection to the server was lost.
*
* @method connectionLostConnection
*/
connectionLostConnection: function () {},
/**
* Sent to observers when the disconnect command is sent.
*
* @method connectionProcessingDisconnect
*/
connectionProcessingDisconnect: function() {},
/**
* Sent to observers when connection to the server was closed on request via disconnect method.
*
* @method connectionDidDisconnect
*/
connectionDidDisconnect: function () {},
/**
* Sent to observers when all video connections have been switched to pull mode.
*
* @method connectionSwitchedToPull
*/
connectionSwitchedToPull: function () {},
/**
* Sent to observers every time a request to the server has been received properly and without timeout or other terminal errors.
* You can use that to keep track of the connection and monitor it is properly working.
*
* @method connectionRequestSucceeded
*/
connectionRequestSucceeded: function (request, response) {},
connectionVersionChanged: function () {},
connectionReloadConfiguration: function () {},
connectionReloadCameraConfiguration: function () {},
closeStreamFinished: function () {}
};
This is well documented in the Connection.js.
Probably :
connectionFailedToLogIn: function (error) {},
is what you are looking for.
Hi again Kenneth,
I’ve consulted with one of my colleagues (about second question).
We think that starting is not completely correct.
You should call “XPMobileSDK.login” after successful “XPMobileSDK.connect” response.
In other words you should subscribe to “connectionDidConnect” and make login request there.
In order to be sure that we fully understand your code, could you ZIP the whole code (without your application of course, which I suppose is initialized with call of “startApp();”) and attach it here ?
Dear Petar,
startApp() already define in index.chtml and shown in above. As we want to have a form submit for login instead of prompt dialog box, we have put the the script in index.chtml
or coucld you show us a sample that using connectionDidConnect and Form submitting?
please check & thx.
KennethT
Hi Kenneth,
Almost all the new samples are based on code that doesn’t prompt for credentials but are using “submit like” UI.
I’ve tried to clean almost everything in one test sample, except logic for connect and login.