Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ a minimal application to connect to a channel and send events.
- [`activityTimeout (double)`](#activitytimeout-double)
- [`apiKey (string)`](#apikey-string)
- [`authEndpoint (string)`](#authendpoint-string)
- [`host (string)`](#host-string)
- [`wsPort (string)`](#wsPort-number)
- [`wssPort (string)`](#wssPort-number)
- [`cluster (string)`](#cluster-string)
- [`host (string)`](#host-string)
- [`wsPort (number)`](#wsport-number)
- [`wssPort (number)`](#wssport-number)
- [`useTLS (bool)`](#usetls-bool)
- [Event Callback parameters](#event-callback-parameters)
- [`onEvent`](#onevent)
Expand Down Expand Up @@ -161,10 +161,10 @@ describes available parameters for each platform:
| activityTimeout | ✅ | ✅ |
| apiKey | ✅ | ✅ |
| authEndpoint | ✅ | ✅ |
| cluster | ✅ | ✅ |
| host | ✅ | ✅ |
| wsPort | ✅ | ✅ |
| wssPort | ✅ | ✅ |
| cluster | ✅ | ✅ |
| maxReconnectGapInSeconds | ✅ | ✅ |
| maxReconnectionAttempts | ✅ | ✅ |
| pongTimeout | ✅ | ✅ |
Expand All @@ -174,11 +174,11 @@ describes available parameters for each platform:

#### `activityTimeout (double)`

If no messages are received after this time period (in seconds), the ping message is sent to check if the connection is still working. The server supplies the default value, low values result in unnecessary traffic.
If no messages are received after this time period (in seconds), the ping message is sent to check if the connection is still working. The server supplies the default value, low values result in unnecessary traffic.

#### `apiKey (string)`

You can get your `APP_KEY` and `APP_CLUSTER` from the the App page on the App Keys section in your [Pusher Channels Dashboard](https://dashboard.pusher.com/)
You can get your `APP_KEY` and `APP_CLUSTER` from the App page on the App Keys section in your [Pusher Channels Dashboard](https://dashboard.pusher.com/)

#### `authEndpoint (string)`

Expand All @@ -203,13 +203,25 @@ Specifies the wssPort that pusher-js should connect to. If you do not specify a

Specifies the cluster that pusher-js should connect to. Here's the full list of [Pusher clusters](https://pusher.com/docs/clusters). If you do not specify a cluster, `mt1` will be used by default.

#### `host (string)`

Specifies the host that the Pusher client should connect to. If you do not specify a host, the default Pusher host will be used.

#### `wsPort (number)`

Specifies the port that the Pusher client should use for unencrypted WebSocket connections. If not specified, `80` will be used by default.

#### `wssPort (number)`

Specifies the port that the Pusher client should use for encrypted WebSocket connections. If not specified, `443` will be used by default.

#### `useTLS (bool)`

Whether or not you would like to use TLS encrypted transport or not, default is `true`.

#### `authorizerTimeoutInSeconds (double)`

If onAuthorizer callback is not called in Javascript before this time period (in seconds), the authorization for the channel will timeout on the native side. Default value: 10 seconds. iOS only.
If onAuthorizer callback is not called in Javascript before this time period (in seconds), the authorization for the channel will time out on the native side. Default value: 10 seconds. iOS only.


## Event Callback parameters
Expand Down Expand Up @@ -317,7 +329,7 @@ The connection can have different states, as follows:
- `CONNECTED` - Connection successfully established
- `DISCONNECTING` - Connection is about to be disconnected.
- `DISCONNECTED` - Connection has been disconnected with no attempts to automatically reconnect.
- `RECONNECTING` - Atempting to re-establish the connection.
- `RECONNECTING` - Attempting to re-establish the connection.

#### `onError`

Expand Down
20 changes: 10 additions & 10 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@

const [apiKey, onChangeApiKey] = React.useState('');
const [host, onChangeHost] = React.useState('');
const [wsPort, onChangeWsPort] = React.useState(80);
const [wssPort, onChangeWssPort] = React.useState(443);
const [wsPort, onChangeWsPort] = React.useState('');
const [wssPort, onChangeWssPort] = React.useState('');
const [cluster, onChangeCluster] = React.useState('');
const [channelName, onChangeChannelName] = React.useState('');
const [eventName, onChangeEventName] = React.useState('');
Expand Down Expand Up @@ -69,10 +69,10 @@

await pusher.init({
apiKey,
host,
wsPort,
wssPort,
cluster,
host: host || undefined,
wsPort: wsPort ? Number(wsPort) : undefined,
wssPort: wssPort ? Number(wssPort) : undefined,
// authEndpoint
// ============
// You can let the pusher library call an endpoint URL,
Expand Down Expand Up @@ -123,7 +123,7 @@
log(`onEvent: ${event}`);
};

const onSubscriptionSucceeded = (channelName: string, data: any) => {

Check warning on line 126 in example/src/App.tsx

View workflow job for this annotation

GitHub Actions / build

'channelName' is already declared in the upper scope on line 32 column 10
log(
`onSubscriptionSucceeded: ${channelName} data: ${JSON.stringify(data)}`
);
Expand All @@ -139,7 +139,7 @@
};

const onSubscriptionCount = (
channelName: string,

Check warning on line 142 in example/src/App.tsx

View workflow job for this annotation

GitHub Actions / build

'channelName' is already declared in the upper scope on line 32 column 10
subscriptionCount: Number
) => {
log(
Expand All @@ -148,18 +148,18 @@
};

const onSubscriptionError = (
channelName: string,

Check warning on line 151 in example/src/App.tsx

View workflow job for this annotation

GitHub Actions / build

'channelName' is already declared in the upper scope on line 32 column 10
message: string,
e: any
) => {
log(`onSubscriptionError: ${message}, channelName: ${channelName} e: ${e}`);
};

const onDecryptionFailure = (eventName: string, reason: string) => {

Check warning on line 158 in example/src/App.tsx

View workflow job for this annotation

GitHub Actions / build

'eventName' is already declared in the upper scope on line 33 column 10
log(`onDecryptionFailure: ${eventName} reason: ${reason}`);
};

const onMemberAdded = (channelName: string, member: PusherMember) => {

Check warning on line 162 in example/src/App.tsx

View workflow job for this annotation

GitHub Actions / build

'channelName' is already declared in the upper scope on line 32 column 10
log(`onMemberAdded: ${channelName} user: ${member}`);
const channel: PusherChannel | undefined = pusher.getChannel(channelName);

Expand All @@ -170,7 +170,7 @@
onChangeMembers([...channel.members.values()]);
};

const onMemberRemoved = (channelName: string, member: PusherMember) => {

Check warning on line 173 in example/src/App.tsx

View workflow job for this annotation

GitHub Actions / build

'channelName' is already declared in the upper scope on line 32 column 10
log(`onMemberRemoved: ${channelName} user: ${member}`);
const channel: PusherChannel | undefined = pusher.getChannel(channelName);

Expand All @@ -182,7 +182,7 @@
};

// See https://pusher.com/docs/channels/library_auth_reference/auth-signatures/ for the format of this object.
const onAuthorizer = async (channelName: string, socketId: string) => {

Check warning on line 185 in example/src/App.tsx

View workflow job for this annotation

GitHub Actions / build

'channelName' is already declared in the upper scope on line 32 column 10
log(
`calling onAuthorizer. channelName=${channelName}, socketId=${socketId}`
);
Expand Down Expand Up @@ -242,25 +242,25 @@
style={styles.input}
onChangeText={onChangeHost}
value={host}
placeholder="Host"
placeholder="Host (optional)"
autoCapitalize="none"
keyboardType="default"
/>
<TextInput
style={styles.input}
onChangeText={onChangeWsPort}
value={wsPort}
placeholder="80"
placeholder="WS Port (optional)"
autoCapitalize="none"
keyboardType="default"
keyboardType="number-pad"
/>
<TextInput
style={styles.input}
onChangeText={onChangeWssPort}
value={wssPort}
placeholder="443"
placeholder="WSS Port (optional)"
autoCapitalize="none"
keyboardType="default"
keyboardType="number-pad"
/>
<TextInput
style={styles.input}
Expand Down
29 changes: 12 additions & 17 deletions example/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3091,10 +3091,10 @@ mimic-fn@^2.1.0:
resolved "https://registry.yarnpkg.com/mimic-fn/-/mimic-fn-2.1.0.tgz#7ed2c2ccccaf84d3ffcb7a69b57711fc2083401b"
integrity sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==

minimatch@^3.0.2, minimatch@^3.1.1:
version "3.1.2"
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.1.2.tgz#19cd194bfd3e428f049a70817c038d89ab4be35b"
integrity sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==
minimatch@^3.0.2, minimatch@^3.1.1, minimatch@^3.1.5:
version "3.1.5"
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.1.5.tgz#580c88f8d5445f2bd6aa8f3cadefa0de79fbd69e"
integrity sha512-VgjWUsnnT6n+NUk6eZq77zeFdpW2LWDzP6zFGrCbHXiYNul5Dzqk2HHQ5uFH2DNW5Xbp8+jVzaeNt94ssEEl4w==
dependencies:
brace-expansion "^1.1.7"

Expand Down Expand Up @@ -3407,10 +3407,10 @@ picocolors@^1.1.1:
resolved "https://registry.yarnpkg.com/picocolors/-/picocolors-1.1.1.tgz#3d321af3eab939b083c8f929a1d12cda81c26b6b"
integrity sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==

picomatch@^2.0.4, picomatch@^2.2.3, picomatch@^2.3.1:
version "2.3.1"
resolved "https://registry.yarnpkg.com/picomatch/-/picomatch-2.3.1.tgz#3ba3833733646d9d3e4995946c1365a67fb07a42"
integrity sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==
picomatch@^2.0.4, picomatch@^2.2.3, picomatch@^2.3.1, picomatch@^2.3.2:
version "2.3.2"
resolved "https://registry.yarnpkg.com/picomatch/-/picomatch-2.3.2.tgz#5a942915e26b372dc0f0e6753149a16e6b1c5601"
integrity sha512-V7+vQEJ06Z+c5tSye8S+nHUfI51xoXIXjHQ99cQtKUkQqqO1kO/KCJUfZXuB47h/YBlDhah2H3hdUGXn8ie0oA==

pify@^4.0.1:
version "4.0.1"
Expand Down Expand Up @@ -3761,15 +3761,10 @@ scheduler@^0.22.0:
dependencies:
loose-envify "^1.1.0"

semver@^5.5.0, semver@^5.6.0:
version "5.7.1"
resolved "https://registry.yarnpkg.com/semver/-/semver-5.7.1.tgz#a954f931aeba508d307bbf069eff0c01c96116f7"
integrity sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==

semver@^6.1.1, semver@^6.1.2, semver@^6.3.0:
version "6.3.0"
resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.0.tgz#ee0a64c8af5e8ceea67687b133761e1becbd1d3d"
integrity sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==
semver@^5.5.0, semver@^5.6.0, semver@^5.7.2, semver@^6.1.1, semver@^6.1.2, semver@^6.3.0:
version "5.7.2"
resolved "https://registry.yarnpkg.com/semver/-/semver-5.7.2.tgz#48d55db737c3287cd4835e17fa13feace1c41ef8"
integrity sha512-cBznnQ9KjJqU67B52RMC65CMarK2600WFnbkcaiwWq3xy/5haFJlshgnpjovMVJ+Hff49d8GEn0b87C5pDQ10g==

send@0.18.0:
version "0.18.0"
Expand Down
9 changes: 6 additions & 3 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,10 @@ export class Pusher {

public init(args: {
apiKey: string;
cluster?: string;
host?: string;
wsPort?: Number;
wssPort?: Number;
cluster?: string;
authEndpoint?: string;
useTLS?: boolean;
activityTimeout?: Number;
Expand Down Expand Up @@ -281,10 +281,10 @@ export class Pusher {

return PusherWebsocketReactNative.initialize({
apiKey: args.apiKey,
cluster: args.cluster,
host: args.host,
wsPort: args.wsPort,
wssPort: args.wssPort,
cluster: args.cluster,
authEndpoint: args.authEndpoint,
useTLS: args.useTLS,
activityTimeout: args.activityTimeout,
Expand Down Expand Up @@ -366,7 +366,10 @@ export class Pusher {
event.channelName.startsWith('private-') ||
event.channelName.startsWith('presence-')
) {
const data = Platform.OS === 'android' ? JSON.stringify(event.data ?? {}) : event.data
const data =
Platform.OS === 'android'
? JSON.stringify(event.data ?? {})
: event.data;
await PusherWebsocketReactNative.trigger(
event.channelName,
event.eventName,
Expand Down
Loading
Loading