Skip to content

Commit

Permalink
support query parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Jahns committed Feb 18, 2020
1 parent 0dd8758 commit 68d00c0
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 23 deletions.
2 changes: 1 addition & 1 deletion bin/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ const pingTimeout = 30000
* @param {any} req
* @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'
// get doc, create if it does not exist yet
const doc = map.setIfUndefined(docs, docName, () => {
Expand Down
33 changes: 20 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@
]
},
"dependencies": {
"lib0": "^0.2.3",
"lib0": "^0.2.15",
"y-protocols": "^0.2.0"
},
"devDependencies": {
"rollup": "^1.29.0",
"rollup": "^1.31.1",
"rollup-cli": "^1.0.9",
"standard": "^12.0.1",
"typescript": "^3.7.4",
"typescript": "^3.7.5",
"yjs": "13.0.0-105"
},
"peerDependenies": {
Expand Down
14 changes: 8 additions & 6 deletions src/y-websocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import * as awarenessProtocol from 'y-protocols/awareness.js'
import * as mutex from 'lib0/mutex.js'
import { Observable } from 'lib0/observable.js'
import * as math from 'lib0/math.js'
import * as url from 'lib0/url.js'

const messageSync = 0
const messageQueryAwareness = 3
Expand Down Expand Up @@ -164,18 +165,19 @@ const broadcastMessage = (provider, buf) => {
*/
export class WebsocketProvider extends Observable {
/**
* @param {string} url
* @param {string} serverUrl
* @param {string} roomname
* @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()
// ensure that url is always ends with /
while (url[url.length - 1] === '/') {
url = url.slice(0, url.length - 1)
while (serverUrl[serverUrl.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.doc = doc
/**
Expand Down

0 comments on commit 68d00c0

Please sign in to comment.