@bluecopa/core 0.1.9 → 0.1.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.es.js
CHANGED
|
@@ -4817,26 +4817,31 @@ Centrifuge.SubscriptionState = SubscriptionState;
|
|
|
4817
4817
|
Centrifuge.State = State;
|
|
4818
4818
|
Centrifuge.UnauthorizedError = UnauthorizedError;
|
|
4819
4819
|
class CentrifugoWebsocket {
|
|
4820
|
-
constructor(connectionUrl) {
|
|
4820
|
+
constructor(connectionUrl, accessToken, userId) {
|
|
4821
4821
|
this.connectionUrl = connectionUrl;
|
|
4822
|
+
this.accessToken = accessToken;
|
|
4823
|
+
this.userId = userId;
|
|
4822
4824
|
this.centrifuge = null;
|
|
4823
4825
|
this.subscriptions = {};
|
|
4824
4826
|
this.isConnected = false;
|
|
4825
|
-
const config = getConfig();
|
|
4826
|
-
this.accessToken = config.accessToken;
|
|
4827
|
-
this.userId = config.userId;
|
|
4828
4827
|
}
|
|
4829
4828
|
connect() {
|
|
4830
4829
|
if (!this.accessToken) {
|
|
4831
4830
|
throw new Error("Unable to connect to websocket, missing info");
|
|
4832
4831
|
}
|
|
4833
|
-
if (!this.connectionUrl) {
|
|
4834
|
-
throw new Error("Unable to connect to websocket, missing url");
|
|
4835
|
-
}
|
|
4836
4832
|
if (!this.centrifuge) {
|
|
4837
|
-
|
|
4838
|
-
|
|
4839
|
-
|
|
4833
|
+
const token = atob(this.accessToken);
|
|
4834
|
+
this.centrifuge = new Centrifuge(
|
|
4835
|
+
[
|
|
4836
|
+
{
|
|
4837
|
+
transport: "websocket",
|
|
4838
|
+
endpoint: this.connectionUrl
|
|
4839
|
+
}
|
|
4840
|
+
],
|
|
4841
|
+
{
|
|
4842
|
+
token
|
|
4843
|
+
}
|
|
4844
|
+
);
|
|
4840
4845
|
this.centrifuge.on("connecting", () => {
|
|
4841
4846
|
console.log("Connecting to centrifuge", this.connectionUrl);
|
|
4842
4847
|
});
|
|
@@ -4912,7 +4917,7 @@ class WebsocketContextFactory {
|
|
|
4912
4917
|
static create(mechanism, args) {
|
|
4913
4918
|
let websocketProvider;
|
|
4914
4919
|
if (mechanism === "centrifugo") {
|
|
4915
|
-
websocketProvider = new CentrifugoWebsocket(args.connectionUrl);
|
|
4920
|
+
websocketProvider = new CentrifugoWebsocket(args.connectionUrl, args.token, args.userId);
|
|
4916
4921
|
}
|
|
4917
4922
|
websocketProvider == null ? void 0 : websocketProvider.connect();
|
|
4918
4923
|
return websocketProvider;
|