Skip to content

Commit f2365fb

Browse files
committed
Merged PR 13583: Add SDKSessionId
Add SDKSessionId
1 parent 22ddefb commit f2365fb

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

src/embed.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ export abstract class Embed {
222222
throw errors;
223223
}
224224

225-
return this.service.hpm.post<void>("/report/create", config, { uid: this.config.uniqueId }, this.iframe.contentWindow)
225+
return this.service.hpm.post<void>("/report/create", config, { uid: this.config.uniqueId, sdkSessionId: this.service.getSdkSessionId() }, this.iframe.contentWindow)
226226
.then(response => {
227227
return response.body;
228228
},
@@ -288,7 +288,7 @@ export abstract class Embed {
288288
*/
289289
load(config: IEmbedConfigurationBase, phasedRender?: boolean): Promise<void> {
290290
const path = phasedRender && config.type === 'report' ? this.phasedLoadPath : this.loadPath;
291-
return this.service.hpm.post<void>(path, config, { uid: this.config.uniqueId }, this.iframe.contentWindow)
291+
return this.service.hpm.post<void>(path, config, { uid: this.config.uniqueId, sdkSessionId: this.service.getSdkSessionId() }, this.iframe.contentWindow)
292292
.then(response => {
293293
utils.assign(this.config, config);
294294
return response.body;

src/service.ts

+6
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ export class Service implements IService {
105105
/** TODO: Look for way to make wpmp private. This is only public to allow stopping the wpmp in tests */
106106
wpmp: wpmp.WindowPostMessageProxy;
107107
private router: router.Router;
108+
private uniqueSessionId: string;
108109

109110
private static DefaultInitEmbedUrl: string = "http://app.powerbi.com/reportEmbed";
110111

@@ -120,6 +121,7 @@ export class Service implements IService {
120121
this.wpmp = wpmpFactory(config.wpmpName, config.logMessages);
121122
this.hpm = hpmFactory(this.wpmp, null, config.version, config.type);
122123
this.router = routerFactory(this.wpmp);
124+
this.uniqueSessionId = utils.generateUUID();
123125

124126
/**
125127
* Adds handler for report events.
@@ -296,6 +298,10 @@ export class Service implements IService {
296298
return this.embeds.length;
297299
}
298300

301+
getSdkSessionId(): string {
302+
return this.uniqueSessionId;
303+
}
304+
299305
/**
300306
* Given a configuration based on a Power BI element, saves the component instance that reference the element for later lookup.
301307
*

src/util.ts

+22
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,28 @@ export function createRandomString(): string {
108108
return (Math.random() + 1).toString(36).substring(7);
109109
}
110110

111+
/**
112+
* Generates a 20 charachter uuid.
113+
*
114+
* @export
115+
* @returns {string}
116+
*/
117+
export function generateUUID(): string {
118+
let d = new Date().getTime();
119+
if (typeof performance !== 'undefined' && typeof performance.now === 'function') {
120+
d += performance.now();
121+
}
122+
return 'xxxxxxxxxxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
123+
// Generate a random number, scaled from 0 to 16.
124+
// Bitwise-and by 15 since we only care about the last 4 bits.
125+
const r = (d + Math.random() * 16) & 15 | 0;
126+
127+
// Shift 4 times to divide by 16
128+
d >>= 4;
129+
return r.toString(16);
130+
});
131+
}
132+
111133
/**
112134
* Adds a parameter to the given url
113135
*

0 commit comments

Comments
 (0)