@@ -37,7 +37,7 @@ def generate_arena_token(
37
37
user ,
38
38
username ,
39
39
realm = "realm" ,
40
- scene = None ,
40
+ namespaced_scene = None ,
41
41
device = None ,
42
42
camid = None ,
43
43
userid = None ,
@@ -83,29 +83,32 @@ def generate_arena_token(
83
83
p_anonymous_users = SCENE_ANON_USERS_DEF
84
84
p_video = SCENE_VIDEO_CONF_DEF
85
85
p_users = SCENE_USERS_DEF
86
- if scene and Scene .objects .filter (name = scene ).exists ():
87
- scene_perm = Scene .objects .get (name = scene )
86
+
87
+ # create permissions shorthand
88
+ if namespaced_scene and Scene .objects .filter (name = namespaced_scene ).exists ():
89
+ scene_perm = Scene .objects .get (name = namespaced_scene )
88
90
p_public_read = scene_perm .public_read
89
91
p_public_write = scene_perm .public_write
90
92
p_anonymous_users = scene_perm .anonymous_users
91
93
p_video = scene_perm .video_conference
92
94
p_users = scene_perm .users
93
95
94
96
# add jitsi server params if a/v scene
95
- if scene and camid and p_users and p_video :
97
+ if namespaced_scene and camid and p_users and p_video :
96
98
host = os .getenv ("HOSTNAME" )
97
99
headers = {"kid" : host }
98
100
payload ["aud" ] = "arena"
99
101
payload ["iss" ] = "arena-account"
100
- # we use the scene name as the jitsi room name, handle RFC 3986 reserved chars as = '_'
101
- roomname = re .sub (r"[!#$&'()*+,\/:;=?@[\]]" , '_' , scene .lower ())
102
+ # we use the namespace + scene name as the jitsi room name, handle RFC 3986 reserved chars as = '_'
103
+ roomname = re .sub (r"[!#$&'()*+,\/:;=?@[\]]" , '_' , namespaced_scene .lower ())
102
104
payload ["room" ] = roomname
103
105
104
106
# everyone should be able to read all public scenes
105
107
if not device : # scene token scenario
106
108
subs .append (f"{ realm } /s/{ PUBLIC_NAMESPACE } /#" )
107
109
# And transmit env data
108
110
pubs .append (f"{ realm } /env/{ PUBLIC_NAMESPACE } /#" )
111
+
109
112
# user presence objects
110
113
if user .is_authenticated :
111
114
if device : # device token scenario
@@ -122,8 +125,8 @@ def generate_arena_token(
122
125
subs .append (f"{ realm } /env/#" )
123
126
pubs .append (f"{ realm } /env/#" )
124
127
# vio experiments, staff only
125
- if scene :
126
- pubs .append (f"{ realm } /vio/{ scene } /#" )
128
+ if namespaced_scene :
129
+ pubs .append (f"{ realm } /vio/{ namespaced_scene } /#" )
127
130
else :
128
131
# scene owners have rights to their scene objects only
129
132
subs .append (f"{ realm } /s/{ username } /#" )
@@ -134,7 +137,7 @@ def generate_arena_token(
134
137
# add scenes that have been granted by other owners
135
138
u_scenes = Scene .objects .filter (editors = user )
136
139
for u_scene in u_scenes :
137
- if not scene or (scene and u_scene .name == scene ):
140
+ if not namespaced_scene or (namespaced_scene and u_scene .name == namespaced_scene ):
138
141
subs .append (f"{ realm } /s/{ u_scene .name } /#" )
139
142
pubs .append (f"{ realm } /s/{ u_scene .name } /#" )
140
143
subs .append (f"{ realm } /env/{ u_scene .name } /#" )
@@ -148,47 +151,52 @@ def generate_arena_token(
148
151
# device owners have rights to their device objects only
149
152
subs .append (f"{ realm } /d/{ username } /#" )
150
153
pubs .append (f"{ realm } /d/{ username } /#" )
154
+
151
155
# anon/non-owners have rights to view scene objects only
152
- if scene and not user .is_staff :
156
+ if namespaced_scene and not user .is_staff :
153
157
# did the user set specific public read or public write?
154
158
if not user .is_authenticated and not p_anonymous_users :
155
159
return None # anonymous not permitted
156
160
if p_public_read :
157
- subs .append (f"{ realm } /s/{ scene } /#" )
161
+ subs .append (f"{ realm } /s/{ namespaced_scene } /#" )
158
162
# Interactivity to extent of viewing objects is similar to publishing env
159
- pubs .append (f"{ realm } /env/{ scene } /#" )
163
+ pubs .append (f"{ realm } /env/{ namespaced_scene } /#" )
160
164
if p_public_write :
161
- pubs .append (f"{ realm } /s/{ scene } /#" )
165
+ pubs .append (f"{ realm } /s/{ namespaced_scene } /#" )
162
166
# user presence objects
163
167
if camid and p_users : # probable web browser write
164
- pubs .append (f"{ realm } /s/{ scene } /{ camid } " )
165
- pubs .append (f"{ realm } /s/{ scene } /{ camid } /#" )
168
+ pubs .append (f"{ realm } /s/{ namespaced_scene } /{ camid } " )
169
+ pubs .append (f"{ realm } /s/{ namespaced_scene } /{ camid } /#" )
166
170
if handleftid and p_users :
167
- pubs .append (f"{ realm } /s/{ scene } /{ handleftid } " )
171
+ pubs .append (f"{ realm } /s/{ namespaced_scene } /{ handleftid } " )
168
172
if handrightid and p_users :
169
- pubs .append (f"{ realm } /s/{ scene } /{ handrightid } " )
173
+ pubs .append (f"{ realm } /s/{ namespaced_scene } /{ handrightid } " )
174
+
170
175
# chat messages
171
- if scene and userid and p_users :
172
- namespace = scene .split ("/" )[0 ]
173
- userhandle = userid + base64 .b64encode (userid .encode ()).decode ()
176
+ if namespaced_scene and userid and p_users :
177
+ namespace = namespaced_scene .split ("/" )[0 ]
174
178
# receive private messages: Read
175
179
subs .append (f"{ realm } /c/{ namespace } /p/{ userid } /#" )
176
180
# receive open messages to everyone and/or scene: Read
177
181
subs .append (f"{ realm } /c/{ namespace } /o/#" )
178
182
# send open messages (chat keepalive, messages to all/scene): Write
179
- pubs .append (f"{ realm } /c/{ namespace } /o/{ userhandle } " )
183
+ pubs .append (f"{ realm } /c/{ namespace } /o/{ userid } " )
180
184
# private messages to user: Write
181
- pubs .append (f"{ realm } /c/{ namespace } /p/+/{ userhandle } " )
185
+ pubs .append (f"{ realm } /c/{ namespace } /p/+/{ userid } " )
186
+
182
187
# apriltags
183
- if scene :
188
+ if namespaced_scene :
184
189
subs .append (f"{ realm } /g/a/#" )
185
190
pubs .append (f"{ realm } /g/a/#" )
186
- # arts runtime-mngr
191
+
192
+ # runtime manager
187
193
subs .append (f"{ realm } /proc/#" )
188
194
pubs .append (f"{ realm } /proc/#" )
189
- # network graph
195
+
196
+ # network metrics
190
197
subs .append ("$NETWORK" )
191
198
pubs .append ("$NETWORK/latency" )
199
+
192
200
if len (subs ) > 0 :
193
201
payload ["subs" ] = clean_topics (subs )
194
202
if len (pubs ) > 0 :
0 commit comments