@bluecopa/core 0.1.32 → 0.1.34
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
|
@@ -9044,7 +9044,7 @@ const NotificationChannel = "user-notification";
|
|
|
9044
9044
|
const StatementResultChannel = "report-result";
|
|
9045
9045
|
const ReconResultChannel = "recon-result";
|
|
9046
9046
|
class PusherWebsocket {
|
|
9047
|
-
constructor(userId, pusherKey, pusherCluster) {
|
|
9047
|
+
constructor(userId, pusherKey, pusherCluster, authenticationEndpoint) {
|
|
9048
9048
|
this.pusher = null;
|
|
9049
9049
|
this.isConnected = false;
|
|
9050
9050
|
this.notebookChannel = null;
|
|
@@ -9055,6 +9055,7 @@ class PusherWebsocket {
|
|
|
9055
9055
|
this.userId = userId;
|
|
9056
9056
|
this.pusherKey = pusherKey;
|
|
9057
9057
|
this.pusherCluster = pusherCluster;
|
|
9058
|
+
this.authenticationEndpoint = authenticationEndpoint;
|
|
9058
9059
|
}
|
|
9059
9060
|
/**
|
|
9060
9061
|
* Set user info for presence channels.
|
|
@@ -9065,10 +9066,38 @@ class PusherWebsocket {
|
|
|
9065
9066
|
}
|
|
9066
9067
|
connect() {
|
|
9067
9068
|
if (this.pusherKey) {
|
|
9068
|
-
|
|
9069
|
-
|
|
9070
|
-
|
|
9071
|
-
|
|
9069
|
+
if (this.authenticationEndpoint) {
|
|
9070
|
+
const pusherOptions = {
|
|
9071
|
+
cluster: this.pusherCluster
|
|
9072
|
+
};
|
|
9073
|
+
const authEndpoint = this.authenticationEndpoint;
|
|
9074
|
+
pusherOptions.authorizer = (channel, options) => {
|
|
9075
|
+
return {
|
|
9076
|
+
authorize: async (socketId, callback) => {
|
|
9077
|
+
const formData = new URLSearchParams();
|
|
9078
|
+
formData.append("socket_id", socketId);
|
|
9079
|
+
formData.append("channel_name", channel.name);
|
|
9080
|
+
try {
|
|
9081
|
+
const response = await axios.post(authEndpoint, formData, {
|
|
9082
|
+
headers: {
|
|
9083
|
+
"Content-Type": "application/x-www-form-urlencoded"
|
|
9084
|
+
},
|
|
9085
|
+
withCredentials: true
|
|
9086
|
+
});
|
|
9087
|
+
callback(null, response.data);
|
|
9088
|
+
} catch (error) {
|
|
9089
|
+
callback(error, null);
|
|
9090
|
+
}
|
|
9091
|
+
}
|
|
9092
|
+
};
|
|
9093
|
+
};
|
|
9094
|
+
this.pusher = new Pusher(this.pusherKey, pusherOptions);
|
|
9095
|
+
} else {
|
|
9096
|
+
this.pusher = new Pusher(this.pusherKey, {
|
|
9097
|
+
cluster: this.pusherCluster,
|
|
9098
|
+
userAuthentication: { endpoint: "/pusher/auth", transport: "ajax" }
|
|
9099
|
+
});
|
|
9100
|
+
}
|
|
9072
9101
|
this.notebookChannel = this.pusher.subscribe("private-notebook-" + this.userId);
|
|
9073
9102
|
this.notificationChannel = this.pusher.subscribe(`user-notification-${this.userId}`);
|
|
9074
9103
|
this.reconResultChannel = this.pusher.subscribe(`private-recon-result-${this.userId}`);
|
|
@@ -9219,7 +9248,7 @@ class WebsocketContextFactory {
|
|
|
9219
9248
|
if (!args.pusherCluster) {
|
|
9220
9249
|
throw new Error("Pusher cluster is required");
|
|
9221
9250
|
}
|
|
9222
|
-
websocketProvider = new PusherWebsocket(args.userId, args.pusherKey, args.pusherCluster);
|
|
9251
|
+
websocketProvider = new PusherWebsocket(args.userId, args.pusherKey, args.pusherCluster, args.authenticationEndpoint);
|
|
9223
9252
|
} else {
|
|
9224
9253
|
throw new Error(`Unsupported mechanism: ${mechanism}. Supported mechanisms are: pusher, centrifugo`);
|
|
9225
9254
|
}
|