Mobile First Server 8.0 connection check from client side - ibm-mobilefirst

Need to check whether MFP server up and running, if server not reachable, need to alert user that system is down.
i have used the below code
renderer.listen('document', 'mfpjsloaded', () => {
WLAuthorizationManager.obtainAccessToken("").then(
function(accessToken) {
console.log("MFP Server is up and running");
},
function(error) {
console.log("MFP Server is not reachable");
}
);
});
but app throws Application Error The connection to the server was unsuccessful. (file:///android_asset/www/index.html)

Related

React Native Signalr keeps saying connection needs to be initialized

I have this in my code:
useEffect(() => {
if(loaded2 == false){
connection = signalr.hubConnection('https://webambe.com/xxx');
connection.logging = true;
proxy = connection.createHubProxy('xxx');
//receives broadcast messages from a hub function, called "helloApp"
proxy.on('updateAll', (argOne) => {
setAlertNum(1);
//Here I could respond by calling something else on the server...
});
// atempt connection, and handle errors
connection.start().done(() => {
//console.log("dddd" + proxy.connectionState);
setLoaded2(true);
//console.log('Now connected, connection ID=' + connection.id);
setTrans(false);
}).fail(() => {
//console.log('Failed');
});
//connection-handling
connection.connectionSlow(() => {
//console.log('We are currently experiencing difficulties with the connection.')
});
connection.error((error) => {
const errorMessage = error.message;
let detailedError = '';
if (error.source && error.source._response) {
detailedError = error.source._response;
}
if (detailedError === 'An SSL error has occurred and a secure connection to the server cannot be made.') {
//console.log('When using react-native-signalr on ios with http remember to enable http in App Transport Security https://github.com/olofd/react-native-signalr/issues/14')
}
//console.debug('SignalR error: ' + errorMessage, detailedError)
});
}
});
When the code hits connection.start().done((), then the connection should be established but when I hit the send button that invokes the hub i get this error (setLoaded2(true) means that the connection is established):
Connection has not been fully initialized. Use .start().done() to run the logic after
connection has started.
But I have stated that says that connection has started here:
setLoaded2(true);
When this is called setTrans(false) is called to get rid of the transparent view so users can interact with the UI.
The hub connects successfully and I can run commands to the server and back, but I just want to know how to say when the connection is established so that the user can use the system.
I'm not sure if this is the way it shud be done but its working and staying connected when I move the connection and proxy outside my functional component:
connection = signalr.hubConnection('https://webambe.com/xxx');
connection.logging = true;
proxy = connection.createHubProxy('xxx');
when added this code outside the component the connection stays connected and no issues with signalr

How to fix " Error: Failed to start the transport 'WebSockets': null " in reactnative using #aspnet/signalr library?

I keep getting Failed to start the transport 'WebSockets': null when connecting to server.
I'm implementing a simple chat in reactnative mobile app. And I'm using #aspnet/signalr(version-1.1.4) library. I am getting this error - Error: Failed to start the transport 'WebSockets': null. See logs here
componentDidMount(){
try {
const connection = new signalR.HubConnectionBuilder() //Connect to a hub
.withUrl(baseUrl + `/chatbus`, {
transport: signalR.HttpTransportType.WebSockets | signalR.HttpTransportType.LongPolling,
'content-type': 'application/json',
accessTokenFactory: () => authToken //for authorization
})
.configureLogging(signalR.LogLevel.Debug)
.build();
connection.on('NotifySignalR', (ChatObject) => {
console.log(ChatObject);
});
connection.start()
.then(() => {
console.log('Chat Connection started.');
console.log('Now connected, connection ID=' + connection.id);
this.initalAttemptForChat = true;
connection.invoke("start");
})
.catch(() => {
this.initalAttemptForChat = false;
console.log('Error while establishing chatbus connection!');
});
} catch (e) {
console.log("error ", e);
throw e;
}
}
If you have you app in Windows Server just enable thw "WebSocket Protocol".
"Add or Remove Programs">"Turn Windows features on or off" > "Web Server(IIS)">"Web Server">"Application Development">"WebSocket Protocol".
For anyone using Windows Server 2012, the steps are as follows (https://learn.microsoft.com/en-us/iis/get-started/whats-new-in-iis-8/iis-80-websocket-protocol-support):
To enable support for the WebSocket Protocol on Windows Server 2012, use the following steps:
Open Server Manager.
Under the Manage menu, click Add Roles and Features.
Select Role-based or Feature-based Installation, and then click Next.
Select the appropriate server, (your local server is selected by default), and then click Next.
Expand Web Server (IIS) in the Roles tree, then expand Web Server, and then expand Application Development.
Select WebSocket Protocol, and then click Next.
If no additional features are needed, click Next.
Click Install.
When the installation completes, click Close to exit the wizard.

WebSockets not working when application is built

I have got to ASP.NET-Core 2.0 apps communicating via WebSockets.
App A is Server.
Application A is running on a remote server with Ubuntu.
App B is Client
Application B is running on a PC setup in my office.
When I test my applications locally in Debug everything works fine. Client connects to the server and they can exchange information.
However, when I build my Server app, Client can connect to it but when server tries to send a message to the client the message is not received by the client.
public async Task<RecievedResult> RecieveAsync(CancellationToken cancellationToken)
{
RecievedResult endResult;
var buffer = new byte[Connection.ReceiveChunkSize];
WebSocketReceiveResult result;
MemoryStream memoryStream = new MemoryStream();
do
{
if (cancellationToken.IsCancellationRequested)
{
throw new TaskCanceledException();
}
Console.WriteLine("Server Invoke");
// result never finishes when application is build. On debug it finishes and method returns the correct result
result = await _webSocket.ReceiveAsync(new ArraySegment<byte>(buffer), cancellationToken);
if (result.MessageType == WebSocketMessageType.Close)
{
await CloseAsync(cancellationToken);
endResult = new RecievedResult(null, true);
return endResult;
}
memoryStream.Write(buffer, 0, result.Count);
} while (!result.EndOfMessage);
endResult = new RecievedResult(memoryStream, false);
return endResult;
}
This is the part of code where everything hangs.
What I tried was:
Build Server - Build Client => not working
Build Server - Debug Client => not working
Debug Server - Debug Client => working
I need any advice what might be wrong here and where I should look for issues.
Console if free of errors. Everything hangs on:
result = await _webSocket.ReceiveAsync(new ArraySegment<byte>(buffer), cancellationToken);

OpenTok - Subscriber failed to subscribe to a stream in a reasonable amount of time

I am implementing a Network Test for my Web-application using OpenTok's js library.
To do that, I create a publisher, connect to session, then make a subscriber connect to the publisher's stream.
The Test is working on other browsers (I have tested Chrome and Internet Explorer) but on Firefox version 57.0.1 I get an error - 'The stream was unable to connect due to a network error. Make sure you have a stable network connection and that it isn't blocked by a firewall.'
Make sure when you create the OpenTok Session you are using a 'routed' Session, not a 'relayed' one. Also make sure you are passing the 'testNetwork' property to the subscribe method. Here is a working sample:
// Sample code
var session = OT.initSession(APIKEY, SESSIONID);
session.connect(TOKEN, function(err) {
if (err) {
alert(err.message);
return;
}
var publisher = session.publish();
publisher.on('streamCreated', function(event) {
session.subscribe(event.stream, null, {
testNetwork: true
}, function(err) {
if (err) alert(err.message);
});
});
});
https://jsbin.com/quruzac/edit

Preview not working properly in MFP8.0

I'm developing an application that just connects to MFP 8.0 server but when I run the app using the MFP web simulator the log says "getCachedAccessToken for scope failed: undefined" . But when I run the same application using the emulator/device it works fine.
function wlCommonInit() {
WLAuthorizationManager.obtainAccessToken().then(
function () {
alert ("You are now connected to the server");
},
function(result) {
alert("Not able to connect: "+ JSON.stringify(result));
}
);
}
Is there any way to test the MFP server connection in the MFP web simulator?
This is a known limitation of the 8.0 release.
You can read more about it, here: http://engtest01w.francelab.fr.ibm.com:9090/support/knowledgecenter/SSHS8R_8.0.0/com.ibm.worklight.dev.doc/wl_studio_tools/topics/cmbswl.html
Tokens are part of the OAuth flow.
As a workaround, you can use a simulator.