Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2025 EclipseSource and others.
* Copyright (c) 2025, 2026 EclipseSource and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand All @@ -18,15 +18,17 @@

rwt.widgets.Camera = function( properties ) {
bindAll( this, [ "init", "layout", "start", "stop", "takePicture", "showNextVideoInputDevice",
"isRunning", "onRender", "destroy" ] );
"isRunning", "onRender", "destroy", "capture" ] );
this.parent = rap.getObject( properties.parent );
this.uploadPath = properties.uploadPath;
this.canvasElement = document.createElement( "canvas" );
this.videoElement = document.createElement( "video" );
this.cameraFlipElement = document.createElement( "img" );
this.cameraCaptureElement = document.createElement( "img" );
this.parent.append( this.videoElement );
this.parent.append( this.canvasElement );
this.parent.append( this.cameraFlipElement );
this.parent.append( this.cameraCaptureElement );
this.parent.addListener( "Resize", this.layout );
this.parent.addListener( "Dispose", this.destroy );
this.videoInputDeviceId = null;
Expand All @@ -46,9 +48,11 @@
destroy : function() {
this.stop();
this.cameraFlipElement.removeEventListener( "click", this.showNextVideoInputDevice );
this.cameraCaptureElement.removeEventListener( "click", this.capture );
this.canvasElement.parentNode.removeChild( this.canvasElement );
this.videoElement.parentNode.removeChild( this.videoElement );
this.cameraFlipElement.parentNode.removeChild( this.cameraFlipElement );
this.cameraCaptureElement.parentNode.removeChild( this.cameraCaptureElement );
},

init : async function() {
Expand All @@ -60,7 +64,15 @@
this.cameraFlipElement.height = 32;
this.cameraFlipElement.style.position = "absolute";
this.cameraFlipElement.style.cursor = "pointer";
this.cameraFlipElement.style.visibility = "hidden";
this.cameraFlipElement.addEventListener( "click", this.showNextVideoInputDevice );
this.cameraCaptureElement.src = "rwt-resources/camera/circle-slice-8-64.png";
this.cameraCaptureElement.width = 64;
this.cameraCaptureElement.height = 64;
this.cameraCaptureElement.style.position = "absolute";
this.cameraCaptureElement.style.cursor = "pointer";
this.cameraCaptureElement.style.visibility = "hidden";
this.cameraCaptureElement.addEventListener( "click", this.capture );
this.videoInputDeviceId = await initVideoInputDeviceId();
},

Expand All @@ -71,7 +83,11 @@
this.videoElement.width = area[ 2 ];
this.videoElement.height = area[ 3 ];
this.cameraFlipElement.style.top = "5px";
this.cameraFlipElement.style.left = "5px";
this.cameraFlipElement.style.left = "20px";
this.cameraFlipElement.style.visibility = "visible";
this.cameraCaptureElement.style.top = "40px";
this.cameraCaptureElement.style.left = "5px";
this.cameraCaptureElement.style.visibility = "visible";
},

start : async function() {
Expand Down Expand Up @@ -136,6 +152,10 @@
}
},

capture : function() {
this.takePicture( { compressionQuality : 1 } );
},

showNextVideoInputDevice : async function() {
var running = this.isRunning();
if( running ) {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2025 EclipseSource and others.
* Copyright (c) 2025, 2026 EclipseSource and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -60,7 +60,9 @@ public class Camera extends Composite {
private static final String RESOURCES_PATH = "org/eclipse/rap/rwt/addons/camera/";
private static final String REGISTER_PATH = "camera/";

private static final String[] RESOURCES_FILES = { "Camera.js", "camera-flip-32.png" };
private static final String[] RESOURCES_FILES = {
"Camera.js", "camera-flip-32.png", "circle-slice-8-64.png"
};
private static final String REMOTE_TYPE = "rwt.widgets.Camera";

private final RemoteObject remoteObject;
Expand All @@ -80,6 +82,7 @@ public Camera( Composite parent, int style ) {
remoteObject.set( PROPERTY_PARENT, getId( this ) );
cameraListeners = new ArrayList<CameraListener>();
serverPush = new ServerPushSession();
serverPush.start();
String uploadPath = registerFileUploadServiceHandler();
remoteObject.set( PROPERTY_UPLOAD_PATH, stripContextPath( uploadPath ) );
}
Expand All @@ -98,7 +101,6 @@ public void takePicture( CameraOptions options ) {
SWT.error( SWT.ERROR_NULL_ARGUMENT );
}
remoteObject.call( METHOD_TAKE_PICTURE, createProperties( options ) );
serverPush.start();
}

/**
Expand Down Expand Up @@ -131,6 +133,7 @@ public void removeCameraListener( CameraListener listener ) {
public void dispose() {
if( !isDisposed() ) {
remoteObject.destroy();
serverPush.stop();
}
super.dispose();
}
Expand Down Expand Up @@ -201,7 +204,6 @@ void handleUploadFailed( Display display, final ImageUploadReceiver receiver ) {
public void run() {
notifyListenersWithoutPicture();
receiver.reset();
serverPush.stop();
}
} );
}
Expand All @@ -214,7 +216,6 @@ void handleUploadFinished( Display display, final ImageUploadReceiver receiver )
public void run() {
notifyListenersWithImage( receiver.getImage() );
receiver.reset();
serverPush.stop();
}
} );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@ public void testIsSerializable() {
assertTrue( Serializable.class.isAssignableFrom( Camera.class ) );
}

@Test
public void testConstructor_activatesServerPush() {
assertTrue( ServerPushManager.getInstance().isServerPushActive() );
}

@Test
public void testDisposal_deactivatesServerPush() {
camera.dispose();

assertFalse( ServerPushManager.getInstance().isServerPushActive() );
}

@Test
public void testCameraListenerIsSerializable() {
assertTrue( Serializable.class.isAssignableFrom( CameraListener.class ) );
Expand Down Expand Up @@ -109,13 +121,6 @@ public void testRemoveFailsWithNullListener() {
camera.removeCameraListener( null );
}

@Test
public void testDelegatesImage_activatesServerPush() {
camera.takePicture( createOptions() );

assertTrue( ServerPushManager.getInstance().isServerPushActive() );
}

@Test
public void testDelegatesImage_withFailedUpload() {
CameraListener listener = mock( CameraListener.class );
Expand All @@ -128,7 +133,6 @@ public void testDelegatesImage_withFailedUpload() {

verify( listener ).receivedPicture( null );
verify( receiver ).reset();
assertFalse( ServerPushManager.getInstance().isServerPushActive() );
}

@Test
Expand All @@ -145,7 +149,6 @@ public void testDelegatesImage_withSuccessfulUpload() {

verify( listener ).receivedPicture( image );
verify( receiver ).reset();
assertFalse( ServerPushManager.getInstance().isServerPushActive() );
}

@Test
Expand Down