Twilio Worker:Uncaught TypeError:this._setupWebsocket不是函数

时间:2017-02-28 13:35:14

标签: angular twilio

我在Angular 2中忙于Twilio Taskrouter,但每次执行时都会出错: Twilio.TaskRouter.Worker(tokenData._workerToken);

我得到的错误是Uncaught TypeError: this._setupWebsocket is not a function

这些是我的注射执行的功能:

  this.getTokens("Bob","http://contactcenter.brancheteers.nl/api/twilio/twilioToken","TwilioToken");
  this.getTokens("workerSId here","http://contactcenter.    brancheteers.nl/api/taskrouter/workerToken","WorkerToken");

  getTokens(inputData, url, tokenType) {
    var getData;
    var x = this.http.get(url + "/" + inputData).map(response => response.json());
    x.subscribe(
      data => getData = data,
      error => console.error("HTTP REQUEST FAILED getTokens@baMsgCenter"),
      () => this.initToken(tokenType, getData)
    );
  }

  initToken(tokenType, tokenData) {
    if(tokenType == "WorkerToken") { Twilio.TaskRouter.Worker(tokenData._workerToken);  }
    if(tokenType == "TwilioToken") { Twilio.Device.setup(tokenData._token);  }
  }

我还补充道 在declare const Twilio: any;

之上@injectable()

并调试我记录以查看是否返回了有效的工作人员令牌,并且工作正常。另外值得注意的是twilio设备确实有效。每当我删除行twilio.taskrouter ...时,错误就消失了

我不确定我做错了什么或者是不是错误。为了澄清我想要的东西,我希望错误分散,并让Twilio.Taskrouter.Worker工作,以便我可以将调用队列出来。

    at Function.Worker (http://media.twiliocdn.com/taskrouter/js/v1.0/taskrouter.worker.min.js:1:3135)
    at BaMsgCenterService.initToken (http://localhost:3000/main.bundle.js:2682:31)
    at SafeSubscriber._complete (http://localhost:3000/main.bundle.js:2678:181)
    at SafeSubscriber.__tryOrUnsub (http://localhost:3000/vendor.dll.js:589:16)
    at SafeSubscriber.complete (http://localhost:3000/vendor.dll.js:574:26)
    at Subscriber._complete (http://localhost:3000/vendor.dll.js:498:26)
    at Subscriber.complete (http://localhost:3000/vendor.dll.js:480:18)
    at MapSubscriber.Subscriber._complete (http://localhost:3000/vendor.dll.js:498:26)
    at MapSubscriber.Subscriber.complete (http://localhost:3000/vendor.dll.js:480:18)
    at XMLHttpRequest.onLoad (http://localhost:3000/vendor.dll.js:61704:38)
    at ZoneDelegate.invokeTask (http://localhost:3000/polyfills.dll.js:4262:35)
    at Object.onInvokeTask (http://localhost:3000/vendor.dll.js:30261:37)
    at ZoneDelegate.invokeTask (http://localhost:3000/polyfills.dll.js:4261:40)
    at Zone.runTask (http://localhost:3000/polyfills.dll.js:4138:47)
    at XMLHttpRequest.ZoneTask.invoke (http://localhost:3000/polyfills.dll.js:4332:33)
  -------------   Elapsed: 1246 ms; At: Tue Feb 28 2017 14:26:34 GMT+0100 (CET)   -------------  
    at getStacktraceWithUncaughtError (http://localhost:3000/polyfills.dll.js:3857:12) [angular]
    at new LongStackTrace (http://localhost:3000/polyfills.dll.js:3851:22) [angular]
    at Object.onScheduleTask (http://localhost:3000/polyfills.dll.js:3907:18) [angular]
    at ZoneDelegate.scheduleTask (http://localhost:3000/polyfills.dll.js:4239:49) [angular]
    at Zone.scheduleEventTask (http://localhost:3000/polyfills.dll.js:4158:39) [angular]
    at zoneAwareAddListener (http://localhost:3000/polyfills.dll.js:5213:14) [angular]
    at XMLHttpRequest.addEventListener (eval at createNamedFn (http://localhost:3000/polyfills.dll.js:5319:17), <anonymous>:3:43) [angular]
    at Observable._subscribe (http://localhost:3000/vendor.dll.js:61749:18) [angular]
    at Observable.subscribe (http://localhost:3000/vendor.dll.js:119:27) [angular]
    at MapOperator.call (http://localhost:3000/vendor.dll.js:12258:23) [angular]
    at Observable.subscribe (http://localhost:3000/vendor.dll.js:116:22) [angular]
    at BaMsgCenterService.getTokens (http://localhost:3000/main.bundle.js:2678:11) [angular]
    at new BaMsgCenterService (http://localhost:3000/main.bundle.js:2629:14) [angular]
    at CompiledTemplate.proxyViewClass.View_BaPageTop0.createInternal (/NgaModule/BaPageTop/component.ngfactory.js:131:35) [angular]
    at CompiledTemplate.proxyViewClass.AppView.create (http://localhost:3000/vendor.dll.js:79954:21) [angular]
    at CompiledTemplate.proxyViewClass.DebugAppView.create (http://localhost:3000/vendor.dll.js:80406:44) [angular]
    at CompiledTemplate.proxyViewClass.View_Pages0.createInternal (/PagesModule/Pages/component.ngfactory.js:73:19) [angular]
    at CompiledTemplate.proxyViewClass.AppView.create (http://localhost:3000/vendor.dll.js:79954:21) [angular]
    at CompiledTemplate.proxyViewClass.DebugAppView.create (http://localhost:3000/vendor.dll.js:80406:44) [angular]
    at CompiledTemplate.proxyViewClass.View_Pages_Host0.createInternal (/PagesModule/Pages/host.ngfactory.js:16:19) [angular]
    at CompiledTemplate.proxyViewClass.AppView.createHostView (http://localhost:3000/vendor.dll.js:79967:21) [angular]
    at CompiledTemplate.proxyViewClass.DebugAppView.createHostView (http://localhost:3000/vendor.dll.js:80423:52) [angular]
    at ComponentFactory.create (http://localhost:3000/vendor.dll.js:42290:25) [angular]
    at ViewContainerRef_.createComponent (http://localhost:3000/vendor.dll.js:59196:62) [angular]
    at RouterOutlet.activate (http://localhost:3000/vendor.dll.js:65027:40) [angular]
    at ActivateRoutes.placeComponentIntoOutlet (http://localhost:3000/vendor.dll.js:23870:16) [angular]
    at ActivateRoutes.activateRoutes (http://localhost:3000/vendor.dll.js:23837:26) [angular]
    at http://localhost:3000/vendor.dll.js:23773:58 [angular]
    at Array.forEach (native) [angular]
    at ActivateRoutes.activateChildRoutes (http://localhost:3000/vendor.dll.js:23773:29) [angular]
    at ActivateRoutes.activate (http://localhost:3000/vendor.dll.js:23747:14) [angular]
    at http://localhost:3000/vendor.dll.js:23315:22 [angular]
    at SafeSubscriber._next (http://localhost:3000/vendor.dll.js:157:25) [angular]
    at SafeSubscriber.__tryOrUnsub (http://localhost:3000/vendor.dll.js:589:16) [angular]
    at SafeSubscriber.next (http://localhost:3000/vendor.dll.js:538:22) [angular]
    at Subscriber._next (http://localhost:3000/vendor.dll.js:491:26) [angular]
    at Subscriber.next (http://localhost:3000/vendor.dll.js:455:18) [angular]
    at MapSubscriber._next (http://localhost:3000/vendor.dll.js:12287:26) [angular]
    at MapSubscriber.Subscriber.next (http://localhost:3000/vendor.dll.js:455:18) [angular]
    at MergeMapSubscriber.notifyNext (http://localhost:3000/vendor.dll.js:15738:30) [angular]
    at InnerSubscriber._next (http://localhost:3000/vendor.dll.js:85755:21) [angular]
    at InnerSubscriber.Subscriber.next (http://localhost:3000/vendor.dll.js:455:18) [angular]
    at MapSubscriber._next (http://localhost:3000/vendor.dll.js:12287:26) [angular]
    at MapSubscriber.Subscriber.next (http://localhost:3000/vendor.dll.js:455:18) [angular]
    at ReduceSubscriber._complete (http://localhost:3000/vendor.dll.js:33891:30) [angular]
    at ReduceSubscriber.Subscriber.complete (http://localhost:3000/vendor.dll.js:480:18) [angular]
    at MergeMapSubscriber._complete (http://localhost:3000/vendor.dll.js:15730:30) [angular]
    at MergeMapSubscriber.Subscriber.complete (http://localhost:3000/vendor.dll.js:480:18) [angular]
    at ArrayObservable._subscribe (http://localhost:3000/vendor.dll.js:8633:24) [angular]
    at ArrayObservable.Observable.subscribe (http://localhost:3000/vendor.dll.js:119:27) [angular]
    at MergeMapOperator.call (http://localhost:3000/vendor.dll.js:15680:23) [angular]
    at Observable.subscribe (http://localhost:3000/vendor.dll.js:116:22) [angular]
    at ReduceOperator.call (http://localhost:3000/vendor.dll.js:33850:23) [angular]
    at Observable.subscribe (http://localhost:3000/vendor.dll.js:116:22) [angular]
    at MapOperator.call (http://localhost:3000/vendor.dll.js:12258:23) [angular]
    at Observable.subscribe (http://localhost:3000/vendor.dll.js:116:22) [angular]
    at Object.subscribeToResult (http://localhost:3000/vendor.dll.js:679:27) [angular]
    at MergeMapSubscriber._innerSub (http://localhost:3000/vendor.dll.js:15725:38) [angular]
    at MergeMapSubscriber._tryNext (http://localhost:3000/vendor.dll.js:15722:14) [angular]
    at MergeMapSubscriber._next (http://localhost:3000/vendor.dll.js:15705:18) [angular]
    at MergeMapSubscriber.Subscriber.next (http://localhost:3000/vendor.dll.js:455:18) [angular]
    at MergeMapSubscriber.notifyNext (http://localhost:3000/vendor.dll.js:15738:30) [angular]
    at InnerSubscriber._next (http://localhost:3000/vendor.dll.js:85755:21) [angular]
    at InnerSubscriber.Subscriber.next (http://localhost:3000/vendor.dll.js:455:18) [angular]
    at MapSubscriber._next (http://localhost:3000/vendor.dll.js:12287:26) [angular]
    at MapSubscriber.Subscriber.next (http://localhost:3000/vendor.dll.js:455:18) [angular]
    at EverySubscriber.notifyComplete (http://localhost:3000/vendor.dll.js:47338:26) [angular]
    at EverySubscriber._complete (http://localhost:3000/vendor.dll.js:47355:14) [angular]
    at EverySubscriber.Subscriber.complete (http://localhost:3000/vendor.dll.js:480:18) [angular]
    at MergeMapSubscriber._complete (http://localhost:3000/vendor.dll.js:15730:30) [angular]
    at MergeMapSubscriber.Subscriber.complete (http://localhost:3000/vendor.dll.js:480:18) [angular]
    at ArrayObservable._subscribe (http://localhost:3000/vendor.dll.js:8633:24) [angular]
    at ArrayObservable.Observable.subscribe (http://localhost:3000/vendor.dll.js:119:27) [angular]
    at MergeMapOperator.call (http://localhost:3000/vendor.dll.js:15680:23) [angular]
    at Observable.subscribe (http://localhost:3000/vendor.dll.js:116:22) [angular]
    at EveryOperator.call (http://localhost:3000/vendor.dll.js:47318:23) [angular]
    at Observable.subscribe (http://localhost:3000/vendor.dll.js:116:22) [angular]
    at MapOperator.call (http://localhost:3000/vendor.dll.js:12258:23) [angular]
    at Observable.subscribe (http://localhost:3000/vendor.dll.js:116:22) [angular]
    at Object.subscribeToResult (http://localhost:3000/vendor.dll.js:679:27) [angular]
    at MergeMapSubscriber._innerSub (http://localhost:3000/vendor.dll.js:15725:38) [angular]
    at MergeMapSubscriber._tryNext (http://localhost:3000/vendor.dll.js:15722:14) [angular]
    at MergeMapSubscriber._next (http://localhost:3000/vendor.dll.js:15705:18) [angular]
    at MergeMapSubscriber.Subscriber.next (http://localhost:3000/vendor.dll.js:455:18) [angular]
    at MapSubscriber._next (http://localhost:3000/vendor.dll.js:12287:26) [angular]
    at MapSubscriber.Subscriber.next (http://localhost:3000/vendor.dll.js:455:18) [angular]
    at MergeMapSubscriber.notifyNext (http://localhost:3000/vendor.dll.js:15738:30) [angular]
    at InnerSubscriber._next (http://localhost:3000/vendor.dll.js:85755:21) [angular]
    at InnerSubscriber.Subscriber.next (http://localhost:3000/vendor.dll.js:455:18) [angular]
    at MapSubscriber._next (http://localhost:3000/vendor.dll.js:12287:26) [angular]
    at MapSubscriber.Subscriber.next (http://localhost:3000/vendor.dll.js:455:18) [angular]
    at ScalarObservable._subscribe (http://localhost:3000/vendor.dll.js:46766:24) [angular]
    at ScalarObservable.Observable.subscribe (http://localhost:3000/vendor.dll.js:119:27) [angular]
    at MapOperator.call (http://localhost:3000/vendor.dll.js:12258:23) [angular]
    at Observable.subscribe (http://localhost:3000/vendor.dll.js:116:22) [angular]
    at Object.subscribeToResult (http://localhost:3000/vendor.dll.js:679:27) [angular]
    at MergeMapSubscriber._innerSub (http://localhost:3000/vendor.dll.js:15725:38) [angular]
    at MergeMapSubscriber._tryNext (http://localhost:3000/vendor.dll.js:15722:14) [angular]
    at MergeMapSubscriber._next (http://localhost:3000/vendor.dll.js:15705:18) [angular]
    at MergeMapSubscriber.Subscriber.next (http://localhost:3000/vendor.dll.js:455:18) [angular]
    at CatchSubscriber.Subscriber._next (http://localhost:3000/vendor.dll.js:491:26) [angular]
    at CatchSubscriber.Subscriber.next (http://localhost:3000/vendor.dll.js:455:18) [angular]
    at MapSubscriber._next (http://localhost:3000/vendor.dll.js:12287:26) [angular]
    at MapSubscriber.Subscriber.next (http://localhost:3000/vendor.dll.js:455:18) [angular]
    at MapSubscriber._next (http://localhost:3000/vendor.dll.js:12287:26) [angular]
    at MapSubscriber.Subscriber.next (http://localhost:3000/vendor.dll.js:455:18) [angular]
    at MapSubscriber._next (http://localhost:3000/vendor.dll.js:12287:26) [angular]
    at MapSubscriber.Subscriber.next (http://localhost:3000/vendor.dll.js:455:18) [angular]
    at LastSubscriber._complete (http://localhost:3000/vendor.dll.js:66978:25) [angular]
    at LastSubscriber.Subscriber.complete (http://localhost:3000/vendor.dll.js:480:18) [angular]
    at MergeAllSubscriber.notifyComplete (http://localhost:3000/vendor.dll.js:15583:30) [angular]
    at InnerSubscriber._complete (http://localhost:3000/vendor.dll.js:85762:21) [angular]
    at InnerSubscriber.Subscriber.complete (http://localhost:3000/vendor.dll.js:480:18) [angular]
    at MapSubscriber.Subscriber._complete (http://localhost:3000/vendor.dll.js:498:26) [angular]
    at MapSubscriber.Subscriber.complete (http://localhost:3000/vendor.dll.js:480:18) [angular]
    at CatchSubscriber.Subscriber._complete (http://localhost:3000/vendor.dll.js:498:26) [angular]
    at CatchSubscriber.Subscriber.complete (http://localhost:3000/vendor.dll.js:480:18) [angular]
    at FirstSubscriber._emitFinal (http://localhost:3000/vendor.dll.js:47600:25) [angular]
    at FirstSubscriber._emit (http://localhost:3000/vendor.dll.js:47582:14) [angular]
    at FirstSubscriber._tryPredicate (http://localhost:3000/vendor.dll.js:47574:18) [angular]
    at FirstSubscriber._next (http://localhost:3000/vendor.dll.js:47558:18) [angular]
    at FirstSubscriber.Subscriber.next (http://localhost:3000/vendor.dll.js:455:18) [angular]
    at MergeAllSubscriber.OuterSubscriber.notifyNext (http://localhost:3000/vendor.dll.js:640:26) [angular]
    at InnerSubscriber._next (http://localhost:3000/vendor.dll.js:85755:21) [angular]
    at InnerSubscriber.Subscriber.next (http://localhost:3000/vendor.dll.js:455:18) [angular]
    at CatchSubscriber.Subscriber._next (http://localhost:3000/vendor.dll.js:491:26) [angular]
    at CatchSubscriber.Subscriber.next (http://localhost:3000/vendor.dll.js:455:18) [angular]
    at MergeMapSubscriber.notifyNext (http://localhost:3000/vendor.dll.js:15738:30) [angular]
    at InnerSubscriber._next (http://localhost:3000/vendor.dll.js:85755:21) [angular]
    at InnerSubscriber.Subscriber.next (http://localhost:3000/vendor.dll.js:455:18) [angular]
    at MapSubscriber._next (http://localhost:3000/vendor.dll.js:12287:26) [angular]
    at MapSubscriber.Subscriber.next (http://localhost:3000/vendor.dll.js:455:18) [angular]
    at CatchSubscriber.Subscriber._next (http://localhost:3000/vendor.dll.js:491:26) [angular]
    at CatchSubscriber.Subscriber.next (http://localhost:3000/vendor.dll.js:455:18) [angular]
    at FirstSubscriber._emitFinal (http://localhost:3000/vendor.dll.js:47599:25) [angular]
    at FirstSubscriber._emit (http://localhost:3000/vendor.dll.js:47582:14) [angular]
    at FirstSubscriber._tryPredicate (http://localhost:3000/vendor.dll.js:47574:18) [angular]
    at FirstSubscriber._next (http://localhost:3000/vendor.dll.js:47558:18) [angular]
    at FirstSubscriber.Subscriber.next (http://localhost:3000/vendor.dll.js:455:18) [angular]
    at MergeAllSubscriber.OuterSubscriber.notifyNext (http://localhost:3000/vendor.dll.js:640:26) [angular]
    at InnerSubscriber._next (http://localhost:3000/vendor.dll.js:85755:21) [angular]
    at InnerSubscriber.Subscriber.next (http://localhost:3000/vendor.dll.js:455:18) [angular]
    at CatchSubscriber.Subscriber._next (http://localhost:3000/vendor.dll.js:491:26) [angular]
    at CatchSubscriber.Subscriber.next (http://localhost:3000/vendor.dll.js:455:18) [angular]
    at MergeMapSubscriber.notifyNext (http://localhost:3000/vendor.dll.js:15738:30) [angular]
    at InnerSubscriber._next (http://localhost:3000/vendor.dll.js:85755:21) [angular]
    at InnerSubscriber.Subscriber.next (http://localhost:3000/vendor.dll.js:455:18) [angular]
    at MapSubscriber._next (http://localhost:3000/vendor.dll.js:12287:26) [angular]
    at MapSubscriber.Subscriber.next (http://localhost:3000/vendor.dll.js:455:18) [angular]
    at CatchSubscriber.Subscriber._next (http://localhost:3000/vendor.dll.js:491:26) [angular]
    at CatchSubscriber.Subscriber.next (http://localhost:3000/vendor.dll.js:455:18) [angular]
    at FirstSubscriber._emitFinal (http://localhost:3000/vendor.dll.js:47599:25) [angular]
    at FirstSubscriber._emit (http://localhost:3000/vendor.dll.js:47582:14) [angular]
    at FirstSubscriber._tryPredicate (http://localhost:3000/vendor.dll.js:47574:18) [angular]
    at FirstSubscriber._next (http://localhost:3000/vendor.dll.js:47558:18) [angular]
    at FirstSubscriber.Subscriber.next (http://localhost:3000/vendor.dll.js:455:18) [angular]
    at MergeAllSubscriber.OuterSubscriber.notifyNext (http://localhost:3000/vendor.dll.js:640:26) [angular]
    at InnerSubscriber._next (http://localhost:3000/vendor.dll.js:85755:21) [angular]
    at InnerSubscriber.Subscriber.next (http://localhost:3000/vendor.dll.js:455:18) [angular]
    at CatchSubscriber.Subscriber._next (http://localhost:3000/vendor.dll.js:491:26) [angular]
    at CatchSubscriber.Subscriber.next (http://localhost:3000/vendor.dll.js:455:18) [angular]
    at MergeMapSubscriber.notifyNext (http://localhost:3000/vendor.dll.js:15738:30) [angular]
    at InnerSubscriber._next (http://localhost:3000/vendor.dll.js:85755:21) [angular]
    at InnerSubscriber.Subscriber.next (http://localhost:3000/vendor.dll.js:455:18) [angular]
    at Object.subscribeToResult (http://localhost:3000/vendor.dll.js:674:25) [angular]
    at MergeMapSubscriber._innerSub (http://localhost:3000/vendor.dll.js:15725:38) [angular]
    at MergeMapSubscriber._tryNext (http://localhost:3000/vendor.dll.js:15722:14) [angular]
    at MergeMapSubscriber._next (http://localhost:3000/vendor.dll.js:15705:18) [angular]
    at MergeMapSubscriber.Subscriber.next (http://localhost:3000/vendor.dll.js:455:18) [angular]
    at ScalarObservable._subscribe (http://localhost:3000/vendor.dll.js:46766:24) [angular]
    at ScalarObservable.Observable.subscribe (http://localhost:3000/vendor.dll.js:119:27) [angular]
    at MergeMapOperator.call (http://localhost:3000/vendor.dll.js:15680:23) [angular]
    at Observable.subscribe (http://localhost:3000/vendor.dll.js:116:22) [angular]
    at CatchOperator.call (http://localhost:3000/vendor.dll.js:46812:23) [angular]
    at Observable.subscribe (http://localhost:3000/vendor.dll.js:116:22) [angular]
    at Object.subscribeToResult (http://localhost:3000/vendor.dll.js:679:27) [angular]
    at MergeAllSubscriber._next (http://localhost:3000/vendor.dll.js:15563:42) [angular]
    at MergeAllSubscriber.Subscriber.next (http://localhost:3000/vendor.dll.js:455:18) [angular]
    at MapSubscriber._next (http://localhost:3000/vendor.dll.js:12287:26) [angular]
    at MapSubscriber.Subscriber.next (

1 个答案:

答案 0 :(得分:1)

Twilio.TaskRouter.Worker(tokenData._workerToken);

是一个对象,因此您需要指定new,即

new Twilio.TaskRouter.Worker(tokenData._workerToken);

您不清楚如何使用Worker,但您可能需要考虑将其分配给变量,以便稍后调用其方法。

var worker = new Twilio.TaskRouter.Worker(tokenData._workerToken);