emitter-io / python Goto Github PK
View Code? Open in Web Editor NEWLicense: Eclipse Public License 1.0
License: Eclipse Public License 1.0
I know that's on the documentation as a ToDo, but how can we retrieve the generated key ? Bellow is a sample code, how can we retrieve it following this example?
from emitter import Client
key = "8houiFt2MZ469D0oiBlaibkVcERscGyP"
def onConnect():
print("Connected!")
def onKeygen():
print("Key generated!")
if __name__ == '__main__':
emitter = Client()
emitter.on_connect = onConnect()
emitter.on_keygen = onKeygen()
emitter.connect("localhost", 8080, False, 30)
emitter.keygen(key, "/test/", "rwsl")
emitter.loop_start()
while True:
pass
Hi,
I have a problem setting up this client for the Django project. I created a project with Cookiecutter Django (https://github.com/cookiecutter/cookiecutter-django). The project uses ASGI and Docker. I wanted to add an Emitter client but I couldn't find any documentation about how it can be done. Since this library is based on Paho, I tried setups for Paho. I created mqtt.py to handle the client code and initialized it in both asgi.py and url.py. In both scenarios, the Django server halts. I also couldn't be able to connect to my Emitter Server too. (I can connect with plain Python script). How can I make it properly connected?
mqtt.py
from emitter import Client
master_sub_key = "full_authorized_subscription_key"
master_channel = "/#/"
emitter_host = "api.emitter.io"
emitter_port = "8080"
def on_connect():
print("Connected: \n\n")
def on_disconnect():
print("Disconnected\n\n")
print("Reconnecting in 1 minute...")
time.sleep(60)
emitter.connect(host=emitter_host, port=emitter_port, secure=False)
def on_error(e):
print(f"Error received: {str(e)}\n\n")
def on_me(me):
print(f"Information about Me received: {str(me)}\n\n")
def on_subscribe(m, channel):
print(f"Message received on handler for {channel}: {m.as_string()}\n\n"),
def on_presence(p):
print(f"Presence message on channel: '{str(p)}'\n\n"),
def on_keygen(kg):
print(f"Keygen message received: {str(kg)}\n\n")
def on_keyban(kb):
print(f"Keyban message received: {str(kb)}\n\n")
def on_message(m):
print(
f"Message received on default handler, destined to {m.channel}: {m.as_string()}\n\n"
)
def mqtt_setup():
emitter = Client()
emitter.on_connect = on_connect
emitter.on_disconnect = on_disconnect
emitter.on_error = on_error
emitter.on_keygen = on_keygen
emitter.on_keyban = on_keyban
emitter.on_me = on_me
emitter.on_presence = on_presence
emitter.on_message = on_message
emitter.connect(host=emitter_host, port=emitter_port, secure=False)
emitter.subscribe(
master_sub_key,
master_channel,
optional_handler=lambda m: on_subscribe(m, master_channel),
options={Client.with_last(5)},
)
emitter.loop_start()
urls.py
# ****
from .mqtt import mqtt_setup
mqtt_setup()
# ****
Is it possible to generate a key for a channel using instance.keygen?
As mentioned in the docs .link() method is used to create 2 char links. As I understand that is a shorthand for channels. There is a .publish_with_lik() method but no .subscribe_with_lik() method. How can I utilize links?
Hi,
There is one thing that confused me about the source code when I was reading emitter.py and here is the code:
def _format_channel(key, channel, options={}):
k = key.strip("/")
c = channel.strip("/")
o = Client._format_options(options)
formatted = "{key}/{channel}/{options}".format(key=k, channel=c, options=o)
return formatted
The code here indicates that whatever the channel is, a "/{options}" will be added after it. However, this makes it impossible to use the wildcard '#' since it has to be the last charactor in the topic.
Or is there a special way to use the wildcard '#' in Emitter?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.