support query parameters
This commit is contained in:
parent
0dd875885a
commit
68d00c0a92
@ -171,7 +171,7 @@ const pingTimeout = 30000
|
|||||||
* @param {any} req
|
* @param {any} req
|
||||||
* @param {any} opts
|
* @param {any} opts
|
||||||
*/
|
*/
|
||||||
exports.setupWSConnection = (conn, req, { docName = req.url.slice(1), gc = true } = {}) => {
|
exports.setupWSConnection = (conn, req, { docName = req.url.slice(1).split('?')[0], gc = true } = {}) => {
|
||||||
conn.binaryType = 'arraybuffer'
|
conn.binaryType = 'arraybuffer'
|
||||||
// get doc, create if it does not exist yet
|
// get doc, create if it does not exist yet
|
||||||
const doc = map.setIfUndefined(docs, docName, () => {
|
const doc = map.setIfUndefined(docs, docName, () => {
|
||||||
|
|||||||
33
package-lock.json
generated
33
package-lock.json
generated
@ -11,9 +11,9 @@
|
|||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"@types/node": {
|
"@types/node": {
|
||||||
"version": "13.1.6",
|
"version": "13.7.2",
|
||||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-13.1.6.tgz",
|
"resolved": "https://registry.npmjs.org/@types/node/-/node-13.7.2.tgz",
|
||||||
"integrity": "sha512-Jg1F+bmxcpENHP23sVKkNuU3uaxPnsBMW0cLjleiikFKomJQbsn0Cqk2yDvQArqzZN6ABfBkZ0To7pQ8sLdWDg==",
|
"integrity": "sha512-uvilvAQbdJvnSBFcKJ2td4016urcGvsiR+N4dHGU87ml8O2Vl6l+ErOi9w0kXSPiwJ1AYlIW+0pDXDWWMOiWbw==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"acorn": {
|
"acorn": {
|
||||||
@ -976,11 +976,18 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"lib0": {
|
"lib0": {
|
||||||
"version": "0.2.3",
|
"version": "0.2.15",
|
||||||
"resolved": "https://registry.npmjs.org/lib0/-/lib0-0.2.3.tgz",
|
"resolved": "https://registry.npmjs.org/lib0/-/lib0-0.2.15.tgz",
|
||||||
"integrity": "sha512-J1Gw9PT78tO3QODgvzk9NVTXTXTsru9LKq+iPOdWw5s1/QiapUKmCJMCWBrNSGkJ0f3WQkZJtGzn3azJwMDdeg==",
|
"integrity": "sha512-wLwuTNNgtC7EQH0b3w4iqpts69TRFVur74Wta7jwgS2w+r/vPLuGcsBA16VoPgBYME7oxDSjEesJw9p/gHmFEg==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"isomorphic.js": "^0.1.0"
|
"isomorphic.js": "^0.1.3"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"isomorphic.js": {
|
||||||
|
"version": "0.1.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/isomorphic.js/-/isomorphic.js-0.1.3.tgz",
|
||||||
|
"integrity": "sha512-pabBRLDwYefSsNS+qCazJ97o7P5xDTrNoxSYFTM09JlZTxPrOEPGKekwqUy3/Np4C4PHnVUXHYsZPOix0jELsA=="
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"load-json-file": {
|
"load-json-file": {
|
||||||
@ -1387,9 +1394,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"rollup": {
|
"rollup": {
|
||||||
"version": "1.29.0",
|
"version": "1.31.1",
|
||||||
"resolved": "https://registry.npmjs.org/rollup/-/rollup-1.29.0.tgz",
|
"resolved": "https://registry.npmjs.org/rollup/-/rollup-1.31.1.tgz",
|
||||||
"integrity": "sha512-V63Iz0dSdI5qPPN5HmCN6OBRzBFhMqNWcvwgq863JtSCTU6Vdvqq6S2fYle/dSCyoPrBkIP3EIr1RVs3HTRqqg==",
|
"integrity": "sha512-2JREN1YdrS/kpPzEd33ZjtuNbOuBC3ePfuZBdKEybvqcEcszW1ckyVqzcEiEe0nE8sqHK+pbJg+PsAgRJ8+1dg==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"@types/estree": "*",
|
"@types/estree": "*",
|
||||||
@ -1648,9 +1655,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"typescript": {
|
"typescript": {
|
||||||
"version": "3.7.4",
|
"version": "3.7.5",
|
||||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-3.7.4.tgz",
|
"resolved": "https://registry.npmjs.org/typescript/-/typescript-3.7.5.tgz",
|
||||||
"integrity": "sha512-A25xv5XCtarLwXpcDNZzCGvW2D1S3/bACratYBx2sax8PefsFhlYmkQicKHvpYflFS8if4zne5zT5kpJ7pzuvw==",
|
"integrity": "sha512-/P5lkRXkWHNAbcJIiHPfRoKqyd7bsyCma1hZNUGfn20qm64T6ZBlrzprymeu918H+mB/0rIg2gGK/BXkhhYgBw==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"uniq": {
|
"uniq": {
|
||||||
|
|||||||
@ -40,14 +40,14 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"lib0": "^0.2.3",
|
"lib0": "^0.2.15",
|
||||||
"y-protocols": "^0.2.0"
|
"y-protocols": "^0.2.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"rollup": "^1.29.0",
|
"rollup": "^1.31.1",
|
||||||
"rollup-cli": "^1.0.9",
|
"rollup-cli": "^1.0.9",
|
||||||
"standard": "^12.0.1",
|
"standard": "^12.0.1",
|
||||||
"typescript": "^3.7.4",
|
"typescript": "^3.7.5",
|
||||||
"yjs": "13.0.0-105"
|
"yjs": "13.0.0-105"
|
||||||
},
|
},
|
||||||
"peerDependenies": {
|
"peerDependenies": {
|
||||||
|
|||||||
@ -19,6 +19,7 @@ import * as awarenessProtocol from 'y-protocols/awareness.js'
|
|||||||
import * as mutex from 'lib0/mutex.js'
|
import * as mutex from 'lib0/mutex.js'
|
||||||
import { Observable } from 'lib0/observable.js'
|
import { Observable } from 'lib0/observable.js'
|
||||||
import * as math from 'lib0/math.js'
|
import * as math from 'lib0/math.js'
|
||||||
|
import * as url from 'lib0/url.js'
|
||||||
|
|
||||||
const messageSync = 0
|
const messageSync = 0
|
||||||
const messageQueryAwareness = 3
|
const messageQueryAwareness = 3
|
||||||
@ -164,18 +165,19 @@ const broadcastMessage = (provider, buf) => {
|
|||||||
*/
|
*/
|
||||||
export class WebsocketProvider extends Observable {
|
export class WebsocketProvider extends Observable {
|
||||||
/**
|
/**
|
||||||
* @param {string} url
|
* @param {string} serverUrl
|
||||||
* @param {string} roomname
|
* @param {string} roomname
|
||||||
* @param {Y.Doc} doc
|
* @param {Y.Doc} doc
|
||||||
* @param {{connect:boolean,awareness:awarenessProtocol.Awareness,db:any|null}} conf
|
* @param {{connect:boolean,awareness:awarenessProtocol.Awareness,db:any|null,params:Object<string,string>}} conf
|
||||||
*/
|
*/
|
||||||
constructor (url, roomname, doc, { connect = true, awareness = new awarenessProtocol.Awareness(doc), db = null } = /** @type {any} */ ({})) {
|
constructor (serverUrl, roomname, doc, { connect = true, awareness = new awarenessProtocol.Awareness(doc), db = null, params = {} } = /** @type {any} */ ({})) {
|
||||||
super()
|
super()
|
||||||
// ensure that url is always ends with /
|
// ensure that url is always ends with /
|
||||||
while (url[url.length - 1] === '/') {
|
while (serverUrl[serverUrl.length - 1] === '/') {
|
||||||
url = url.slice(0, url.length - 1)
|
serverUrl = serverUrl.slice(0, serverUrl.length - 1)
|
||||||
}
|
}
|
||||||
this.url = url + '/' + roomname
|
const encodedParams = url.encodeQueryParams(params)
|
||||||
|
this.url = serverUrl + '/' + roomname + (encodedParams.length === 0 ? '' : '&' + encodedParams)
|
||||||
this.roomname = roomname
|
this.roomname = roomname
|
||||||
this.doc = doc
|
this.doc = doc
|
||||||
/**
|
/**
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user