@pushprotocol/socket
Advanced tools
Comparing version
@@ -5,2 +5,14 @@ # Changelog | ||
# [0.2.0](https://github.com/ethereum-push-notification-service/push-sdk/compare/socket-0.1.0...socket-0.2.0) (2023-01-23) | ||
### Features | ||
* add chat wss ([aba9f17](https://github.com/ethereum-push-notification-service/push-sdk/commit/aba9f17c037fe59e44729c9b49c8eaa9e2a71630)) | ||
* add new chat events for websocket ([429061f](https://github.com/ethereum-push-notification-service/push-sdk/commit/429061f2f906420f5fe3d854d3602277dae1021b)) | ||
* add new types for create wss function ([d5a11ed](https://github.com/ethereum-push-notification-service/push-sdk/commit/d5a11ed9f5336f0a8197707cbe29848eb2faad54)) | ||
* add validation for chat websocket ([9b77ff7](https://github.com/ethereum-push-notification-service/push-sdk/commit/9b77ff7102475f8b4187028c9fc5cb68c94c4985)) | ||
# [0.1.0](https://github.com/ethereum-push-notification-service/sdk/compare/socket-0.0.1...socket-0.1.0) (2022-10-07) | ||
@@ -7,0 +19,0 @@ |
{ | ||
"name": "@pushprotocol/socket", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"type": "commonjs", | ||
@@ -5,0 +5,0 @@ "publishConfig": { |
import { SocketInputOptions } from '../types'; | ||
export declare function createSocketConnection({ user, env, socketOptions }: SocketInputOptions): import("socket.io-client").Socket<import("@socket.io/component-emitter").DefaultEventsMap, import("@socket.io/component-emitter").DefaultEventsMap> | null; | ||
export declare function createSocketConnection({ user, env, socketType, apiKey, socketOptions }: SocketInputOptions): import("socket.io-client").Socket<import("@socket.io/component-emitter").DefaultEventsMap, import("@socket.io/component-emitter").DefaultEventsMap> | null; |
@@ -7,12 +7,23 @@ "use strict"; | ||
const helpers_1 = require("../helpers"); | ||
function createSocketConnection({ user, env, socketOptions }) { | ||
function createSocketConnection({ user, env, socketType = 'notification', apiKey, socketOptions }) { | ||
const { autoConnect = true, reconnectionAttempts = 5, } = socketOptions || {}; | ||
const epnsWSUrl = config_1.API_URLS[env]; | ||
if (socketType === 'chat' && !apiKey) { | ||
throw Error('apiKey is necessary for chat'); | ||
} | ||
const pushWSUrl = config_1.API_URLS[env]; | ||
console.log(env); | ||
console.log(pushWSUrl); | ||
const transports = ['websocket']; | ||
let epnsSocket = null; | ||
let pushSocket = null; | ||
try { | ||
const userAddressInCAIP = (0, helpers_1.getCAIPAddress)(env, user, 'User'); | ||
// the backend only accepts CAIP | ||
const query = { address: userAddressInCAIP }; | ||
epnsSocket = (0, socket_io_client_1.io)(epnsWSUrl, { | ||
const userAddressInCAIP = socketType === 'chat' | ||
? (0, helpers_1.walletToPCAIP10)(user) | ||
: (0, helpers_1.getCAIPAddress)(env, user, 'User'); | ||
let query; | ||
if (socketType === 'notification') | ||
query = { address: userAddressInCAIP }; | ||
else | ||
query = { mode: 'chat', did: userAddressInCAIP, apiKey }; | ||
console.log(config_1.API_URLS); | ||
pushSocket = (0, socket_io_client_1.io)(pushWSUrl, { | ||
transports, | ||
@@ -25,3 +36,3 @@ query, | ||
catch (e) { | ||
console.error('[EPNS-SDK] - Socket connection error: '); | ||
console.error('[PUSH-SDK] - Socket connection error: '); | ||
console.error(e); | ||
@@ -31,3 +42,3 @@ } | ||
// eslint-disable-next-line no-unsafe-finally | ||
return epnsSocket; | ||
return pushSocket; | ||
} | ||
@@ -34,0 +45,0 @@ } |
@@ -11,2 +11,7 @@ export declare const ENV: { | ||
USER_SPAM_FEEDS: string; | ||
CHAT_SEND_MESSAGE: string; | ||
CHAT_CREATE_INTENT: string; | ||
CHAT_UPDATE_INTENT: string; | ||
CHAT_SEND_MESSAGE_ERROR: string; | ||
CHAT_RECEIVED_MESSAGE: string; | ||
}; |
@@ -10,7 +10,15 @@ "use strict"; | ||
exports.EVENTS = { | ||
// Websocket | ||
CONNECT: 'connect', | ||
DISCONNECT: 'disconnect', | ||
// Notification | ||
USER_FEEDS: 'userFeeds', | ||
USER_SPAM_FEEDS: 'userSpamFeeds' | ||
USER_SPAM_FEEDS: 'userSpamFeeds', | ||
// Chat | ||
CHAT_SEND_MESSAGE: 'CHAT_SEND', | ||
CHAT_CREATE_INTENT: 'CREATE_INTENT', | ||
CHAT_UPDATE_INTENT: 'UPDATE_INTENT', | ||
CHAT_SEND_MESSAGE_ERROR: 'CHAT_ERROR', | ||
CHAT_RECEIVED_MESSAGE: 'CHATS' | ||
}; | ||
//# sourceMappingURL=constants.js.map |
@@ -20,1 +20,2 @@ export interface AddressValidatorsType { | ||
export declare function getCAIPAddress(env: string, address: string, msg?: string): string; | ||
export declare const walletToPCAIP10: (account: string) => string; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getCAIPAddress = exports.getFallbackETHCAIPAddress = exports.validateCAIP = exports.isValidETHAddress = void 0; | ||
exports.walletToPCAIP10 = exports.getCAIPAddress = exports.getFallbackETHCAIPAddress = exports.validateCAIP = exports.isValidETHAddress = void 0; | ||
// import * as ethers from 'ethers'; | ||
@@ -62,2 +62,9 @@ const ethers_1 = require("ethers"); | ||
exports.getCAIPAddress = getCAIPAddress; | ||
const walletToPCAIP10 = (account) => { | ||
if (account.includes('eip155:')) { | ||
return account; | ||
} | ||
return 'eip155:' + account; | ||
}; | ||
exports.walletToPCAIP10 = walletToPCAIP10; | ||
//# sourceMappingURL=helpers.js.map |
export declare type SocketInputOptions = { | ||
user: string; | ||
env: string; | ||
socketOptions?: any; | ||
socketType?: 'notification' | 'chat'; | ||
apiKey?: string; | ||
socketOptions?: SocketOptions; | ||
}; | ||
export declare type SocketOptions = { | ||
autoConnect: boolean; | ||
reconnectionAttempts?: number; | ||
}; | ||
/** | ||
@@ -7,0 +13,0 @@ * TODO define types for |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
18844
17.59%237
19.7%