Skip to content

Commit

Permalink
Set user id param
Browse files Browse the repository at this point in the history
  • Loading branch information
sudoanand committed Oct 7, 2021
1 parent 94dccef commit 8b8d91e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 23 deletions.
2 changes: 1 addition & 1 deletion dist/piesocket.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "piesocket-js",
"version": "1.2.3",
"version": "1.2.4",
"description": "PieSocket Javascript Client",
"main": "src/index.js",
"unpkg": "dist/piesocket.js",
Expand Down
27 changes: 6 additions & 21 deletions src/PieSocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,37 +106,22 @@ export default class PieSocket {
}

async getEndpoint(channelId) {
let user_id = this.options.userId;

let endpoint = `wss://${this.options.clusterId}.piesocket.com/v${this.options.version}/${channelId}?api_key=${this.options.apiKey}&notify_self=${this.options.notifySelf}&source=jssdk&v=${pjson.version}&presence=${this.options.presence}`

//Set auth
if(this.options.jwt){
endpoint = endpoint+"&jwt="+this.options.jwt;
}
else if(this.isGuarded(channelId)){
const auth = await this.getAuthToken(channelId);

//Set user id
if(auth.channel_data){

if(typeof auth.channel_data == "string"){
try{
const channelData = JSON.parse(auth.channel_data);
if(channelData.user_id){
user_id = channelData.user_id;
}
}catch(e){}
}
else if(typeof auth.channel_data == 'object' && auth.channel_data.user_id){
user_id = auth.channel_data.user_id;
}
if(auth.auth){
endpoint = endpoint + "&jwt="+auth.auth;
}

endpoint = endpoint + "&jwt="+auth.auth;
}

if(user_id){
endpoint = endpoint + "&user="+user_id;
//Set user identity
if(this.options.userId){
endpoint = endpoint + "&user="+this.options.userId;
}

return endpoint;
Expand Down

0 comments on commit 8b8d91e

Please sign in to comment.