I would like to start a mirth channel from another mirth channel, wait for it to complete, stop it and then start another. I have this code in the main channel started. My question is how to I get a response back from the other channel? I do have the following line in channel 'CH1' as the last line.
return "<data><value>1</value></data>";
Snipped from MAIN CHANNEL:
var channelName = 'CH1'
ChannelUtil.StartChannel(channelName)
while (getChannelState(channelName).toUpperCase() == "STARTED") {
}
function getChannelState(channelName){
var channelStatus = ChannelUtil.getChannelState(channelName);
if(channelStatus != null){
return channelStatus.toString();
}
return "UNKNOWN";
}
You can accomplish this by creating a controller channel that would switch channels on and off.
The child channels would send status updates to the controller by using the route message command in a javascript transformer.
router.routeMessage('CONTROL CHANNEL', 'I am done');
I'm curious though as to what you're trying to do.
Would creating a separate destination as a channel writer and sending a message to the child channel work?
Related
I have been looking to distribute the socket connection to listen or trigger some/on provider.
My case i have some API that need to hit when signal from socket onMessage is coming. service is inside of provider and used more then one widget. so when the signal is comming then triggre the provider so the state will change on all of widget where provider was listed.
I have estabilish the socket connection on base widget, and have been connected. I have websocket.dart class and here is my websocket on message handler:
onMessage(dynamic data) {
final Map decoded = jsonDecode(data);
final body = decoded["body"];
switch (body) {
case "authenticated":
Log.info("Wss conn is authenticated.");
_connected = true;
return;
case "fetchNotification":
Log.info("fetchNotification");
return;
case "authenticated":
Log.warning("Wss conn is unauthenticated.");
_connected = false;
establishConnection();
return;
default:
Log.warning("Invalid signal body");
}
}
from code above on fetchNofication signal need to trigger some provider to hit the API and updating some widget.
The workaround for now, I wrapped all the websocket classes to extend the provider. so all widgets that need to listen for ws signal must use websocket provider. but this is not good enough i think
I need to ensure that a certain HTTP request was send successfully. Therefore, I'm wondering if a simple way exists to move such a request into a background service task.
The background of my question is the following:
We're developing a survey application using flutter. Unfortunately, the app is intended to be used in an environment where no mobile internet connection can be guaranteed. Therefore, I’m not able to simply post the result of the survey one time but I have to retry it if it fails due to network problems. My current code looks like the following. The problem with my current solution is that it only works while the app is active all the time. If the user minimizes or closes the app, the data I want to upload is lost.
Therefore, I’m looking for a solution to wrap the upload process in a background service task so that it will be processed even when the user closes the app. I found several posts and plugins (namely https://medium.com/flutter-io/executing-dart-in-the-background-with-flutter-plugins-and-geofencing-2b3e40a1a124 and https://pub.dartlang.org/packages/background_fetch) but they don’t help in my particular use case. The first describes a way how the app could be notified when a certain event (namely the geofence occurred) and the second only works every 15 minutes and focuses a different scenario as well.
Does somebody knows a simple way how I can ensure that a request was processed even when there is a bad internet connection (or even none at the moment) while allowing the users to minimize or even close the app?
Future _processUploadQueue() async {
int retryCounter = 0;
Future.doWhile(() {
if(retryCounter == 10){
print('Abborted after 10 tries');
return false;
}
if (_request.uploaded) {
print('Upload ready');
return false;
}
if(! _request.uploaded) {
_networkService.sendRequest(request: _request.entry)
.then((id){
print(id);
setState(() {
_request.uploaded = true;
});
}).catchError((e) {
retryCounter++;
print(e);
});
}
// e ^ retryCounter, min 0 Sec, max 10 minutes
int waitTime = min(max(0, exp(retryCounter)).round(), 600);
print('Waiting $waitTime seconds till next try');
return new Future.delayed(new Duration(seconds: waitTime), () {
print('waited $waitTime seconds');
return true;
});
})
.then(print)
.catchError(print);
}
You can use the plugin shared_preferences to save each HTTP response to the device until the upload completes successfully. Like this:
requests: [
{
id: 8eh1gc,
request: "..."
},
...
],
Then whenever the app is launched, check if any requests are in the list, retry them, and delete them if they complete. You could also use the background_fetch to do this every 15 minutes.
I'm creating a research experiment that uses WebAudio API to record audio files spoken by the user.
I came up with a solution for this using recorder.js and everything was working fine... until I tried it yesterday.
I am now getting this error in Chrome:
"The AudioContext was not allowed to start. It must be resumed (or
created) after a user gesture on the page."
And it refers to this link: Web Audio API policy.
This appears to be a consequence of Chrome's new policy outlined at the link above.
So I attempted to solve the problem by using resume() like this:
var gumStream; //stream from getUserMedia()
var rec; //Recorder.js object
var input; //MediaStreamAudioSourceNode we'll be recording
// shim for AudioContext when it's not avb.
var AudioContext = window.AudioContext || window.webkitAudioContext;
var audioContext = new AudioContext; //new audio context to help us record
function startUserMedia() {
var constraints = { audio: true, video:false };
audioContext.resume().then(() => { // This is the new part
console.log('context resumed successfully');
});
navigator.mediaDevices.getUserMedia(constraints).then(function(stream) {
console.log("getUserMedia() success, stream created, initializing Recorder.js");
gumStream = stream;
input = audioContext.createMediaStreamSource(stream);
rec = new Recorder(input, {numChannels:1});
audio_recording_allowed = true;
}).catch(function(err) {
console.log("Error");
});
}
Now in the console I'm getting:
Error
context resumed successfully
And the stream is not initializing.
This happens in both Firefox and Chrome.
What do I need to do?
I just had this exact same problem! And technically, you helped me to find this answer. My error message wasn't as complete as yours for some reason and the link to those policy changes had the answer :)
Instead of resuming, it's best practise to create the audio context after the user interacted with the document (when I say best practise, if you have a look at padenot's first comment of 28 Sept 2018 on this thread, he mentions why in the first bullet point).
So instead of this:
var audioContext = new AudioContext; //new audio context to help us record
function startUserMedia() {
audioContext.resume().then(() => { // This is the new part
console.log('context resumed successfully');
});
}
Just set the audio context like this:
var audioContext;
function startUserMedia() {
if(!audioContext){
audioContext = new AudioContext;
}
}
This should work, as long as startUserMedia() is executed after some kind of user gesture.
I'm working with cordova's BLE (bluetooth low energy)
After I subscribe to notifications of BLE (which returns Observable), I want to send some message to the ble device, what is the best way to perform this, basically I need to run a function once after the subscription is made so that once device responds back to me, the code in the subscription is run.
ble.startNotification(deviceId, uuid1, uuid2).subscribe(bufferData=> {
//do something with bufferData
})
now after this, I want to run something like a callback,
.then(()=> {
//send message to device (only once), after the message is sent, the device will respond back and the `do something with bufferData` code will be run
})
I could easily do a setTimeout and send a message to the device after few seconds, and of course it works, but I want to do it cleanly, after I'm sure the subscription happened (subscription to the Observable of course)
You can wrap existing method using create operator and add custom code that will be executed on every new subscription.
See the example:
// emulate cordova with "dummy" bluetooth interface
const BLE = {
startNotification: () => Rx.Observable.interval(1000)
}
const wrappedBLE = (...params) =>
Rx.Observable.create(observer => {
// constructor fn will be executed on every new subscribtion
const disposable = BLE.startNotification(...params).subscribe(observer);
// place code to send notification here, instead of console log
console.log('New subscriber for BLE with params: ', params);
return disposable;
});
wrappedBLE("param1", "param2", "param3")
.subscribe(e => console.log("received notification: ", e));
<script src="https://unpkg.com/rxjs#5.4.3/bundles/Rx.min.js"></script>
I am using pubnub in my web application to show the notification.
var newmsgCount = 0;
Pubnub.init({
subscribe_key: 'sub-key',
publish_key: 'pub-key',
ssl: true,
uuid: 'ENV'+"_"+userIdNotificationId
});
Pubnub.subscribe({
channel: 'ENV'+"_"+userIdNotificationId,
callback: function (newMsg) {
newmsgCount = newmsgCount + 1;
}
});
Pubnub.history({
channel: 'ENV'+"_"+userIdNotificationId,
include_token: true,
callback: function (messages) {
var messagelist = messages[0];
for (var i = 0; i < messagelist.length; i++) {
newmsgCount = newmsgCount + 1;
}
}
});
This is subscribe method i am using in my front end code.When i continuously push 3 or 4 messages to the subscribed channel it's only showing only one message in subscribe method.
Once i refresh the page i am reading the message count from pubnub history but there i am getting actual message count. But its not showing actual count in pubnub subscribe.
Any one please suggest whats the wrong in my implementation.
I update all code in above section in page refresh i will get the count from pubnub history function but in the pubnub subscribe is using to get the live count, once the user get new notification that count is read from pubnub subscribe. This count is not getting correct. Once the page is refreshed i am getting the actual count from pubnub history from same channel. I don't know why it's happening. Any other pubnub function available to get the live notification count for the user without page refresh. Please suggest