Why doesn't SwiftyZeroMQ support epgm:// and pgm:// transport-classes? - swift

We currently want a way to pass data between devices with sockets so we used ZeroMQ on our server-side with a python script and everything seems to be working. Our protocol address currently is epgm://224.0.0.1:28650, However, we need to communicate with the python script so we decided to use this Swift library. Currently, I'm directly using the library from this repository and it seems to be using ZeroMQ library version 4.2 with patch level .2. Then, using this function, I'm checking whether or not the library has the .pgm protocol which my app reports that there it doesn't support it.
Although the library has this function to check whether or not it supports a certain protocol, I'm unable to find ANYTHING on google regarding how I would get the library to support the pgm protocol.
After looking through the original swift library, I was able to find zmq.h which, from what I can tell is what the swift library is using as it's ZMQ library. So, after discovering this, I attempted to recompile libzmq with the "--with-pgm" build option that we used to fix the issue on PyZMQ. However, I haven't really had much luck with this and I'm not even sure this is how I'm supposed to proceed. I'm currently at a loss and any help would be appreciated. Thanks.
Here's the Swift code that we're currently using:
import SwiftyZeroMQ5
class communicationClass{
var context: SwiftyZeroMQ.Context?;
var subscriber: SwiftyZeroMQ5.SwiftyZeroMQ.Socket?;
init(){
do{
context = try SwiftyZeroMQ.Context();
subscriber = try context?.socket(.subscribe);
try subscriber?.connect("epgm://224.0.0.1:28650");
}
catch{
print("error - \(error)")
}
}
}
Here's the error that it outputs: error - Protocol not supported

Q : "Why doesn't SwiftyZeroMQ support epgm:// and pgm:// transport-classes?"
Documentation is clear & sound on this:The as-is package does explicitly state, it does not support epgm://-transport class as of 2020-10.
The next step:
Try using the pgm://-transport-class, instead of the epgm:// and if that fails, file an issue at the package maintainers' incident-management queue, as they claim it should work.

So, due to the lack of support of EPGM and PGM, we have decided to use raw UDP with ZeroMQ's dish/radio draft apis. These draft apis are supposed to replace EPGM and PGM but they're still in development. The apis work for our use case but it may vary depending on your use case.
EDIT:
So, there's a better answer to this question. The reason why SwiftyZeroMQ (at least my version) doesn't support the EPGM and PGM protocols is that you need to compile ZMQ yourself with the openpgm option.

Related

Cannot find UIDocumentPickerViewController in scope

I am completely new to iOS or Mac development, and I am trying to implement opening and reading files in an app for MacOS. By default I had my app use SwiftUI. Looking up how to implement such a functionality using SwiftUI I saw suggestions to use UIDocumentPickerViewController. However I cannot find a proper documentation as to how to use it in practice. Apple's documentation page is not informative at all -- it doesn't provide any information as of how to actually use this class.
Trying to follow some examples I found elsewhere on the Internet, I am now stuck with getting Cannot find UIDocumentPickerViewController in scope compilation error. I have tried importing UIKit, AppKit, CoreServices, MobileCoreServices, Cocoa but nothing seems to help -- extending the class as described in another StackOverflow answer just fails with the same compilation error.
How do I properly use UIDocumentPickerViewController, or how do I implement the same functionality using some other method if this one is wrong?
Apparently UIDocumentPickerViewController is not available when building for Mac OS X, and NSOpenPanel seems to be a way to get the necessary functionality.

Is there a Swift bridge for Python?

I developed a script to set attributes for my iTunes music library on my Mac using an Apple Script bridge called AppScript. AppScript Allowed me to write my code in native Python without having to learn Apple Script. AppSript would translate my native Python to Apple Script. Since Apple Script has been replaced with Swift I am wondering if there is a similar bridge for Swift. I have done my research, but no luck. Additionally if there is, can you provide an example of how to control iTunes(now Music) with said library? Thanks in advance
Swift is designed to use MacOS's programming APIs: AppKit, Quartz, CoreFoundation, NSObject, etc, rather than the higher level OSAX event-driven elements (open, print, close, document, window, etc) used in AppleScript.
The system-bundled python (2.7) comes with pyObjC, which allows python to use the same programming APIs that Swift does, e.g. "writing apps". PyObjC also contains a Scripting Bridge to the AppleScript events and objects. The canonical example code does use iTunes:
from Foundation import *
from ScriptingBridge import *
iTunes = SBApplication.applicationWithBundleIdentifier_("com.apple.iTunes")
print iTunes.currentTrack().name()
(Obvs, this is python2 and you need to put brackets round the print command. Also, personally, I wouldn't import * everything, as it's very slow.)
Here are some other methods/attributes based on the Script Dictionary:
iTunes.nextTrack()
iTunes.previousTrack()
iTunes.playpause()
iTunes.fastForward()
iTunes.setShuffleEnabled_(False)
iTunes.currentPlaylist().playOnce_(False)
The system-bundled version of pyObjC is very old, but the library itself is still being developed. If you're using python3, then you should install the latest version of pyObjC.
FWIW, you can actually run uncompiled Swift as a 'script' in the shell.

How to make a Swift framework submodule really private?

I've found another question which brings more details regarding the problem and possible solutions. It seems like there is a known bug which is a subject for future improvements.
Objective C classes within an iOS Swift-based dynamic framework
I'm developing a framework in Swift and I'm using some Objective-C code inside the framework. So far my module map looks like this:
framework module MyModule {
umbrella header "MyModule-umbrella.h"
export *
explicit module Private {
header "MyTools.h"
}
}
My concern is that all the APIs from MyTools.h are visible from outside the framework: for example, if you install the framework using Cocoapods, then you import MyModule into your application (not MyModule.Private), you are able to access MyTools.h which is not desirable and redundant. Is there any way to make MyTools invisible from outside the framework?
PS. I use Cocoapods to distribute the framework, here is my podspec (the most significant part):
s.module_map = 'Pod/MyModule.modulemap'
s.frameworks = 'CoreData', 'CoreTelephony', 'SystemConfiguration'
s.resources = 'Pod/Classes/MessageStorage/*.xcdatamodeld'
s.public_header_files = 'Pod/Classes/**/*.h'
s.private_header_files = 'Pod/Classes/MyTools/**/*.h'
s.source_files = 'Pod/Classes/**/*.{h,m,swift}'
PSS. My umbrella header does not import MyTools.h
PSSS. Just tried to exclude the header from the main module:
framework module MyModule {
umbrella header "MyModule-umbrella.h"
export *
exclude header "MyTools.h"
explicit module Private {
header "MyTools.h"
}
}
No luck.
I found another question which brings more details regarding the problem and possible solutions (which don't work though). It seems like there is a known bug which is a subject for future improvements.
Objective C classes within an iOS Swift-based dynamic framework
I had exactly the same problems recently. The quick answer is you can't :) Even if you declare "private" modulemap, it can be always imported by your framework users. Please note, that usually, it is not a concern, especially with open source. You just say "this is an internal module, don't use it".
But (there is always but) - you can have behavior, that effectively works the same - allows you to use your Objective-C classes withing same framework target, without making them public. It works in closed source setup, I'm not 100% sure how would it behave with pods.
The case a bit too complex to paste everything here. I'm adding a link to my article about the topic, maybe it will help you. But speaking honestly - it might be a bit of overhead in your setup.
Creating Swift framework with private Objective-C members. The Good, the Bad, and the Ugly
Github example project

Sentry Raven inside Firefox Addon SDK

I am making a Firefox Extension and I want to log the errors/messages/exceptions produced by the extension code using Sentry.
I tried the JavsScript Raven client but I guess its not really made to live inside the "Content" context.
The error I get is: message = "debug" is read-only, but my actual question is, how do I go about integrating Sentry in a Firefox Addon?
PS: No, this wont go into general distribution, my api keys are safe.
What I did was just to omit calling .install() and just use the error/message reporting.
There will be no automatic catching and source code but it works for my purposes.

Soundtouch bpm iPhone

I'm trying to integrate a mechanism to calculate the BPM of the song in the iPod library(also on iphone).
Searching on the web I found that the most used and reliable libraries to do this things is soundtouch.Anyone has experience with this library? It is computationally possible to make it run on the iPhone hardware?
I have recently been using the code from the BPMDetect class of the soundtouch library succesfully. Initially compiled it on C++, later on translated the code to C# and lately I've been using the C++ code on an Android app through JNI. I'm not really familiar with development in iOS but I'm almost certain that it is possible what you're trying to do.
The only files you should use from the soundtouch source code are the following:
C++ files
BPMDetect.cpp
FIFOSampleBuffer.cpp
PeakFinder.cpp
Header files
BPMDetect.h
FIFOSampleBuffer.h
FIFOSamplePipe.h
PeakFinder.h
soundtouch_config.h
STTypes.h
At least these are the only ones I had to use to make it work.
The BPMDetect class recieves raw samples through its inputSamples() method, it's capable of calculating a bpm value even when the whole file is not yet loaded into its buffer. I have found that these intermediate values differ from the one obtained once the whole file is loaded, which is more accurate, in my experience.
Hope this helps.
EDIT:
It's a kind of complex process to explain in a comment so I'm going to edit the answer.
The gist of it is that you need your android app to consume native code. In order to do that, you need to compile the files listed above from the soundtouch library with the Android NDK toolset.
That will leave you with native code that will be able to process raw sound data, but you still need to get the data from the sound file, which you can do several ways, I think. The way I was doing it was using the FMOD library for Android, here's a nice example for that: FMOD for Android.
Supposing you declared a method like this in your C code:
void Java_your_package_YourClassName_cPlay(JNIEnv *env, jobject thiz)
{
sound->play();
}
On the Android app you use your native methods in the following way:
public class Sound {
// Native method declaration
private native void cPlay();
public void play()
{
cPlay();
}
}
In order to have a friendlier API to work with you can create wrappers around these function calls.
I put the native C code I was using in a gist here.
Hope this helps.