IBM MobileFirst 8.0.0 - WorkLight Logger and Analytics not working - ibm-mobilefirst

I have implemented WL Logger and WL Analytics in my ionic app. But the logs(Client side + Server side) are not publishing on the console.
My steps are:-
1. I have enabled MFPLogger on my console.
2. Initialize WL using
enter code here
WL.Client.init({
onSuccess : function() {
WL.Logger.config({ capture: true });
WL.Analytics.init(this);
enter code here
WL.Analytics.addDeviceEventListener
(WL.Analytics.DeviceEvent.NETWORK);
WL.Analytics.addDeviceEventListener
(WL.Analytics.DeviceEvent.LIFECYCLE);
setInterval(function() {
WL.Logger.send();
WL.Analytics.send();
}, 6000);
console.log("Success WL");
},
onFailure : function(err){
}
});
//Client Side
WL.Logger.info(response)
WL.Analytics.log({type : message},message);
//End
//Server Side
MFP.Logger.info(logging_message);
//End
Please help

Please try with this one.
WL.Client.init({
onSuccess : function() {
WL.Logger.config({ maxFileSize : 100000, // allow persistent storage of up to 100k of log data
// level : 'info', // at debug (and above) level
capture : true,
stringify: true // capture data passed to log API calls into persistent storage
});
WL.Analytics.enable().then(function (success) {
console.log(success);
}).fail(function (errObj) {
console.log(errObj);
});
setInterval(function() {
WL.Logger.send();
WL.Analytics.send();
}, 6000);
console.log("Success WL");
},
onFailure : function(err){
console.log("Failed WL");
WL.Logger.error('Caught an exception', err);
}
});

Related

why service worker download new content automatically, but doesn't update?

I register service worker this way:
/* eslint-disable no-console */
import { register } from 'register-service-worker'
if (process.env.NODE_ENV === 'production') {
register(`${process.env.BASE_URL}service-worker.js`, {
ready() {
console.log('App is being served from cache by a service worker.');
},
registered() {
console.log('Service worker has been registered.');
},
cached() {
console.log('Content has been cached for offline use.');
},
updatefound() {
console.log('New content is downloading.');
},
updated() {
console.log('New content is available; please refresh.');
},
offline() {
console.log('No internet connection found. App is running in offline mode.');
},
error(error) {
console.error('Error during service worker registration:', error);
}
});
}
when I vue-cli-service build --mode production and then I deploy to the server, online I can correctly see the logs:
App is being served from cache by a service worker.
Service worker has been registered.
New content is downloading.
New content is available; please refresh.
It seems to download automatically the content, but from now, it still always show New content is available; please refresh (and in fact, the content is not refreshed).
It seems it won't refresh automatically? Only downloading? Why?
How can I refresh on updated()?
what I did in this situation was to resolve a promise that will reload the page for the user. This is nice because it waits and then does the page reload after the data has come in.
/* eslint-disable no-console */
import { register } from 'register-service-worker'
if (process.env.NODE_ENV === 'production') {
register(`${process.env.BASE_URL}service-worker.js`, {
ready() {
console.log('App is being served from cache by a service worker.');
},
registered() {
console.log('Service worker has been registered.');
},
cached() {
console.log('Content has been cached for offline use.');
},
updatefound() {
console.log('New content is downloading.');
},
updated() {
console.log('New content is available; please refresh.');
Promise.resolve().then(() => { window.location.reload(true); });
},
offline() {
console.log('No internet connection found. App is running in offline mode.');
},
error(error) {
console.error('Error during service worker registration:', error);
}
});
}
you should use skipWaiting method of service worker object.
maybe this can help you:
updated(registration){
const waitingServiceWorker = registration.waiting;
if (waitingServiceWorker) {
waitingServiceWorker.addEventListener('statechange', event => {
if (event.target.state === 'activated') {
window.location.reload();
}
});
waitingServiceWorker.postMessage({ type: 'SKIP_WAITING' });
}
}
whether this code is working or not depends on your service-worker.js content.
but the idea is the same you should use skip waiting.

PWA stored in Azure - The script has an unsupported MIME type ('text/plain')

I'm building my first custom service-worker.js and I encountered this error.
I'm using Vue + PWA (workbox)
registerServiceWorker.js :
import { register } from "register-service-worker";
if (process.env.NODE_ENV === "production") {
console.log("service worker won't be registerd for now");
register(`${process.env.BASE_URL}service-worker.js`, {
ready() {
console.log("App is being served from cache by a service worker.");
},
registered() {
console.log("Service worker has been registered.");
},
cached() {
console.log("Content has been cached for offline use.");
},
updatefound() {
console.log("New content is downloading.");
},
updated() {
console.log("New content is available; please refresh.");
},
offline() {
console.log(
"No internet connection found. App is running in offline mode."
);
},
error(error) {
console.error("Error during service worker registration:", error);
}
});
}
service-worker.js :
console.log("Hello from service-worker.js");
In order to get rid of this error I just changed the Content Type of the service-worker.js file (using Microsoft Azure Storage Explorer -> right click -> properties -> ContentType)
PS: let me know if you know how to automate this.

Remote video streaming using Janus-gateway not displaying in react-native

I am trying to display a remote streaming video using janus gateway in my react native project.
I am using this package: https://github.com/oney/react-native-webrtc to display the streaming video in my component and janus library (janus.mobile.js file) from here https://github.com/atyenoria/react-native-webrtc-janus-gateway/blob/master/src/janus.mobile.js
My onremotestream function is triggered but i keep receiving a black screen instead of my streaming video.( both android and ios )
I am using react-native-webrtc v : 1.75.3
react-native : 0.60.5
I call Janus this way in my component:
Here's my code:
`export default class VideoExample extends Component {
componentDidMount() {
containerStreaming = this;
Janus.init({debug: "all", callback: function() {
if(started)
return;
started = true;
}});
this.janusStart();
}
janusStart = () => {
containerStreaming.setState({ visible: true });
let janus = new Janus({
server: containerStreaming.props.server,
iceServers: containerStreaming.props.iceServers,
token: containerStreaming.props.token,
success: function() {
janus.attach({
plugin: "janus.plugin.streaming",
success: function(pluginHandle) {
streaming = pluginHandle;
Janus.log(`Janus Plugin Attached : ${pluginHandle.getId()}`);
streaming.send({ "message": {"request": "watch", id: containerStreaming.props.id } });
},
error: function(error) {
Janus.error(`Error Attaching Janus Plugin ${error}`)
},
mediaState: function(medium, on) {
containerStreaming.setState({status: 'stopped', info: 'Stopped'});
Janus.log("Janus " + (on ? "started" : "stopped") + " receiving our " + medium);
},
webrtcState: function(on) {
console.log("Janus says our WebRTC PeerConnection is " + (on ? "up" : "down") + " now");
// $("#videolocal").parent().parent().unblock();
},
onmessage: function(msg, jsep) {
console.log("jsep" ,jsep.sdp);
Janus.log(`Janus Message received : ${JSON.stringify(msg)} and jsep ${jsep}`);
var result = msg['result'];
if (!!result && result['status'] == 'stopped') {
janus.destroy();
return;
}
if (jsep !== null && jsep !== undefined) {
Janus.log(`JANUS : Handling SDP as well : ${jsep}`);
streaming.createAnswer({
jsep: jsep,
media: { audioSend: false, videoSend: false }, // recvonly
success: function(jsep){
Janus.debug(`Janus Got SDP : ${jsep}`);
streaming.send({ message: { request: 'start' }, jsep: jsep });
},
error: function(error) {
Janus.error(`Janus WebRTC error : ${error}`)
}
});
}
},
onremotestream: function(stream) {
Janus.log('Janus Remote stream detected');
Janus.log(stream);
containerStreaming.setState({status: 'streaming', info: 'Streaming'});
containerStreaming.setState({selfViewSrc: stream.toURL()});
},
oncleanup: function() {
Janus.log('Janus clean up notification')
}
})
},
error: function(error) {
Janus.error('Janus -- ' + error);
Janus.error('Destroying Janus');
janus.destroy();
},
destroyed: function() {
window.location.reload();
},
});
};
`
render() {
return (
<RTCView
zOrder={0}
streamURL={this.state.selfViewSrc}
style={styles.streamingStyle} />
);};
}
The same story with desktop chromium app with cefsharp.Net

Mobilefirst 7.1 wlInitOptions return undefined with WL.Client.Init

We have Mobile hybrid app running on MFP 7.1.0.00.20170627-0807. Our wlInitOptions is as below:
var wlInitOptions = {
autoHideSplash : false,
showIOS7StatusBar : false,
onSuccess : function (response) {
console.log(" wlInitOptions onSuccess :" + JSON.stringify(response));
},
onFailure : function (error) {
alert("System Error: Failed to connect !!");
},
onConnectionFailure: function (error) {
WL.SimpleDialog.show(
"System Error: Server connection error",
error,
[{text: "Close", handler: null}]
);
},
onUserInstanceAccessViolation : function (error) {
WL.SimpleDialog.show(
"System Error: User Access not available",
error,
[{text: "Close", handler: null}]
);
},
timeout: 10000,
onRequestTimeout : function (error) {
WL.SimpleDialog.show(
"System Error: Request Timeout",
error,
[{text: "Close", handler: null}]
);
},
onErrorRemoteDisableDenial : function (message, downloadLink) {
WL.SimpleDialog.show(
appStoreUpdateTitle,
message,
[{text: notNowButton, handler: function() {WL.App.close();}},
{text: downloadNewVersionBtn, handler: function() {WL.App.openURL(downloadLink, "_blank");}}]
);
},
};
if (window.addEventListener) {
window.addEventListener('load', function() {
WL.Client.init(wlInitOptions);
console.log(" wlInitOptions 1 :" + JSON.stringify(WL.Client.init(wlInitOptions)));
}, false);
} else if (window.attachEvent) {
window.attachEvent('onload', function() {
WL.Client.init(wlInitOptions);
console.log(" wlInitOptions 2 :" + JSON.stringify(WL.Client.init(wlInitOptions)));
});
}
};
I'm trying to identify what is the response we get from success init. However, the log is always comes as undefined even though our app is working as expected.
How would I know what is the response content and why it is undefined.
The reason behind this is to track the failure of the init call so we can capture the log and the exact response that caused the failure.
Logs:
2017-07-26 12:56:04.281 ManulifeBankMobile[19779:517705] wlInitOptions onSuccess :undefined
2017-07-26 12:56:04.281 ManulifeBankMobile[19779:517705] wlInitOptions 1 :undefined
2017-07-26 12:56:04.281 ManulifeBankMobile[19779:517705] wlInitOptions 2 :undefined
The WL.Client.init() function is an asynchronous void function - it doesn't return anything. You can use the onSuccess and onFailure callbacks to react to overall success or failure of the WL.Client.init() call, respectively. These callbacks, however, are not passed a reference to the actual response. If you want to respond to specific failure scenarios, you can specify a number of additional failure callback functions in your options object. These callbacks will be invoked when the associated error scenario occurs:
onUnsupportedVersion
onRequestTimeout
onUnsupportedBrowser
onDisabledCookies
onUserInstanceAccessViolation
onErrorRemoteDisableDenial
onErrorAppVersionAccessDenial
Note that the general onFailure callback will be invoked in every failure case.
See the WL.Client.init() documentation for more info

MobileFirst and Ionic Push notification callback

I have an Ionic project and I added a push notification callback handler as explained in official documentation (my expectation is to have some alert when inside the app and a notification arrive), but it is never invoked.
WL.Client.Push.registerEventSourceCallback(
"myPush",
"PushAdapter",
"PushEventSource",
pushNotificationReceived);
Here the question is where I have to place the pushNotificationReceived function to be called ? I try in index.js and inside the controller as a function, but I do not have success.
Thank for help
Have you reviewed the sample application for push notifications?.
The sample demonstrates implementation of push notifications APIs. https://developer.ibm.com/mobilefirstplatform/documentation/getting-started-7-1/foundation/notifications/push-notifications-overview/push-notifications-in-hybrid-applications/event-source-notifications-in-hybrid-applications/
See the supplied main.js file: https://github.com/MobileFirst-Platform-Developer-Center/EventSourceNotifications/blob/release71/apps/HybridEventSource/common/js/main.js
You have to include callback function in ionic inside the app.js file after "Successfully connected with mobile first server".
WLAuthorizationManager.obtainAccessToken().then(
function (response) {
//alert("successfully obtained a token from the server");
MFPPush.initialize (
function(successResponse) {
//alert("Successfully intialized");
MFPPush.registerNotificationsCallback(notificationReceived);
},
function(failureResponse) {
console.log("Failed to initialize");
}
);
MFPPush.isPushSupported (
function(successResponse) {
//alert("Push Supported: " + successResponse);
},
function(failureResponse) {
console.log("Failed to get push support status");
}
);
MFPPush.registerDevice(
function(successResponse) {
//alert("Successfully registered");
},
function(failureResponse) {
console.log("Failed to register");
}
);
function notificationReceived(message) {
alert(JSON.stringify(message.alert));
}
},
function(response) {
//alert("res"+JSON.stringify(response));
console.log("Unable to obtain a token from the server: " + JSON.stringify(response));
if(JSON.stringify(response.status) == 403){
console.log("The Application is disabled on this Device");
ionic.Platform.exitApp();
}
}
);