Is there any way to use firebase push notification in electron?I want to create a push notification for my electron app which is a chat app and whenever a new message comes I want to get that notification.But I did not get any good material online to implement it.How can I do it?
1 Answer
You can use Websocket.
Python Snippet for websocket
Client Side:
from ws4py.client.threadedclient import WebSocketClient
client_url = "ws://server_url + "/websocket/create
ws_client = WebsocketClient(client_url)
ws_client.connect()
Server Side: Assuming you have a server with server_url serving the api /websocket/create:
from ws4py.websocket import WebSocket
class ws_server(Websocket):
WebSocket.__init__(self, *args, **kwargs)
class WebSocketHandler(object):
@cherrypy.expose
def create(self):
# wsInstance is of type ws_server. Must set userName.
wsInstance = cherrypy.request.ws_handler
And in the Server's config:
cherrypy.tree.mount(WebSocketHandler(), '/websocket',
config={
'/': {
'tools.response_headers.on': True,
'tools.sessions.locking': 'explicit',
'tools.websocket.on': True,
'tools.websocket.handler_cls': ws_server,
},
})