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
Related
When I installed the app for first time the push notification is not receiving, if I kill the app and open again the push notifications is working fine.
When I console the code and trigger the push notification manually through FCM , I found that the notification data is not receiving on the onMessage function and on getInitialNotification() the result shows as undefined.
Please check the below code for getting push notifications and also the packages and versions which I have used.
Packages :
"#react-native-firebase/messaging": "^7.5.0",
"#react-native-community/push-notification-ios": "^1.10.1",
"react-native-push-notification": "^8.1.1",
Code :
componentWillUnmount() {
if (Platform.OS === "ios" && this.messageListener1 && this.messageListener2) {
this.messageListener1();
this.messageListener2();
}
}
async requestUserPermission() {
const { navigate } = { ...this.props }
const authStatus = await messaging().requestPermission();
const enabled =
authStatus === messaging.AuthorizationStatus.AUTHORIZED ||
authStatus === messaging.AuthorizationStatus.PROVISIONAL;
if (enabled) {
this.messageListener1 = messaging().onMessage(async remoteMessage => {
PushNotification.localNotification({
/* Android Only Properties */
id: remoteMessage.data.id, // (optional) Valid unique 32 bit integer specified as string. default: Autogenerated Unique ID
autoCancel: true, // (optional) default: true
vibrate: true, // (optional) default: true
vibration: 300, // vibration length in milliseconds, ignored if vibrate=false, default: 1000
group: remoteMessage.data,
userInfo: {
data: remoteMessage.data,
},
title: remoteMessage.notification.title,
message: remoteMessage.notification.body,
});
});
messaging()
.getInitialNotification()
.then(async remoteMessage => {
if (remoteMessage) {
if (await GlobalStorage.handleInitialNotification(remoteMessage)) {
navigate(remoteMessage);
PushNotification.cancelLocalNotifications({ id: remoteMessage.data.id });
}
}
});
this.messageListener2 = messaging().onNotificationOpenedApp(remoteMessage => {
GlobalStorage.handleInitialNotification(remoteMessage)
navigate(remoteMessage);
PushNotification.cancelLocalNotifications({ id: remoteMessage.data.id });
});
Note : There is no issues in getting the FCM token.
I faced the same problem.
I tried all the packages and the result is the same in all of them.
Here's the situation:
*Everything is fine with the Notification integration.
*When you install the application for the first time, there is no notification.
*When you open the application for the first time and kill it in the background and open it again and throw it into the background, everything works fine. You start receiving notifications.
It's really interesting. Has anyone experienced this and know what exactly is causing the issue?
The issue is only facing mainly on android device and here is solution I used to solve the issue
const { navigate,
} = { ...this.props }
PushNotification.configure({
onRegister: function (token) {
},
onNotification: function (notification) {
const clicked = notification.userInteraction ? notification.userInteraction : "";
notification.finish(PushNotificationIOS.FetchResult.NoData);
if (clicked) {
navigate(notification);s
PushNotification.cancelLocalNotifications({ id: notification.id });
} else if (!notification.foreground) {
navigate(notification);
PushNotification.cancelLocalNotifications({ id: notification.id });
}
else {
PushNotification.localNotification({
/* Android Only Properties */
channelId: "app_name", // (required)
channelName: "app_name", // (required)
id: notification.id, // (optional) Valid unique 32 bit integer specified as string. default: Autogenerated Unique ID
// autoCancel: true, // (optional) default: true
vibrate: true, // (optional) default: true
vibration: 300, // vibration length in milliseconds, ignored if vibrate=false, default: 1000
group: notification.data, // (optional) add group to message
priority: "high", // (optional) set notification priority, default: high
visibility: "private", // (optional) set notification visibility, default: private
importance: "high",
userInfo: {
id: notification.id,
name: "name",
title: notification.title,
message: notification.message,
data: notification.data
},
title: notification.title,
message: notification.message,
});
}
notification.finish(PushNotificationIOS.FetchResult.NoData);
},
senderID: "",
permissions: {
alert: true,
badge: true,
sound: true
},
popInitialNotification: true,
requestPermissions: true
});
So I searched here about this problem and I saw many experienced it but still didn't find solution.
FCM Push notifications arrive twice if the browser is in background
Ty for your help.
My nuxt config firebase serviced:
services: {
auth: true, // Just as example. Can be any other service.,
messaging: {
createServiceWorker: true,
fcmPublicVapidKey: "###", // OPTIONAL : Sets vapid key for FCM after initialization
inject: fs.readFileSync("./serviceWorker.js")
}
}
my service worker:
messaging.setBackgroundMessageHandler(function(payload) {
console.log("[firebase-messaging-sw.js] Received background message ");
self.registration.hideNotification();
return null;
});
self.addEventListener("push", function(e) {
data = e.data.json();
const options = {
tag: "notification-1",
body: data.notification.body,
vibrate: [100, 50, 100],
data: {
dateOfArrival: Date.now(),
primaryKey: "1"
}
};
self.registration.showNotification(data.notification.title, options);
});
self.addEventListener(
"notificationclick",
function(event) {
console.log("test", event);
event.notification.close();
const url = "home";
event.waitUntil(
self.clients.matchAll({ type: "window" }).then(windowClients => {
// Check if there is already a window/tab open with the target URL
for (let i = 0; i < windowClients.length; i++) {
const client = windowClients[i];
// If so, just focus it.
if (client.url === url && "focus" in client) {
return client.focus();
}
}
if (self.clients.openWindow) {
console.log("open window");
}
})
);
},
false
);
Add
self.registration.hideNotification();
On top of line
self.registration.showNotification(
This allows your app to hide the default notification in which case you will only have one notification.
I would like to know how I can do to detect if during any moment of the execution of an Ionic 4 app (not only at the beginning of the app), the user manually turns off or on the GPS.
What Ionic 4 event can I hear from the GPS, to be able to alert at any time of the execution of the app if the user turned off or on the GPS?
Thank you very much and sorry for my bad English
My code on app.component.ts:
initializeApp() {
this.platform.ready().then(() => {
this.screenOrientation.lock(this.screenOrientation.ORIENTATIONS.PORTRAIT_PRIMARY);
this.platform.backButton.subscribeWithPriority(9999, () => {
document.addEventListener('backbutton', function (event) {
event.preventDefault();
event.stopPropagation();
}, false);
this.presentAlertConfirm();
});
this.geolocation.getCurrentPosition().then((resp) => {
this.global.origin = { lat: resp.coords.latitude, lng: resp.coords.longitude };
this.global.latitude = resp.coords.latitude;
this.global.longitude = resp.coords.longitude;
}).catch((error) => {
console.log('Error getting location', error);
});
let watch = this.geolocation.watchPosition();
watch.subscribe((data) => {
this.global.origin = { lat: data.coords.latitude, lng: data.coords.longitude };
this.global.latitude = data.coords.latitude;
this.global.longitude = data.coords.longitude;
}, error => {
console.log('Error getting location in WATCH', error); //error handling //
})
this.statusBar.styleDefault();
this.splashScreen.hide();
});
}
You have to watch for some GPS change. As proposed in the Ionic 4 documentation and as you have done correctly:
this.watch = this.geolocation.watchPosition();
this.watch.subscribe((data) => {
// usable data
}, (error) => {
// some error
}, { timeout: 30000 });
timeout: The maximum length of time (milliseconds) that is allowed to pass without receiving a set of coordinates.
And remeber to unsubscribe on destroy:
public ngOnDestroy(): void {
this.watch.unsubscribe();
}
So I am trying to use react-native-fbsdk FBAppInviteDialog to show invitation dialog but I always get this error
I was trying to use this code from Sending App Invites in a React Native app
here is my code
constructor (props) {
super(props)
this.state = {
appInviteContent: {
applinkUrl: 'https://facebook.com'
}
}
}
_onPress = () => {
var tmp = this
AppInviteDialog.canShow(this.state.appInviteContent).then(
function (canShow) {
if (canShow) {
return AppInviteDialog.show(tmp.state.appInviteContent)
}
}
).then(
function (result) {
if (result.isCancelled) {
Alert.alert('Share cancelled')
} else {
Alert.alert('Share success with postId: ' + result.postId)
}
},
function (error) {
Alert.alert('Share fail with error: ' + error)
}
)
}
If you want that the showDialog works you must first as the example show something like this:
appInviteContent= {
contentType: 'link',
contentUrl: Platform.select({ ios: 'https://iossomething.com',
android: 'https://androidsomething.com'}),
contentDescription: 'Check the website!',
};
Also as I see there in the code you are using the flow language.
Check that.
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);
}
});