npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@tencentcloud/web-push

v1.0.1

Published

Tencent Cloud Web Push SDK - Service Worker-based web push notification service

Readme

Tencent Cloud Web Push SDK

A web-based push notification SDK built on modern Web APIs including Service Worker, Push API, and Notification API.

Features

  • 🚀 Built on modern Web standard APIs
  • 📱 Cross-platform push notification support
  • 🔧 TypeScript support
  • 📊 Built-in analytics functionality
  • 🎯 Event-driven architecture
  • 💾 Local state persistence
  • 🔒 Secure VAPID authentication

Browser Support

  • Chrome 50+
  • Firefox 44+
  • Safari 16+
  • Edge 17+

Integration Step

Step 1: Integrating @Tencentcloud/Web-Push

【npm】

npm install @tencentcloud/web-push --save

【yarn】

yarn add @tencentcloud/web-push

Step 2: Configure the Service Worker File

After integrating @tencentcloud/web-push, copy the Service Worker (sw.js) to your project's root directory. After website deployment, ensure this file can be accessed through https://your-domain.com/sw.js. Otherwise, the browser will be unable to register the Service Worker.

Note:

  • The sw.js file must be placed in the website's root directory to work properly due to browser security restrictions.
  • The sw.js file can only be registered successfully under HTTPS connection (or local development environment localhost). Ensure your live production environment website supports HTTPS.

Role of the public directory: In modern front-end projects (such as Vue, React, Next.js, etc.), the public directory is a unique directory whose content will not be compiled or renamed during build. Files placed in the public directory will be copied to the website's root directory as-is.

Note:

  • Place sw.js in the src or other directories, and it may be compiled or renamed (such as changed into sw.123abcde.js) by packaging tools (Webpack/Vite), thereby failing to register correctly.
  • If your project does not have a public directory (such as old-style HTML projects), place sw.js directly in the same directory as index.html to ensure it is located in the root directory after build output.

【macOS】

cp node_modules/@tencentcloud/web-push/dist/sw.js public/sw.js

【Windows】

copy node_modules\@tencentcloud\web-push\dist\sw.js public\sw.js

Step 3: Register for Push Services

In your homepage (for example: index.js), add @tencentcloud/web-push and register.

import WebPush from '@tencentcloud/web-push';

const SDKAppID = 0; // Your SDKAppID
const appKey = ''; // client key
const userID = ''; // user ID

// Register for push service
await WebPush.registerPush({ SDKAppID, appKey, userID });

// Listen to push messages
WebPush.addPushListener(WebPush.EVENT.MESSAGE_RECEIVED, (message) => {
  console.log('received push message:', message);
});

// Listen to notification click
WebPush.addPushListener(WebPush.EVENT.NOTIFICATION_CLICKED, (data) => {
  console.log('notification clicked:', data);
});

API Reference

Methods

| API | Parameters | Description | | -------------------- | --------------------------------------------------- | -------------------------- | | registerPush | options: RegisterPushOptions | Register push service | | unRegisterPush | - | Unregister push service | | addPushListener | eventName: EVENT, listener: Function<EventResult> | Add push event listener | | removePushListener | eventName: EVENT, listener: Function<EventResult> | Remove push event listener |

Type Definitions

interface RegisterPushOptions {
  SDKAppID: number;
  appKey: string;
  userID: string;
  serviceWorkerPath?: string;
  chat?: any;
}

enum EVENT {
  MESSAGE_RECEIVED = 'message_received',
  MESSAGE_REVOKED = 'message_revoked',
  NOTIFICATION_CLICKED = 'notification_clicked',
}

interface Message {
  ID: string;
  type:
    | 'TIMTextElem'
    | 'TIMImageElem'
    | 'TIMSoundElem'
    | 'TIMVideoFileElem'
    | 'TIMFileElem'
    | 'TIMCustomElem'
    | 'TIMRelayElem'
    | 'TIMLocationElem'
    | 'TIMFaceElem';
  payload: any;
  conversationID: string;
  conversationType: 'C2C' | 'GROUP';
  to: string;
  from: string;
  flow: string;
  time: number;
  status: string;
  isRevoked: boolean;
  nick: string;
  avatar: string;
  isPeerRead: boolean;
  nameCard: string;
  atUserList: string[];
  cloudCustomData: string;
  isDeleted: boolean;
  isModified: boolean;
  needReadReceipt: boolean;
  readReceiptInfo: any;
  isBroadcastMessage: boolean;
  isSupportExtension: boolean;
  receiverList?: string[];
  revoker: string;
  sequence: number;
  progress: number;
  revokerInfo: {
    userID: string;
    nick: string;
    avatar: string;
  };
  revokeReason: string;
  hasRiskContent: boolean;
}

interface MessageReceivedResult {
  message: Message;
}

interface MessageRevokedResult {
  messageID: string;
}

interface MessageNotificationClickedResult {
  ext: string;
}

interface EventResult {
  data:
    | MessageReceivedResult
    | MessageRevokedResult
    | MessageNotificationClickedResult;
}

Event Types

  • MESSAGE_RECEIVED: Received a push message
  • MESSAGE_REVOKED: Message was revoked
  • NOTIFICATION_CLICKED: Notification was clicked

Important Notes

Service Worker Scope

Service Workers must be placed in the website's root directory (e.g., /sw.js) to control push messages across the entire website. Placing them in subdirectories will not function correctly.

HTTPS Requirement

The Web Push API requires websites to use the HTTPS protocol (except for local development environments using localhost).

Browser Permissions

Users need to authorize notification permissions upon first use. Please guide users to authorize permissions at appropriate times.

License

MIT License