Skip to content

Commit

Permalink
Merge pull request #7 from spoonconsulting/on-leave-should-kill-scan
Browse files Browse the repository at this point in the history
On leave should kill scan and isSupported
  • Loading branch information
zfir authored Jun 21, 2024
2 parents e380f95 + f0f45d4 commit 693b3b6
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 10 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@spoonconsulting/cordova-plugin-roomplan",
"version": "1.0.0-beta5",
"version": "1.0.0-beta6",
"description": "",
"main": "index.js",
"scripts": {
Expand Down
14 changes: 12 additions & 2 deletions src/ios/CDVRoomPlan.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import Foundation
import UIKit
import RoomPlan
import ARKit

@objc(CDVRoomPlan)
class CDVRoomPlan: CDVPlugin, RoomCaptureSessionDelegate, RoomCaptureViewDelegate, UIDocumentPickerDelegate {
Expand All @@ -34,8 +35,8 @@ class CDVRoomPlan: CDVPlugin, RoomCaptureSessionDelegate, RoomCaptureViewDelegat
super.init()
}

@objc(openRoomPlan:)
func openRoomPlan(command: CDVInvokedUrlCommand) {
@objc(open:)
func open(command: CDVInvokedUrlCommand) {
self.command = command
roomCaptureView = RoomCaptureView(frame: viewController.view.bounds)
roomCaptureView.captureSession.delegate = self
Expand All @@ -48,9 +49,17 @@ class CDVRoomPlan: CDVPlugin, RoomCaptureSessionDelegate, RoomCaptureViewDelegat
roomCaptureView.bottomAnchor.constraint(equalTo: viewController.view.bottomAnchor),
roomCaptureView.rightAnchor.constraint(equalTo: viewController.view.rightAnchor)
]);
NotificationCenter.default.addObserver(self, selector: #selector(cancelScanning), name: UIApplication.willResignActiveNotification, object: nil)
startSession()
}

@objc(isSupported:)
func isSupported(command: CDVInvokedUrlCommand) {
let pluginResult = CDVPluginResult(status: CDVCommandStatus_OK, messageAs: ARWorldTrackingConfiguration.supportsSceneReconstruction(.mesh))
pluginResult?.keepCallback = true
self.commandDelegate.send(pluginResult, callbackId: command.callbackId)
}

private func startSession() {
state = "scanning"
roomCaptureView?.captureSession.run(configuration: roomCaptureSessionConfig)
Expand Down Expand Up @@ -94,6 +103,7 @@ class CDVRoomPlan: CDVPlugin, RoomCaptureSessionDelegate, RoomCaptureViewDelegat
self.activityIndicator?.stopAnimating()
stopSession()
roomCaptureView.removeFromSuperview()
NotificationCenter.default.removeObserver(self)
let result = ["message": "Scanning cancelled"]
let pluginResult = CDVPluginResult(status: CDVCommandStatus_OK, messageAs: result)
pluginResult?.keepCallback = true
Expand Down
15 changes: 10 additions & 5 deletions www/CDVRoomPlan.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
var exec = require('cordova/exec');
var exec = require("cordova/exec");

exports.openRoomPlan = function(success, error) {
console.log("CDVRoomPlan.js: openRoomPlan");
exec(success, error, "CDVRoomPlan", "openRoomPlan", []);
};
exports.open = function (success, error) {
console.log("CDVRoomPlan.js: open");
exec(success, error, "CDVRoomPlan", "open", []);
};

exports.isSupported = function (success, error) {
console.log("CDVRoomPlan.js: isSupported");
exec(success, error, "CDVRoomPlan", "isSupported", []);
}

0 comments on commit 693b3b6

Please sign in to comment.