How to stop ScreenSharing manually with tokbox sdk in Swift [duplicate] - swift

I am working on an IOS application(SWIFT) in which i have used tokbox for screensharing, i am able to share the screen but not able to stop screensharing.
This is the code I have used for screensharing.
publisher?.videoType = .screen
publisher?.audioFallbackEnabled = false
let cap = ScreenCapturer(withView:view)
publisher?.videoCapture = cap
session?.publish(publisher, error: &error)
Can anyone guide to stop screensharing in swift.

To stop screen sharing will need to stop the publisher from streaming. To do that you can call:
[OTSession unpublish:error:]
More info is available on the Video API guides
For your case, where you are adding screen sharing to an existing call, you will need to create an additional publisher for the screen sharing rather than editing the existing one. To use the existing publisher it will require the publisher to be reinitialised to switch between publishing a camera feed vs a screen which will stop publishing audio too.
In addition to creating a new publisher, you need to create a new subscriber for the other user, you can do that in the subscriberDidConnect delegate function on the OTSubscriberDelegate.
Additionally, you will need to handle the destruction of both the new publisher and subscriber. This will be done in the delegate functions are you using already on the OTSessionDelegate and OTPublisherDelegate.
I have created a demo app which demonstrates this behaviour.

Related

How to stop tokbox screen sharing in SWIFT

I am working on an IOS application(SWIFT) in which i have used tokbox for screensharing, i am able to share the screen but not able to stop screensharing.
This is the code I have used for screensharing.
publisher?.videoType = .screen
publisher?.audioFallbackEnabled = false
let cap = ScreenCapturer(withView:view)
publisher?.videoCapture = cap
session?.publish(publisher, error: &error)
Can anyone guide to stop screensharing in swift.
To stop screen sharing will need to stop the publisher from streaming. To do that you can call:
[OTSession unpublish:error:]
More info is available on the Video API guides
For your case, where you are adding screen sharing to an existing call, you will need to create an additional publisher for the screen sharing rather than editing the existing one. To use the existing publisher it will require the publisher to be reinitialised to switch between publishing a camera feed vs a screen which will stop publishing audio too.
In addition to creating a new publisher, you need to create a new subscriber for the other user, you can do that in the subscriberDidConnect delegate function on the OTSubscriberDelegate.
Additionally, you will need to handle the destruction of both the new publisher and subscriber. This will be done in the delegate functions are you using already on the OTSessionDelegate and OTPublisherDelegate.
I have created a demo app which demonstrates this behaviour.

Agora SDK not working in Windows Build. VideoSurface.cs always gets tmpi = -1 in Update

I am trying to implement Screen broadcast with Unity using the Agora Video Chat SDK for Unity. I used this source, which doesn't work initially. But after modifying the code as below, I am able to receive my own stream through the server, inside Unity editor (2019.1.2f1).
//Adding inside Start
mRtcEngine.OnJoinChannelSuccess = Joined;
}
private void Joined(string channelName, uint uid, int elapsed)
{
var videoSource = FindObjectOfType<VideoSurface>();
videoSource.SetForUser(uid);
videoSource.SetEnable(true);
}
But nothing happens in the Windows build. I checked the VideoSurface.cs file. I am continuously getting tmpi = -1 inside Update. What could be the reason?
PS. I check all firewall permissions for the build. Also, the user is able to join the channel. It's just the stream that is not being received. Help appreciated.
You shouldn't need to modify the code like that. And also, in the code above you register the callback for the local user. If you want to show remote user's video, you should register the callback for OnUserJoined().
Have you seen the tutorial about the Screensharing? https://www.agora.io/en/blog/how-to-broadcast-your-screen-with-unity3d-and-agora/
Please try that. If you are still confused, you may take a look at this github repo. It has different contents to share, but the concept and Agora API usage are pretty much the same.

How to clear/invalidate ambient cache on iOS app

When I update tilesets on mapbox, changes don't appear in the iOS app unless I re-install it. There is seemingly documentation on this here: https://docs.mapbox.com/ios/api/maps/5.2.0/Classes/MGLOfflineStorage.html#/c:objc(cs)MGLOfflineStorage(im)setMaximumAmbientCacheSize:withCompletionHandler: but I can't figure out how exactly to implement it. I don't have an MGLOfflineStorage object because I am not worried about offline map storage right now, I just want to refresh the cache in the app. There are good examples of how to do this in android, but not on iOS. Any help is appreciated (preferably in swift)
It appears to be correct to call the methods on the shared MGLOfflineStorage object. The method parameter should be a closure containing any code you want to execute upon completion.
MGLOfflineStorage.shared.invalidateAmbientCache { error in
print("Invalidated")
}
Naturally you should check the error in the usual 'safe' way.

How to get GLFW window Id of FlutterWindow

I am trying to build a video player using flutter for Desktop. There is a video_player plugin available for iOS and Android, but not for Desktop. So, for the time being thought of trying to use gstreamer for decoding and hardware rendering in C++ code as back-end to flutter. The idea is to pass the Window Id of the flutter window to gstreamer's glimagesink plugin for rendering the video.
I am using the latest code from https://github.com/google/flutter-desktop-embedding as the base for my experiments. Below mentioned points are with reference to this repo.
In file flutter-desktop-embedding/example/linux/main.cc, FlutterWindowController object is created as shown below.
flutter::FlutterWindowController flutter_controller(icu_data_path);
This internally calls
FlutterDesktopInit();
While hovering the mouse pointer on the above method, VS code shows the following
bool FlutterDesktopInit()
Sets up the library's graphic context. Must be called before any other
methods.
Note: Internally, this library uses GLFW, which does not support multiple
copies within the same process. Internally this calls glfwInit, which will
fail if you have called glfwInit elsewhere in the process.
It is clear that FlutterDesktopInit() uses GLFW to create window. Checked whether I can get the window handle. But, no luck. I could only get the FlutterWindow object as shown below.
flutter::FlutterWindow *win = flutter_controller.window();
Appreciate if somebody can give some hint on how to get the GLFW window handle, which can be used with glimagesink.
You can't get references to any GLFW objects through that API. This is by design because, as the comment you quoted says, you can't have multiple copies of GLFW within the same process. GLFW is statically linked into the Linux Flutter embedding, so you can't use GLFW in the runner or a plugin.
Implementing a video player should be done using the texture APIs, which will be added for GLFW in this PR.

How do I retrieve a list of my downloaded offline map packs using Mabox and Swift?

I am wanting to add offline map functionality to an iOS app build using Swift and Mapbox. There is great documentation and examples for downloading a map region pack, but am having a difficult time figuring out how to retrieve a list of offline packs. Their documentation here gives these instructions on how to receive:
"To detect when the shared offline storage object has finished loading its packs property, observe KVO change notifications on the packs key path. The initial load results in an NSKeyValueChangeSetting change."
But I am having a difficult time find any examples or explanations as to what that means. Any help would be greatly appreciated!
An array of all known offline packs can be retrieved using the .packs attribute of the MGLOfflineStorage class. Like so:
MGLOfflineStorage.shared.packs
To access these packs, you just need to iterate over the array or pass a specific index and retrieve whatever information you're interested in from the packs.
There is a good example of using this array to create a tableview of the completed offline packs on a device in the SDK's open source test app (NB: this example is written in Obj-C).
⚠️ Disclaimer: I currently work at Mabpox ⚠️
I was finally able to come to a solution. To observe the packs retrieval using Swift, you can use this code:
MGLOfflineStorage.shared.observe(\.packs, options: [.new, .old]){ object, change in
var offlinePacksArr : [MGLOfflinePack] = object.packs // Access to packs array here
}