Skip to content
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

Bring v2 up to date with current changes on master #140

Open
wants to merge 47 commits into
base: v2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
011a06f
1.3.18
dmonad Nov 20, 2021
6b61bae
correct npx directive
zhuangya Dec 30, 2021
eb53b55
Add docs about auth approach #94
dmonad Feb 23, 2022
4c4b244
implement connection-close & connecton-error event and add parameter …
dmonad Mar 21, 2022
57fba26
Merge pull request #91 from zhuangya/patch-1
dmonad Mar 21, 2022
33c0021
add y-websocket bin entry (should be the proper name)
dmonad Mar 21, 2022
fc009dd
1.4.0
dmonad Mar 21, 2022
6fcabc5
add documentation
dmonad Mar 21, 2022
d6df8ad
remove usage of lib0/mutex - closes #99
dmonad Apr 17, 2022
313c38a
1.4.1
dmonad Apr 17, 2022
73157ab
Fixed: The memory leak problem that 'websocketprovider' cannot releas…
war1644 Apr 21, 2022
d4f4a99
Merge pull request #102 from war1644/master
dmonad Apr 21, 2022
cc6df43
1.4.2
dmonad Apr 21, 2022
3c77495
add option to disable broadcastchannel - closes #103
dmonad Apr 22, 2022
f133fb2
1.4.3
dmonad Apr 22, 2022
f02ed34
Improve the judgment condition of WS connection status in resync scen…
lijie1129 Jun 26, 2022
bfb9d30
Merge pull request #111 from lijie1129/refactor/resync
dmonad Jun 26, 2022
c925c24
remove vestigial mutex code
broofa Aug 4, 2022
625a9d5
Merge pull request #113 from broofa/patch-1
dmonad Aug 5, 2022
6415ca2
Update utils.js
aryzing Aug 11, 2022
1ee18c3
Export message type constants
aryzing Aug 11, 2022
8fa06a4
fix: `server.listen` port
himself65 Aug 18, 2022
2da70b3
Merge pull request #116 from Himself65/patch-1
dmonad Aug 19, 2022
aa43c0b
Merge pull request #115 from aryzing/patch-2
dmonad Aug 19, 2022
20c1ac2
Merge pull request #114 from aryzing/patch-1
dmonad Aug 19, 2022
1d5d547
lint
dmonad Aug 19, 2022
37887ba
1.4.4
dmonad Aug 19, 2022
8c04e0a
fix handling of auth message - fixes #117
dmonad Aug 31, 2022
8e85c7f
lint
dmonad Aug 31, 2022
2ef5e96
bump lib0 dependency. closes #118
dmonad Sep 8, 2022
829a159
use unload instead of beforeUnload to send disconnect message. closes…
dmonad Sep 9, 2022
da27b0b
1.4.5
dmonad Sep 9, 2022
58ae11f
fix: WebSocket is already in CLOSING or CLOSED state.
strdr4605 Sep 28, 2022
d98ea1f
add exports.module field - yjs/yjs#438
dmonad Jan 1, 2023
6c945d3
Add server side transaction origin
kkeybbs Feb 22, 2023
312ac84
Merge pull request #132 from kkeybbs/master
dmonad Feb 22, 2023
d22aecc
Merge pull request #121 from strdr4605/master
dmonad Mar 2, 2023
0b5279f
cleanup
dmonad Mar 2, 2023
10f650c
1.4.6
dmonad Mar 2, 2023
9cd9600
feat: add worklows PR & master
Abdel-Monaam-Aouini Mar 10, 2023
c4c3d84
Merge pull request #134 from Abdel-Monaam-Aouini/add-workflow
dmonad Mar 11, 2023
51b7052
bump rollup
dmonad Mar 11, 2023
35be343
upgrade typescript & lint
dmonad Mar 11, 2023
61c2035
1.5.0
dmonad Mar 11, 2023
5db415a
bump packages
dmonad Mar 11, 2023
07123d4
Merge branch 'master' into v2
joshkopecek Jun 3, 2023
37d7590
Remove mutex to pass linting
joshkopecek Jun 3, 2023
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
45 changes: 45 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: CI

on:
push:
branches:
- master
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
branches:
- '**'
paths-ignore:
- 'dist/**'

permissions:
contents: read

jobs:
test:
runs-on: ubuntu-latest
timeout-minutes: 10
strategy:
matrix:
node-version: [18.x, 16.x, 14.x]
steps:
- uses: actions/checkout@v3

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}

- name: 📥 Install
run: npm install

- name: Unit tests
run: npm test

- name: ESLint checks
run: npm run lint

- name: Build
run: npm run dist

- name: Preversion
run: npm run preversion
16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ This repository implements a basic server that you can adopt to your specific us
Start a y-websocket server:

```sh
HOST=localhost PORT=1234 npx y-websocket-server
HOST=localhost PORT=1234 npx y-websocket
```

### Client Code:
Expand Down Expand Up @@ -71,7 +71,9 @@ wsOpts = {
// E.g. In nodejs, you could specify WebsocketPolyfill = require('ws')
WebsocketPolyfill: Websocket,
// Specify an existing Awareness instance - see https://github.com/yjs/y-protocols
awareness: new awarenessProtocol.Awareness(ydoc)
awareness: new awarenessProtocol.Awareness(ydoc),
// Specify the maximum amount to wait between reconnects (we use exponential backoff).
maxBackoffTime: 2500
}
```

Expand All @@ -94,17 +96,23 @@ wsOpts = {
<dd>Destroy this wsProvider instance. Disconnects from the server and removes all event handlers.</dd>
<b><code>wsProvider.on('sync', function(isSynced: boolean))</code></b>
<dd>Add an event listener for the sync event that is fired when the client received content from the server.</dd>
<b><code>wsProvider.on('status', function({ status: 'disconnected' | 'connecting' | 'connected' }))</code></b>
<dd>Receive updates about the current connection status.</dd>
<b><code>wsProvider.on('connection-close', function(WSClosedEvent))</code></b>
<dd>Fires when the underlying websocket connection is closed. It forwards the websocket event to this event handler.</dd>
<b><code>wsProvider.on('connection-error', function(WSErrorEvent))</code></b>
<dd>Fires when the underlying websocket connection closes with an error. It forwards the websocket event to this event handler.</dd>
</dl>

## Websocket Server

Start a y-websocket server:

```sh
HOST=localhost PORT=1234 npx y-websocket-server
HOST=localhost PORT=1234 npx y-websocket
```

Since npm symlinks the `y-websocket-server` executable from your local `./node_modules/.bin` folder, you can simply run npx. The `PORT` environment variable already defaults to 1234, and `HOST` defaults to `localhost`.
Since npm symlinks the `y-websocket` executable from your local `./node_modules/.bin` folder, you can simply run npx. The `PORT` environment variable already defaults to 1234, and `HOST` defaults to `localhost`.

### Websocket Server with Persistence

Expand Down
4 changes: 2 additions & 2 deletions bin/callback.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const isCallbackSet = !!CALLBACK_URL
export const callbackHandler = (update, origin, doc) => {
const room = doc.name
const dataToSend = {
room: room,
room,
data: {}
}
const sharedObjectList = Object.keys(CALLBACK_OBJECTS)
Expand All @@ -42,7 +42,7 @@ const callbackRequest = (url, timeout, data) => {
hostname: url.hostname,
port: url.port,
path: url.pathname,
timeout: timeout,
timeout,
method: 'POST',
headers: {
'Content-Type': 'application/json',
Expand Down
3 changes: 2 additions & 1 deletion bin/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ wss.on('connection', setupWSConnection)

server.on('upgrade', (request, socket, head) => {
// You may check auth of request here..
// See https://github.com/websockets/ws#client-authentication
/**
* @param {any} ws
*/
Expand All @@ -30,6 +31,6 @@ server.on('upgrade', (request, socket, head) => {
wss.handleUpgrade(request, /** @type {any} */ (socket), head, handleAuth)
})

server.listen(port, () => {
server.listen(port, host, () => {
console.log(`running at '${host}' on port ${port}`)
})
8 changes: 5 additions & 3 deletions bin/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import * as awarenessProtocol from 'y-protocols/awareness'

import * as encoding from 'lib0/encoding'
import * as decoding from 'lib0/decoding'
import * as mutex from 'lib0/mutex'
import * as map from 'lib0/map'

import debounce from 'lodash.debounce'
Expand Down Expand Up @@ -89,7 +88,6 @@ export class WSSharedDoc extends Y.Doc {
constructor (name) {
super({ gc: gcEnabled })
this.name = name
this.mux = mutex.createMutex()
/**
* Maps from conn to set of controlled user ids. Delete all user ids from awareness when this conn is closed
* @type {Map<Object, Set<number>>}
Expand Down Expand Up @@ -164,7 +162,11 @@ const messageListener = (conn, doc, message) => {
switch (messageType) {
case messageSync:
encoding.writeVarUint(encoder, messageSync)
syncProtocol.readSyncMessage(decoder, encoder, doc, null)
syncProtocol.readSyncMessage(decoder, encoder, doc, conn)

// If the `encoder` only contains the type of reply message and no
// message, there is no need to send the message. When `encoder` only
// contains the type of reply, its length is 1.
if (encoding.length(encoder) > 1) {
send(doc, conn, encoding.toUint8Array(encoder))
}
Expand Down
Loading