浏览代码

fixing postMessage in WebWorker
postMessage in webworker has a different signature than the one in window.
typescript, however, can't understand the context.
This is a way to override ts's errors when using the correct signature.

Raanan Weber 7 年之前
父节点
当前提交
5a8d16b013
共有 1 个文件被更改,包括 6 次插入3 次删除
  1. 6 3
      src/Collisions/babylon.collisionWorker.ts

+ 6 - 3
src/Collisions/babylon.collisionWorker.ts

@@ -1,5 +1,8 @@
 declare function importScripts(...urls: string[]): void;
 
+// since typescript doesn't understand the file's execution context, we need to override postMessage's signature for error-free compilation
+const safePostMessage: any = self.postMessage;
+
 module BABYLON {
 
     //If this file is included in the main thread, this will be initialized.
@@ -192,7 +195,7 @@ module BABYLON {
                 error: WorkerReplyType.SUCCESS,
                 taskType: WorkerTaskType.INIT
             }
-            postMessage(reply, "");
+            safePostMessage(reply);
         }
 
         public onUpdate(payload: UpdatePayload) {
@@ -226,7 +229,7 @@ module BABYLON {
             }
 
 
-            postMessage(replay, "");
+            safePostMessage(replay);
         }
 
         public onCollision(payload: CollidePayload) {
@@ -247,7 +250,7 @@ module BABYLON {
                 taskType: WorkerTaskType.COLLIDE,
                 payload: replyPayload
             }
-            postMessage(reply, "");
+            safePostMessage(reply);
         }
     }