From 50d4517d0df40c9bdbe2620801ce7ae3a439d0fc Mon Sep 17 00:00:00 2001 From: Steve Ruiz Date: Wed, 30 Jun 2021 23:55:00 +0100 Subject: [PATCH] remove pusher --- package.json | 2 - pages/api/pusher-auth.ts | 33 ---------- state/coop/client-pusher.ts | 123 ------------------------------------ state/state.ts | 2 +- yarn.lock | 45 ------------- 5 files changed, 1 insertion(+), 204 deletions(-) delete mode 100644 pages/api/pusher-auth.ts delete mode 100644 state/coop/client-pusher.ts diff --git a/package.json b/package.json index 19c200c6e..8d1b419be 100644 --- a/package.json +++ b/package.json @@ -60,8 +60,6 @@ "next-auth": "^3.27.0", "next-pwa": "^5.2.21", "perfect-freehand": "^0.4.91", - "pusher": "^5.0.0", - "pusher-js": "^7.0.3", "react": "^17.0.2", "react-dom": "^17.0.2", "react-error-boundary": "^3.1.3", diff --git a/pages/api/pusher-auth.ts b/pages/api/pusher-auth.ts deleted file mode 100644 index bca40d6d8..000000000 --- a/pages/api/pusher-auth.ts +++ /dev/null @@ -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 diff --git a/state/coop/client-pusher.ts b/state/coop/client-pusher.ts deleted file mode 100644 index 663d10032..000000000 --- a/state/coop/client-pusher.ts +++ /dev/null @@ -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 }) => { - 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() diff --git a/state/state.ts b/state/state.ts index 389f0dc63..37273d3de 100644 --- a/state/state.ts +++ b/state/state.ts @@ -7,7 +7,7 @@ import history from './history' import storage from './storage' import clipboard from './clipboard' import * as Sessions from './sessions' -import coopClient from './coop/client-pusher' +import coopClient from './coop/client-liveblocks' import commands from './commands' import { getCommonBounds, diff --git a/yarn.lock b/yarn.lock index 2508e4864..92e9ffa23 100644 --- a/yarn.lock +++ b/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" 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: version "6.0.0" 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" 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: version "3.3.0" 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" 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: version "1.0.2" 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" 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: version "0.2.1" 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" 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: version "0.4.0" resolved "https://registry.yarnpkg.com/type-check/-/type-check-0.4.0.tgz#07b8203bfa7056c0657050e3ccd2c37730bab8f1"