Skip to content

Commit

Permalink
feat(cozy-realtime): Add cozy-client plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyrille Perois committed Jan 2, 2020
1 parent 248fac7 commit 820d663
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/cozy-realtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"@babel/cli": "7.4.4",
"babel-plugin-rewire": "1.2.0",
"babel-preset-cozy-app": "^1.7.0",
"cozy-client": "^9.3.0",
"jest-cli": "24.7.1",
"mock-socket": "9.0.0"
},
Expand Down
43 changes: 43 additions & 0 deletions packages/cozy-realtime/src/RealtimePlugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import CozyRealtime from './CozyRealtime'

/**
* Realtime plugin for cozy-client
*
* @class
*/
class RealtimePlugin {
/**
* Constructor of RealtimePlugin
*
* @constructor
* @param {CozyClient} client A cozy-client instance
*/
constructor(client) {
this.realtime = new CozyRealtime({ client })
}

/**
* @see CozyRealtime.subscribe
*/
subscribe(...args) {
this.realtime.subscribe(...args)
}

/**
* @see CozyRealtime.unsubscribe
*/
unsubscribe(...args) {
this.realtime.unsubscribe(...args)
}

/**
* @see CozyRealtime.unsubscribeAll
*/
unsubscribeAll() {
this.realtime.unsubscribeAll()
}
}

RealtimePlugin.pluginName = 'realtime'

export default RealtimePlugin
24 changes: 24 additions & 0 deletions packages/cozy-realtime/src/RealtimePlugin.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import RealtimePlugin from './RealtimePlugin'
import CozyClient from 'cozy-client'

let client

beforeEach(() => {
client = new CozyClient({
uri: 'http://cozy.tools:8080',
token: 'fake-token'
})
})

it('should attach to the client under the `realtime` plugin name', () => {
expect(client.plugins.realtime).toBeUndefined()
client.registerPlugin(RealtimePlugin)
expect(client.plugins.realtime).toBeInstanceOf(RealtimePlugin)
})

it('should expose the same API as CozyRealtime', () => {
client.registerPlugin(RealtimePlugin)
expect(client.plugins.realtime.subscribe).toBeInstanceOf(Function)
expect(client.plugins.realtime.unsubscribe).toBeInstanceOf(Function)
expect(client.plugins.realtime.unsubscribeAll).toBeInstanceOf(Function)
})
1 change: 1 addition & 0 deletions packages/cozy-realtime/src/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import CozyRealtime from './CozyRealtime'

export { default as RealtimePlugin } from './RealtimePlugin'
export default CozyRealtime
25 changes: 25 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5218,6 +5218,22 @@ cozy-client@^9.1.0:
sift "^6.0.0"
url-search-params-polyfill "^7.0.0"

cozy-client@^9.3.0:
version "9.3.0"
resolved "https://registry.yarnpkg.com/cozy-client/-/cozy-client-9.3.0.tgz#a7ae1c8b86ed153743411a04d0cd74a20520f192"
integrity sha512-0oqRErnUFh5n7rBmjomSC1tNx4F+35D86TlrphXFi494EmSmjKyF0yMnyNVCtA0nB6EaAo2mC1BTEWuUZg8x0A==
dependencies:
cozy-device-helper "^1.7.3"
cozy-stack-client "^9.2.0"
lodash "^4.17.13"
microee "^0.0.6"
prop-types "^15.6.2"
react-redux "^5.0.7"
redux "^3.7.2"
redux-thunk "^2.3.0"
sift "^6.0.0"
url-search-params-polyfill "^7.0.0"

cozy-doctypes@1.67.0:
version "1.67.0"
resolved "https://registry.yarnpkg.com/cozy-doctypes/-/cozy-doctypes-1.67.0.tgz#2e26cf43556cff298d0eec2f06091d15dc1758da"
Expand Down Expand Up @@ -5263,6 +5279,15 @@ cozy-stack-client@^9.1.0:
mime "^2.4.0"
qs "^6.7.0"

cozy-stack-client@^9.2.0:
version "9.2.0"
resolved "https://registry.yarnpkg.com/cozy-stack-client/-/cozy-stack-client-9.2.0.tgz#3d6a9af9e42f6f2d8fad7fe57e83713a3bcafc77"
integrity sha512-ivMjA+EtV7lu6lKzuOIiS00XcTVL6WRbycSmfO7SJrAU12kWp54rlKDS9rMFA2NjCEShjTVdu0intkxYbuimsw==
dependencies:
detect-node "^2.0.4"
mime "^2.4.0"
qs "^6.7.0"

cozy-ui@22.14.1:
version "22.14.1"
resolved "https://registry.yarnpkg.com/cozy-ui/-/cozy-ui-22.14.1.tgz#3a975825667a4524cbe5099f8a92966e45de4557"
Expand Down

0 comments on commit 820d663

Please sign in to comment.