-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update Pusher adapter nodejs examples #102
Open
sacOO7
wants to merge
18
commits into
ably:pusher-adapter-nodejs
Choose a base branch
from
sac-fork:pusher-adapter-nodejs
base: pusher-adapter-nodejs
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
a5d8aad
Added uuid to the config, to make the script work
sacOO7 7618557
Added pusher client code
sacOO7 8235a1e
Added gitignore to the code
sacOO7 c2cbbbe
Refactored package.json, upgraded to latest versions of pusher and pu…
sacOO7 5226107
Updated pusher-client, added subscription success/error callbacks
sacOO7 5554b61
renamed pusher-client to client
sacOO7 0b23a38
Added latest version of express to package.json
sacOO7 df5b881
Added server.js file to process auth requests for private and presenc…
sacOO7 148a8d9
Refactored authorize method for pusher channels
sacOO7 5c6f3c1
Updated server and client scripts
sacOO7 7b37329
Updated client code with presence
sacOO7 72bdc37
Updated clien code with appropriate comments
sacOO7 27a6264
Refactored server file to broadcast events on all three types of chan…
sacOO7 3eaef83
Refactored example.js, updated messages and symbols
sacOO7 ac01578
Refactored server.js file, updated symbols
sacOO7 32db97e
Refactored client.js, updated symbols
sacOO7 9f762a9
Added code for checking client events
sacOO7 ee3bb10
Updated pusher client lib comment to pusher server lib
sacOO7 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
lerna-debug.log* | ||
.pnpm-debug.log* | ||
|
||
# Diagnostic reports (https://nodejs.org/api/report.html) | ||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
*.pid.lock | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
*.lcov | ||
|
||
# nyc test coverage | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# Bower dependency directory (https://bower.io/) | ||
bower_components | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (https://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
node_modules/ | ||
jspm_packages/ | ||
|
||
# Snowpack dependency directory (https://snowpack.dev/) | ||
web_modules/ | ||
|
||
# TypeScript cache | ||
*.tsbuildinfo | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional eslint cache | ||
.eslintcache | ||
|
||
# Optional stylelint cache | ||
.stylelintcache | ||
|
||
# Microbundle cache | ||
.rpt2_cache/ | ||
.rts2_cache_cjs/ | ||
.rts2_cache_es/ | ||
.rts2_cache_umd/ | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# Output of 'npm pack' | ||
*.tgz | ||
|
||
# Yarn Integrity file | ||
.yarn-integrity | ||
|
||
# dotenv environment variable files | ||
.env | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
.env.local | ||
|
||
# parcel-bundler cache (https://parceljs.org/) | ||
.cache | ||
.parcel-cache | ||
|
||
# Next.js build output | ||
.next | ||
out | ||
|
||
# Nuxt.js build / generate output | ||
.nuxt | ||
dist | ||
|
||
# Gatsby files | ||
.cache/ | ||
# Comment in the public line in if your project uses Gatsby and not Next.js | ||
# https://nextjs.org/blog/next-9-1#public-directory-support | ||
# public | ||
|
||
# vuepress build output | ||
.vuepress/dist | ||
|
||
# vuepress v2.x temp and cache directory | ||
.temp | ||
.cache | ||
|
||
# Docusaurus cache and generated files | ||
.docusaurus | ||
|
||
# Serverless directories | ||
.serverless/ | ||
|
||
# FuseBox cache | ||
.fusebox/ | ||
|
||
# DynamoDB Local files | ||
.dynamodb/ | ||
|
||
# TernJS port file | ||
.tern-port | ||
|
||
# Stores VSCode versions used for testing VSCode extensions | ||
.vscode-test | ||
|
||
# yarn v2 | ||
.yarn/cache | ||
.yarn/unplugged | ||
.yarn/build-state.yml | ||
.yarn/install-state.gz | ||
.pnp.* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
console.warn("\n1. Make sure server is running i.e. `npm run server`"+ | ||
"\n2.Run two or more instances of client-events, one for sending and others for receiving client events") | ||
console.warn("\nOnly compatible with unix/bash shell, git bash can be used in windows") | ||
|
||
const Pusher = require('pusher-js'); | ||
|
||
const pusherRealtime = new Pusher('appid.keyid', { // replace with first part of API key before : | ||
wsHost: 'realtime-pusher.ably.io', | ||
wsPort: 443, | ||
disableStats: false, | ||
useTLS: true, | ||
authEndpoint: 'http://localhost:5000/ably/auth', // deprecated | ||
}); | ||
|
||
pusherRealtime.connection.bind('connected', () => { | ||
console.log('connected'); | ||
}); | ||
|
||
pusherRealtime.connection.bind('disconnected', () => { | ||
console.log('disconnected'); | ||
}); | ||
|
||
pusherRealtime.connection.bind("error", (error) => { | ||
console.error(error); | ||
}); | ||
|
||
pusherRealtime.bind_global((eventName, data)=> { | ||
console.log("Global eventName-" + eventName + " data-" + JSON.stringify(data)); | ||
}); | ||
|
||
const alpha = pusherRealtime.subscribe('private-alpha'); | ||
alpha.bind("pusher:subscription_succeeded", () => { | ||
console.log('subscribed to alpha') | ||
}); | ||
alpha.bind("pusher:subscription_error", (err) => { | ||
console.error('alpha subscription error', err) | ||
}); | ||
alpha.bind_global((eventName, data)=> { | ||
console.log("alpha :: eventName-" + eventName + " data-" + JSON.stringify(data)); | ||
}); | ||
|
||
const beta = pusherRealtime.subscribe('private-beta'); | ||
beta.bind("pusher:subscription_succeeded", () => { | ||
console.log('subscribed to beta') | ||
}); | ||
beta.bind("pusher:subscription_error", (err) => { | ||
console.error('beta subscription error', err) | ||
}); | ||
beta.bind_global((eventName, data)=> { | ||
console.log("beta :: eventName-" + eventName + " data-" + JSON.stringify(data)); | ||
}); | ||
|
||
|
||
console.log("\n1.Press A<enter> to send message via alpha\n2.Press B<enter> to send message to beta\nPress Q to quit"); | ||
process.stdin.resume(); | ||
process.stdin.on('data', function (chunk) { | ||
switch(chunk.toString()) { | ||
case "a\n": | ||
case "A\n": | ||
alpha.trigger('client-event', { 'msg': 'Hi from alpha' }); // https://pusher.com/docs/channels/using_channels/events/#eventname-1035650223 | ||
break; | ||
case "b\n": | ||
case "B\n": | ||
beta.trigger('client-event', { 'msg': 'Hi from beta' }); | ||
break; | ||
case "q\n": | ||
case "Q\n": | ||
pusherRealtime.disconnect(); | ||
process.exit(); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
console.warn("\n1. Make sure server is running i.e. `npm run server`") | ||
const Pusher = require('pusher-js'); | ||
|
||
const pusherRealtime = new Pusher('appid.keyid', { // replace with first part of API key before : | ||
wsHost: 'realtime-pusher.ably.io', | ||
wsPort: 443, | ||
disableStats: false, | ||
useTLS: true, | ||
authEndpoint: 'http://localhost:5000/ably/auth', // deprecated | ||
}); | ||
|
||
pusherRealtime.connection.bind('connected', () => { | ||
console.log('connected'); | ||
}); | ||
|
||
pusherRealtime.connection.bind('disconnected', () => { | ||
console.log('disconnected'); | ||
}); | ||
|
||
pusherRealtime.connection.bind("error", (error) => { | ||
console.error(error); | ||
}); | ||
|
||
pusherRealtime.bind_global((eventName, data)=> { | ||
console.log("Global eventName-" + eventName + " data-" + JSON.stringify(data)); | ||
}); | ||
|
||
// Public channel -> Doesn't make any explicit request for authorization | ||
const public_channel = pusherRealtime.subscribe('public-channel'); | ||
public_channel.bind("pusher:subscription_succeeded", () => { | ||
console.log('subscribed to public-channel') | ||
}); | ||
public_channel.bind("pusher:subscription_error", (err) => { | ||
console.error('public channel subscription error', err) | ||
}); | ||
public_channel.bind_global((eventName, data)=> { | ||
console.log("public channel :: eventName-" + eventName + " data-" + JSON.stringify(data)); | ||
}); | ||
|
||
// Private channel -> requests { 'auth' : 'token'} from /ably/auth | ||
const private_channel = pusherRealtime.subscribe('private-channel'); | ||
private_channel.bind("pusher:subscription_succeeded", () => { | ||
console.log('subscribed to private-channel') | ||
}); | ||
private_channel.bind("pusher:subscription_error", (err) => { | ||
console.error('private channel subscription error', err) | ||
}); | ||
private_channel.bind_global((eventName, data)=> { | ||
console.log("private channel :: eventName-" + eventName + " data-" + JSON.stringify(data)); | ||
}); | ||
|
||
// Presence channel -> requests { 'auth' : 'token', 'channelData' : {'userId': '', userInfo: ''}} from /ably/auth | ||
const presence_channel = pusherRealtime.subscribe('presence-channel'); | ||
presence_channel.bind("pusher:subscription_succeeded", (members) => { | ||
console.log('\n###subscribed to presence-channel###') | ||
console.log(`members count :: ${members.count}`) | ||
members.each((member) => { | ||
console.log(member.id, member.info) | ||
}); | ||
console.log('#########\n') | ||
}); | ||
presence_channel.bind("pusher:member_added", (member) => { | ||
console.log('\nmember added', member); | ||
console.log('updated members', presence_channel.members.count) | ||
}); | ||
presence_channel.bind("pusher:member_removed", (member) => { | ||
console.log('\nmember removed', member) | ||
console.log('updated members', presence_channel.members.count) | ||
}); | ||
presence_channel.bind("pusher:subscription_error", (err) => { | ||
console.error('presence channel subscription error', err) | ||
}); | ||
presence_channel.bind_global((eventName, data)=> { | ||
console.log("presence channel :: eventName-" + eventName + " data-" + JSON.stringify(data)); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't
disableStats
betrue
? https://faqs.ably.com/using-the-ably-pusher-protocol-adapterThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I am not sure what it does .... but when I tested it, everything seem to work. Is it supposed to be removed?