Skip to content

Commit c958faf

Browse files
committed
convert to fetch
1 parent dd369ad commit c958faf

File tree

1 file changed

+24
-18
lines changed

1 file changed

+24
-18
lines changed

js-src/Websocket.ts

+24-18
Original file line numberDiff line numberDiff line change
@@ -140,25 +140,31 @@ export class Websocket {
140140
this.options.auth.headers['Authorization'] = 'Bearer ' + this.options.bearerToken;
141141
}
142142

143-
axios.post(this.options.authEndpoint, {
144-
socket_id: this.getSocketId(),
145-
channel_name: channel.name,
146-
}, {
147-
headers: this.options.auth.headers || {}
148-
}).then((response: AxiosResponse) => {
149-
console.log(`Subscribing to channels ${channel.name}`)
150-
151-
this.send({
152-
event: 'subscribe',
153-
data: {
154-
channel: channel.name,
155-
... response.data
156-
},
143+
fetch(this.options.authEndpoint, {
144+
method: 'POST',
145+
headers: {
146+
...this.options.auth.headers,
147+
'Content-Type': 'application/json'
148+
},
149+
body: JSON.stringify({
150+
socket_id: this.getSocketId(),
151+
channel_name: channel.name,
157152
})
158-
}).catch((error) => {
159-
console.log(`Auth request for channel ${channel.name} failed`)
160-
console.error(error)
161-
})
153+
}).then((response) => response.json())
154+
.then((data) => {
155+
console.log(`Subscribing to channels ${channel.name}`)
156+
157+
this.send({
158+
event: 'subscribe',
159+
data: {
160+
channel: channel.name,
161+
... data
162+
},
163+
})
164+
}).catch((error) => {
165+
console.log(`Auth request for channel ${channel.name} failed`)
166+
console.error(error)
167+
});
162168
} else {
163169
console.log(`Subscribing to channels ${channel.name}`)
164170

0 commit comments

Comments
 (0)