@@ -291,6 +291,7 @@ async def process_message(self):
291
291
elif action == "leave" :
292
292
# special user presence message, new way to remove user
293
293
if object_id in self .users :
294
+ self .delete_user_objects (object_id )
294
295
if self .user_left_callback :
295
296
self .callback_wrapper (self .user_left_callback , self .users [object_id ], payload )
296
297
del self .users [object_id ]
@@ -347,6 +348,7 @@ async def process_message(self):
347
348
self .users [object_id ] = obj
348
349
else :
349
350
self .users [object_id ] = Camera (** payload )
351
+ self .reset_private_objects (object_id )
350
352
351
353
if self .user_join_callback :
352
354
self .callback_wrapper (self .user_join_callback , self .users [object_id ], payload )
@@ -463,10 +465,24 @@ def all_objects(self):
463
465
"""Returns all the objects in a scene"""
464
466
return Object .all_objects
465
467
468
+ def get_private_objects (self , userid = None ):
469
+ """ Returns all private user objects"""
470
+ if userid is not None :
471
+ return Object .private_objects .get (userid , None )
472
+ else :
473
+ return Object .private_objects
474
+
475
+ def reset_private_objects (self , userid ):
476
+ """Resets all private user objects"""
477
+ Object .private_objects [userid ] = {}
478
+
466
479
def add_object (self , obj ):
467
480
"""Public function to create an object"""
468
481
if not isinstance (obj , Object ):
469
482
raise ValueError (f"Not a valid ARENA object to add to scene: { type (obj )} " )
483
+ # We have to set program_id here, as only scene has access to its userid
484
+ if getattr (obj , "private" , True ):
485
+ obj .program_id = self .userid
470
486
res = self ._publish (obj , "create" )
471
487
self .run_animations (obj )
472
488
return res
@@ -482,6 +498,10 @@ def update_object(self, obj: Object, **kwargs):
482
498
if kwargs :
483
499
obj .update_attributes (** kwargs )
484
500
501
+ # We have to update program_id here, as only scene has access to its userid
502
+ if getattr (obj , "private" , True ):
503
+ obj .program_id = self .userid
504
+
485
505
# Check if any keys in delayed_prop_tasks are pending new animations
486
506
# and cancel corresponding final update tasks or, if they are in
487
507
# kwarg property updates, cancel the task as well as the animation
@@ -518,6 +538,13 @@ def delete_object(self, obj):
518
538
Object .remove (obj )
519
539
return self ._publish (payload , "delete" , custom_payload = True )
520
540
541
+ def delete_user_objects (self , userid ):
542
+ """Deletes any private user objects"""
543
+ if userid in Object .private_objects :
544
+ for obj in Object .private_objects [userid ].keys ():
545
+ Object .all_objects .pop (obj , None )
546
+ del Object .private_objects [userid ]
547
+
521
548
def delete_program (self , obj ):
522
549
type = None
523
550
try :
@@ -611,12 +638,17 @@ def _publish(self, obj: Object, action, custom_payload=False, publish_topic=PUBL
611
638
with self .telemetry .start_publish_span (obj ["object_id" ], action , obj_type ) as span :
612
639
topic = publish_topic .substitute ({** self .topicParams , ** {"objectId" : obj ["object_id" ]}})
613
640
614
- # self.can_publish_obj indicates if we can publish on the default publish_topic (PUBLISH_TOPICS.SCENE_OBJECTS)
615
- if not self .can_publish_obj and publish_topic == PUBLISH_TOPICS .SCENE_OBJECTS :
616
- self .telemetry .set_error (
617
- f"ERROR: Publish failed! You do not have permission to publish to topic { topic } on { self .web_host } " ,
618
- span ,
619
- )
641
+ if publish_topic == PUBLISH_TOPICS .SCENE_OBJECTS :
642
+ # self.can_publish_obj indicates if we can publish on the default publish_topic (PUBLISH_TOPICS.SCENE_OBJECTS)
643
+ if not self .can_publish_obj :
644
+ self .telemetry .set_error (
645
+ f"ERROR: Publish failed! You do not have permission to publish to topic { topic } on { self .web_host } " ,
646
+ span ,
647
+ )
648
+ elif hasattr (obj , "_private_userid" ):
649
+ topic = PUBLISH_TOPICS .SCENE_OBJECTS_PRIVATE .substitute (
650
+ {** self .topicParams , ** {"objectId" : obj ['object_id' ], "toUid" : obj ['_private_userid' ]}}
651
+ )
620
652
621
653
d = datetime .utcnow ().isoformat ()[:- 3 ] + "Z"
622
654
0 commit comments