remove pusher
This commit is contained in:
parent
b426c40bd8
commit
50d4517d0d
5 changed files with 1 additions and 204 deletions
|
@ -60,8 +60,6 @@
|
||||||
"next-auth": "^3.27.0",
|
"next-auth": "^3.27.0",
|
||||||
"next-pwa": "^5.2.21",
|
"next-pwa": "^5.2.21",
|
||||||
"perfect-freehand": "^0.4.91",
|
"perfect-freehand": "^0.4.91",
|
||||||
"pusher": "^5.0.0",
|
|
||||||
"pusher-js": "^7.0.3",
|
|
||||||
"react": "^17.0.2",
|
"react": "^17.0.2",
|
||||||
"react-dom": "^17.0.2",
|
"react-dom": "^17.0.2",
|
||||||
"react-error-boundary": "^3.1.3",
|
"react-error-boundary": "^3.1.3",
|
||||||
|
|
|
@ -1,33 +0,0 @@
|
||||||
import { NextApiHandler } from 'next'
|
|
||||||
import Pusher from 'pusher'
|
|
||||||
import { v4 as uuid } from 'uuid'
|
|
||||||
|
|
||||||
const pusher = new Pusher({
|
|
||||||
key: '5dc87c88b8684bda655a',
|
|
||||||
appId: '1226484',
|
|
||||||
secret: process.env.PUSHER_SECRET,
|
|
||||||
cluster: 'eu',
|
|
||||||
})
|
|
||||||
|
|
||||||
const PusherAuth: NextApiHandler = (req, res) => {
|
|
||||||
try {
|
|
||||||
const { socket_id, channel_name } = req.body
|
|
||||||
|
|
||||||
const presenceData = {
|
|
||||||
user_id: uuid(),
|
|
||||||
user_info: { name: 'Anonymous' },
|
|
||||||
}
|
|
||||||
|
|
||||||
const auth = pusher.authenticate(
|
|
||||||
socket_id.toString(),
|
|
||||||
channel_name.toString(),
|
|
||||||
presenceData
|
|
||||||
)
|
|
||||||
|
|
||||||
return res.send(auth)
|
|
||||||
} catch (err) {
|
|
||||||
res.status(403).end()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default PusherAuth
|
|
|
@ -1,123 +0,0 @@
|
||||||
import Pusher from 'pusher-js'
|
|
||||||
import * as PusherTypes from 'pusher-js'
|
|
||||||
import state from 'state/state'
|
|
||||||
import { Shape } from 'types'
|
|
||||||
|
|
||||||
class RoomClient {
|
|
||||||
room: string
|
|
||||||
pusher: Pusher
|
|
||||||
channel: PusherTypes.PresenceChannel
|
|
||||||
lastCursorEventTime = 0
|
|
||||||
id: string
|
|
||||||
|
|
||||||
constructor() {
|
|
||||||
// Create pusher instance and bind events
|
|
||||||
|
|
||||||
this.pusher = new Pusher('5dc87c88b8684bda655a', {
|
|
||||||
cluster: 'eu',
|
|
||||||
authEndpoint: 'http://localhost:3000/api/pusher-auth',
|
|
||||||
})
|
|
||||||
|
|
||||||
this.pusher.connection.bind('connecting', () =>
|
|
||||||
state.send('RT_CHANGED_STATUS', { status: 'connecting' })
|
|
||||||
)
|
|
||||||
|
|
||||||
this.pusher.connection.bind('connected', () =>
|
|
||||||
state.send('RT_CHANGED_STATUS', { status: 'connected' })
|
|
||||||
)
|
|
||||||
|
|
||||||
this.pusher.connection.bind('unavailable', () =>
|
|
||||||
state.send('RT_CHANGED_STATUS', { status: 'unavailable' })
|
|
||||||
)
|
|
||||||
|
|
||||||
this.pusher.connection.bind('failed', () => {
|
|
||||||
state.send('RT_CHANGED_STATUS', { status: 'failed' })
|
|
||||||
})
|
|
||||||
|
|
||||||
this.pusher.connection.bind('disconnected', () => {
|
|
||||||
state.send('RT_CHANGED_STATUS', { status: 'disconnected' })
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
connect(roomId: string) {
|
|
||||||
this.room = 'presence-' + roomId
|
|
||||||
|
|
||||||
// Subscribe to channel
|
|
||||||
|
|
||||||
this.channel = this.pusher.subscribe(
|
|
||||||
this.room
|
|
||||||
) as PusherTypes.PresenceChannel
|
|
||||||
|
|
||||||
this.channel.bind('pusher:subscription_error', (err: string) => {
|
|
||||||
console.warn(err)
|
|
||||||
state.send('RT_CHANGED_STATUS', { status: 'subscription-error' })
|
|
||||||
})
|
|
||||||
|
|
||||||
this.channel.bind('pusher:subscription_succeeded', () => {
|
|
||||||
const me = this.channel.members.me
|
|
||||||
const userId = me.id
|
|
||||||
|
|
||||||
this.id = userId
|
|
||||||
|
|
||||||
state.send('RT_CHANGED_STATUS', { status: 'subscribed' })
|
|
||||||
})
|
|
||||||
|
|
||||||
this.channel.bind(
|
|
||||||
'created_shape',
|
|
||||||
(payload: { id: string; pageId: string; shape: Shape }) => {
|
|
||||||
if (payload.id === this.id) return
|
|
||||||
state.send('RT_CREATED_SHAPE', payload)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
this.channel.bind(
|
|
||||||
'deleted_shape',
|
|
||||||
(payload: { id: string; pageId: string; shape: Shape }) => {
|
|
||||||
if (payload.id === this.id) return
|
|
||||||
state.send('RT_DELETED_SHAPE', payload)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
this.channel.bind(
|
|
||||||
'edited_shape',
|
|
||||||
(payload: { id: string; pageId: string; change: Partial<Shape> }) => {
|
|
||||||
if (payload.id === this.id) return
|
|
||||||
state.send('RT_EDITED_SHAPE', payload)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
this.channel.bind(
|
|
||||||
'client-moved-cursor',
|
|
||||||
(payload: { id: string; pageId: string; point: number[] }) => {
|
|
||||||
if (payload.id === this.id) return
|
|
||||||
state.send('RT_MOVED_CURSOR', payload)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
disconnect() {
|
|
||||||
this.pusher.unsubscribe(this.room)
|
|
||||||
}
|
|
||||||
|
|
||||||
reconnect() {
|
|
||||||
this.pusher.subscribe(this.room)
|
|
||||||
}
|
|
||||||
|
|
||||||
moveCursor(pageId: string, point: number[]) {
|
|
||||||
if (!this.channel) return
|
|
||||||
|
|
||||||
const now = Date.now()
|
|
||||||
|
|
||||||
if (now - this.lastCursorEventTime > 200) {
|
|
||||||
this.lastCursorEventTime = now
|
|
||||||
|
|
||||||
this.channel?.trigger('client-moved-cursor', {
|
|
||||||
id: this.id,
|
|
||||||
pageId,
|
|
||||||
point,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default new RoomClient()
|
|
|
@ -7,7 +7,7 @@ import history from './history'
|
||||||
import storage from './storage'
|
import storage from './storage'
|
||||||
import clipboard from './clipboard'
|
import clipboard from './clipboard'
|
||||||
import * as Sessions from './sessions'
|
import * as Sessions from './sessions'
|
||||||
import coopClient from './coop/client-pusher'
|
import coopClient from './coop/client-liveblocks'
|
||||||
import commands from './commands'
|
import commands from './commands'
|
||||||
import {
|
import {
|
||||||
getCommonBounds,
|
getCommonBounds,
|
||||||
|
|
45
yarn.lock
45
yarn.lock
|
@ -2267,13 +2267,6 @@ abab@^2.0.3, abab@^2.0.5:
|
||||||
resolved "https://registry.yarnpkg.com/abab/-/abab-2.0.5.tgz#c0b678fb32d60fc1219c784d6a826fe385aeb79a"
|
resolved "https://registry.yarnpkg.com/abab/-/abab-2.0.5.tgz#c0b678fb32d60fc1219c784d6a826fe385aeb79a"
|
||||||
integrity sha512-9IK9EadsbHo6jLWIpxpR6pL0sazTXV6+SQv25ZB+F7Bj9mJNaOc4nCRabwd5M/JwmUa8idz6Eci6eKfJryPs6Q==
|
integrity sha512-9IK9EadsbHo6jLWIpxpR6pL0sazTXV6+SQv25ZB+F7Bj9mJNaOc4nCRabwd5M/JwmUa8idz6Eci6eKfJryPs6Q==
|
||||||
|
|
||||||
abort-controller@^3.0.0:
|
|
||||||
version "3.0.0"
|
|
||||||
resolved "https://registry.yarnpkg.com/abort-controller/-/abort-controller-3.0.0.tgz#eaf54d53b62bae4138e809ca225c8439a6efb392"
|
|
||||||
integrity sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg==
|
|
||||||
dependencies:
|
|
||||||
event-target-shim "^5.0.0"
|
|
||||||
|
|
||||||
acorn-globals@^6.0.0:
|
acorn-globals@^6.0.0:
|
||||||
version "6.0.0"
|
version "6.0.0"
|
||||||
resolved "https://registry.yarnpkg.com/acorn-globals/-/acorn-globals-6.0.0.tgz#46cdd39f0f8ff08a876619b55f5ac8a6dc770b45"
|
resolved "https://registry.yarnpkg.com/acorn-globals/-/acorn-globals-6.0.0.tgz#46cdd39f0f8ff08a876619b55f5ac8a6dc770b45"
|
||||||
|
@ -3862,11 +3855,6 @@ etag@1.8.1:
|
||||||
resolved "https://registry.yarnpkg.com/etag/-/etag-1.8.1.tgz#41ae2eeb65efa62268aebfea83ac7d79299b0887"
|
resolved "https://registry.yarnpkg.com/etag/-/etag-1.8.1.tgz#41ae2eeb65efa62268aebfea83ac7d79299b0887"
|
||||||
integrity sha1-Qa4u62XvpiJorr/qg6x9eSmbCIc=
|
integrity sha1-Qa4u62XvpiJorr/qg6x9eSmbCIc=
|
||||||
|
|
||||||
event-target-shim@^5.0.0:
|
|
||||||
version "5.0.1"
|
|
||||||
resolved "https://registry.yarnpkg.com/event-target-shim/-/event-target-shim-5.0.1.tgz#5d4d3ebdf9583d63a5333ce2deb7480ab2b05789"
|
|
||||||
integrity sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ==
|
|
||||||
|
|
||||||
events@^3.0.0:
|
events@^3.0.0:
|
||||||
version "3.3.0"
|
version "3.3.0"
|
||||||
resolved "https://registry.yarnpkg.com/events/-/events-3.3.0.tgz#31a95ad0a924e2d2c419a813aeb2c4e878ea7400"
|
resolved "https://registry.yarnpkg.com/events/-/events-3.3.0.tgz#31a95ad0a924e2d2c419a813aeb2c4e878ea7400"
|
||||||
|
@ -4582,11 +4570,6 @@ is-arrayish@^0.2.1:
|
||||||
resolved "https://registry.yarnpkg.com/is-arrayish/-/is-arrayish-0.2.1.tgz#77c99840527aa8ecb1a8ba697b80645a7a926a9d"
|
resolved "https://registry.yarnpkg.com/is-arrayish/-/is-arrayish-0.2.1.tgz#77c99840527aa8ecb1a8ba697b80645a7a926a9d"
|
||||||
integrity sha1-d8mYQFJ6qOyxqLppe4BkWnqSap0=
|
integrity sha1-d8mYQFJ6qOyxqLppe4BkWnqSap0=
|
||||||
|
|
||||||
is-base64@^1.1.0:
|
|
||||||
version "1.1.0"
|
|
||||||
resolved "https://registry.yarnpkg.com/is-base64/-/is-base64-1.1.0.tgz#8ce1d719895030a457c59a7dcaf39b66d99d56b4"
|
|
||||||
integrity sha512-Nlhg7Z2dVC4/PTvIFkgVVNvPHSO2eR/Yd0XzhGiXCXEvWnptXlXa/clQ8aePPiMuxEGcWfzWbGw2Fe3d+Y3v1g==
|
|
||||||
|
|
||||||
is-bigint@^1.0.1:
|
is-bigint@^1.0.1:
|
||||||
version "1.0.2"
|
version "1.0.2"
|
||||||
resolved "https://registry.yarnpkg.com/is-bigint/-/is-bigint-1.0.2.tgz#ffb381442503235ad245ea89e45b3dbff040ee5a"
|
resolved "https://registry.yarnpkg.com/is-bigint/-/is-bigint-1.0.2.tgz#ffb381442503235ad245ea89e45b3dbff040ee5a"
|
||||||
|
@ -6692,24 +6675,6 @@ punycode@^2.1.0, punycode@^2.1.1:
|
||||||
resolved "https://registry.yarnpkg.com/punycode/-/punycode-2.1.1.tgz#b58b010ac40c22c5657616c8d2c2c02c7bf479ec"
|
resolved "https://registry.yarnpkg.com/punycode/-/punycode-2.1.1.tgz#b58b010ac40c22c5657616c8d2c2c02c7bf479ec"
|
||||||
integrity sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==
|
integrity sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==
|
||||||
|
|
||||||
pusher-js@^7.0.3:
|
|
||||||
version "7.0.3"
|
|
||||||
resolved "https://registry.yarnpkg.com/pusher-js/-/pusher-js-7.0.3.tgz#f81c78cdf2ad32f546caa7532ec7f9081ef00b8d"
|
|
||||||
integrity sha512-HIfCvt00CAqgO4W0BrdpPsDcAwy51rB6DN0VMC+JeVRRbo8mn3XTeUeIFjmmlRLZLX8rPhUtLRo7vPag6b8GCw==
|
|
||||||
dependencies:
|
|
||||||
tweetnacl "^1.0.3"
|
|
||||||
|
|
||||||
pusher@^5.0.0:
|
|
||||||
version "5.0.0"
|
|
||||||
resolved "https://registry.yarnpkg.com/pusher/-/pusher-5.0.0.tgz#3dc39ff527637a4b4597652357b0ec562514c8e6"
|
|
||||||
integrity sha512-YaSZHkukytHR9+lklJp4yefwfR4685kfS6pqrSDUxPj45Ga29lIgyN7Jcnsz+bN5WKwXaf2+4c/x/j3pzWIAkw==
|
|
||||||
dependencies:
|
|
||||||
abort-controller "^3.0.0"
|
|
||||||
is-base64 "^1.1.0"
|
|
||||||
node-fetch "^2.6.1"
|
|
||||||
tweetnacl "^1.0.0"
|
|
||||||
tweetnacl-util "^0.15.0"
|
|
||||||
|
|
||||||
querystring-es3@0.2.1, querystring-es3@^0.2.0:
|
querystring-es3@0.2.1, querystring-es3@^0.2.0:
|
||||||
version "0.2.1"
|
version "0.2.1"
|
||||||
resolved "https://registry.yarnpkg.com/querystring-es3/-/querystring-es3-0.2.1.tgz#9ec61f79049875707d69414596fd907a4d711e73"
|
resolved "https://registry.yarnpkg.com/querystring-es3/-/querystring-es3-0.2.1.tgz#9ec61f79049875707d69414596fd907a4d711e73"
|
||||||
|
@ -7874,16 +7839,6 @@ tty-browserify@0.0.1:
|
||||||
resolved "https://registry.yarnpkg.com/tty-browserify/-/tty-browserify-0.0.1.tgz#3f05251ee17904dfd0677546670db9651682b811"
|
resolved "https://registry.yarnpkg.com/tty-browserify/-/tty-browserify-0.0.1.tgz#3f05251ee17904dfd0677546670db9651682b811"
|
||||||
integrity sha512-C3TaO7K81YvjCgQH9Q1S3R3P3BtN3RIM8n+OvX4il1K1zgE8ZhI0op7kClgkxtutIE8hQrcrHBXvIheqKUUCxw==
|
integrity sha512-C3TaO7K81YvjCgQH9Q1S3R3P3BtN3RIM8n+OvX4il1K1zgE8ZhI0op7kClgkxtutIE8hQrcrHBXvIheqKUUCxw==
|
||||||
|
|
||||||
tweetnacl-util@^0.15.0:
|
|
||||||
version "0.15.1"
|
|
||||||
resolved "https://registry.yarnpkg.com/tweetnacl-util/-/tweetnacl-util-0.15.1.tgz#b80fcdb5c97bcc508be18c44a4be50f022eea00b"
|
|
||||||
integrity sha512-RKJBIj8lySrShN4w6i/BonWp2Z/uxwC3h4y7xsRrpP59ZboCd0GpEVsOnMDYLMmKBpYhb5TgHzZXy7wTfYFBRw==
|
|
||||||
|
|
||||||
tweetnacl@^1.0.0, tweetnacl@^1.0.3:
|
|
||||||
version "1.0.3"
|
|
||||||
resolved "https://registry.yarnpkg.com/tweetnacl/-/tweetnacl-1.0.3.tgz#ac0af71680458d8a6378d0d0d050ab1407d35596"
|
|
||||||
integrity sha512-6rt+RN7aOi1nGMyC4Xa5DdYiukl2UWCbcJft7YhxReBGQD7OAM8Pbxw6YMo4r2diNEA8FEmu32YOn9rhaiE5yw==
|
|
||||||
|
|
||||||
type-check@^0.4.0, type-check@~0.4.0:
|
type-check@^0.4.0, type-check@~0.4.0:
|
||||||
version "0.4.0"
|
version "0.4.0"
|
||||||
resolved "https://registry.yarnpkg.com/type-check/-/type-check-0.4.0.tgz#07b8203bfa7056c0657050e3ccd2c37730bab8f1"
|
resolved "https://registry.yarnpkg.com/type-check/-/type-check-0.4.0.tgz#07b8203bfa7056c0657050e3ccd2c37730bab8f1"
|
||||||
|
|
Loading…
Reference in a new issue