@momo2555/koppeliajs 0.0.127 → 0.0.128

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.
@@ -67,6 +67,14 @@ export declare class Console {
67
67
  */
68
68
  get ready(): boolean;
69
69
  getMediaUrl(path: string): string;
70
+ /**
71
+ * Call thus function to fix the link and make it work for both controller and monitor
72
+ * Sometimes, the link is get from monitor or controller and save as a game state. But
73
+ * When the oher client will get the link will not work. Using this function for all media
74
+ * Url is a good practice.
75
+ * @param mediaUrl
76
+ */
77
+ fixMediaUrl(mediaUrl: string): string;
70
78
  getMedia(path: string): Promise<MediaResponseData>;
71
79
  private _initEvents;
72
80
  private _processReceivedData;
@@ -115,6 +115,20 @@ export class Console {
115
115
  path = "/" + path;
116
116
  return this._mediaApiUrl + path;
117
117
  }
118
+ /**
119
+ * Call thus function to fix the link and make it work for both controller and monitor
120
+ * Sometimes, the link is get from monitor or controller and save as a game state. But
121
+ * When the oher client will get the link will not work. Using this function for all media
122
+ * Url is a good practice.
123
+ * @param mediaUrl
124
+ */
125
+ fixMediaUrl(mediaUrl) {
126
+ let url = new URL(mediaUrl);
127
+ let fixedurl = new URL(this._mediaApiUrl);
128
+ fixedurl.pathname = url.pathname;
129
+ fixedurl.search = url.search;
130
+ return fixedurl.toString();
131
+ }
118
132
  async getMedia(path) {
119
133
  const response = await fetch(this.getMediaUrl(path));
120
134
  if (!response.ok) {
@@ -32,6 +32,7 @@ export declare class Koppelia {
32
32
  * @param stageName
33
33
  */
34
34
  goto(stageName: string): void;
35
+ fixMediaUrl(mediaUrl: string): string;
35
36
  /**
36
37
  * Get the list of devices in a callback
37
38
  * @param callback
@@ -81,6 +81,9 @@ export class Koppelia {
81
81
  goto(stageName) {
82
82
  this._stage.goto(stageName);
83
83
  }
84
+ fixMediaUrl(mediaUrl) {
85
+ return this._console.fixMediaUrl(mediaUrl);
86
+ }
84
87
  /**
85
88
  * Get the list of devices in a callback
86
89
  * @param callback
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo2555/koppeliajs",
3
- "version": "0.0.127",
3
+ "version": "0.0.128",
4
4
  "scripts": {
5
5
  "dev": "vite dev",
6
6
  "build": "vite build && npm run package",