push-notification - Electron 推送通知

标签 push-notification electron

有什么方法可以在 Electron 中使用Firebase推送通知?我想为我的 Electron 应用程序(一个聊天应用程序)创建一个推送通知,每当收到新消息时我都希望获得该通知。实现它。我该怎么办?

最佳答案

您可以使用Pushy (paid product),或者如果您愿意自己实现,请使用Websocket。

适用于websocket的Python代码段

客户端:

from ws4py.client.threadedclient import WebSocketClient
client_url = "ws://server_url + "/websocket/create
ws_client = WebsocketClient(client_url)
ws_client.connect()

服务器端:假设您有一台服务器,其中server_url为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

并在服务器的配置中:
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,
                                },
                            })

关于push-notification - Electron 推送通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49212958/

相关文章:

android - GCM服务器java实现空指针异常

webpack - 将 'browser'设置为 'target'后,Webpack将忽略 'electron-renderer'字段

node.js - 在 Linux 上以 root 身份运行 electron

php - 使用 OAuth2.0 的 C2DM 和 PHP(不推荐使用 ClientLogin!)

ios - 在推送通知权限对话框中选择取消后,设置显示通知警报已开启

android - 应用程序被杀死/刷出时的 FCM 推送通知

android - 使用通知导航到带有 navArgs 的 fragment

javascript - 点击后不出现的模态窗口

javascript - 如何在js或 Node js中ping IP

javascript - 如何从 Electron 的主进程访问相机