Skip to content

Commit ddcc9bb

Browse files
committed
feat: add default configs for broadcast, presence, and db changes
1 parent 72fbe1c commit ddcc9bb

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

packages/core/realtime-js/src/RealtimeChannel.ts

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ export default class RealtimeChannel {
1919
public params: { [key: string]: any } = {},
2020
public socket: RealtimeClient
2121
) {
22+
this.params = {
23+
...{ broadcast: { ack: false, self: false }, presence: { key: '' } },
24+
...params,
25+
}
2226
this.timeout = this.socket.timeout
2327
this.joinPush = new Push(
2428
this,
@@ -95,24 +99,21 @@ export default class RealtimeChannel {
9599
if (this.joinedOnce) {
96100
throw `tried to subscribe multiple times. 'subscribe' can only be called a single time per channel instance`
97101
} else {
98-
const configs = this.bindings.reduce(
99-
(acc, binding: { [key: string]: any }) => {
100-
const { type } = binding
101-
if (
102-
![
103-
'phx_close',
104-
'phx_error',
105-
'phx_reply',
106-
'presence_diff',
107-
'presence_state',
108-
].includes(type)
109-
) {
110-
acc[type] = binding
111-
}
112-
return acc
113-
},
114-
{}
115-
)
102+
const { broadcast, presence } = this.params
103+
const configs = {
104+
broadcast,
105+
presence,
106+
realtime: [],
107+
}
108+
109+
this.bindings.reduce((acc, binding) => {
110+
const { type } = binding
111+
if (type === 'realtime') {
112+
acc[type] = acc[type].push(binding)
113+
}
114+
115+
return acc
116+
}, configs)
116117

117118
this.updateJoinPayload({ configs })
118119

0 commit comments

Comments
 (0)