Skip to content

Commit 6b4006b

Browse files
committed
test
1 parent 1481f0f commit 6b4006b

File tree

5 files changed

+52
-9
lines changed

5 files changed

+52
-9
lines changed

src/compas_cloud/server.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import sys
99
import traceback
1010
import pkg_resources
11+
from compas_cloud.speckle import Speckle
1112

1213
try:
1314
from compas.data import DataEncoder
@@ -22,6 +23,7 @@ class CompasServerProtocol(WebSocketServerProtocol):
2223
cached = {}
2324
sessions = None
2425
server_type = "NORMAL"
26+
speckle = Speckle()
2527

2628
def onConnect(self, request):
2729
"""print client info on connection"""
@@ -178,6 +180,9 @@ def process(self, data):
178180
if 'version' in data:
179181
result = self.version()
180182

183+
if 'speckle' in data:
184+
result = self.speckle.process_command(data['speckle'])
185+
181186
except BaseException as error:
182187

183188
if isinstance(error, KeyboardInterrupt):
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
from .client import SpeckleClient
1+
from .speckle import Speckle
Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,33 @@
22
from specklepy.api.credentials import get_account_from_token
33
from specklepy.transports.server import ServerTransport
44
from specklepy.api import operations
5-
from data import Data as SpeckleData
5+
from compas_cloud.speckle.data import Data as SpeckleData
66
from compas.data import json_loads
77
import json
88

99

1010
class Speckle():
11-
def __init__(self, host="speckle.xyz", token=None):
11+
12+
def process_command(self, command):
13+
if 'connect' in command:
14+
return self.connect(host=command['connect']['host'], token=command['connect']['token'])
15+
if 'get' in command:
16+
return self.get_item(command['get']['stream_id'])
17+
if 'update' in command:
18+
return self.update_item(command['update']['item'], stream_id=command['update']['stream_id'])
19+
else:
20+
return "Command not found"
21+
22+
def connect(self, host="speckle.xyz", token=None):
23+
print("Connecting to {} with {}".format(host, token))
1224
self.client = SpeckleClient(host=host)
1325
account = get_account_from_token(token, host)
1426
self.client.authenticate_with_account(account)
27+
return "Connected"
1528

1629
def update_item(self, item, stream_id=None, name=None, message=None):
30+
print("CHECK!", item)
31+
print("CHECK!", stream_id)
1732
# Create new stream if stream_id is None
1833
if not stream_id:
1934
stream_id = self.client.stream.create(name=name)
@@ -34,19 +49,23 @@ def get_item(self, stream_id):
3449
data = received_base.data
3550
return json_loads(json.dumps(data))
3651

52+
# def watch_item(self, stream_id, callback):
53+
# item = self.get_item(stream_id)
54+
# callback(item)
3755

3856
if __name__ == "__main__":
3957

4058
import compas
4159
from compas.datastructures import Mesh
4260

43-
client = Speckle(token="5da18a1e41f477bf4d70bce651b151aa6e14d5cc8d")
61+
client = Speckle()
62+
client.connect(token="4b6a06f4c7b114e3b4115e1bba5536261cb4d3bf20")
4463

4564
stream_id = "c0538fd521"
46-
# mesh = Mesh.from_obj(compas.get('faces.obj'))
47-
# stream_id = client.update_item(mesh, name="faces", stream_id=stream_id)
48-
# print(stream_id)
65+
mesh = Mesh.from_obj(compas.get('faces.obj'))
66+
stream_id = client.update_item(mesh, name="faces", stream_id=stream_id)
67+
print(stream_id)
4968

5069
# stream_id = "c0538fd521"
51-
item = client.get_item(stream_id)
52-
print(item)
70+
# item = client.get_item(stream_id)
71+
# print(item)

temp/speckle.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import compas
2+
from compas.datastructures import Mesh
3+
4+
from compas_cloud.proxy import Proxy
5+
6+
p = Proxy()
7+
result = p.send({"speckle": {"connect": {"host": "speckle.xyz", "token": "4b6a06f4c7b114e3b4115e1bba5536261cb4d3bf20"}}})
8+
print("check", result)
9+
10+
mesh = Mesh.from_obj(compas.get('faces.obj'))
11+
# mesh = Mesh.from_off(compas.get('tubemesh.off'))
12+
13+
14+
mesh = p.send({"speckle": {"update": {"stream_id": "c0538fd521", "item": mesh}}})
15+
print(mesh)

temp/test.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from compas_cloud.proxy import Proxy
2+
3+
p = Proxy(speckle={"host": "speckle.xyz", "token": "__YOUR_TOKEN__"})
4+
p.speckle.watch([stream1, stream2, stream3])

0 commit comments

Comments
 (0)