osc.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. * WebRTC.js : Behaves as a wrapper for vwf/view/rtcObject
  3. * Maps simple 1:1 signal model to a broadcast model using target and sender ids
  4. */
  5. define(["module", "vwf/view", "vwf/view/oscjs/dist/osc-module"], function(module, view, osc) {
  6. return view.load(module, {
  7. initialize: function() {
  8. self = this;
  9. this.osc = osc;
  10. this.portValue = '8081';
  11. this.hostValue = 'localhost';
  12. this.port = null;
  13. //window._osc = this.osc;
  14. window._OSCManager = this;
  15. },
  16. /*
  17. * Receives incoming messages
  18. */
  19. // calledMethod: function(id, name, params) {
  20. // },
  21. setOSCHostAndPort: function(h,p) {
  22. this.hostValue = h;
  23. this.portValue = p;
  24. },
  25. connect: function() {
  26. this.disconnect();
  27. this.port = new osc.WebSocketPort({
  28. url: 'ws://' + this.hostValue + ':' + this.portValue
  29. //url: "ws://localhost:8081"
  30. });
  31. this.port.on("message", function (oscMessage) {
  32. console.log("message", oscMessage);
  33. findAllNodesWithOSC(oscMessage);
  34. });
  35. this.port.open();
  36. },
  37. disconnect: function() {
  38. console.log('disconnect');
  39. if (this.port !== null)
  40. this.port.close(1000, 'manual close');
  41. },
  42. getStatus: function() {
  43. if (this.port){
  44. return this.port.socket.readyState
  45. }
  46. return 3
  47. }
  48. })
  49. function findAllNodesWithOSC(oscMessage){
  50. let appID = vwf.application();
  51. var oscSceneProp = vwf.getProperty(appID, 'osc');
  52. if (oscSceneProp !== undefined){
  53. if (oscSceneProp){
  54. //console.log('now callMethod');
  55. vwf_view.kernel.callMethod(appID, 'getOSC', [oscMessage]);
  56. }
  57. }
  58. var children = vwf.children(appID);
  59. children.forEach(function(child){
  60. var oscprop = vwf.getProperty(child, 'osc');
  61. if (oscprop !== undefined){
  62. if (oscprop){
  63. //console.log('now callMethod');
  64. vwf_view.kernel.callMethod(child, 'getOSC', [oscMessage]);
  65. }
  66. }
  67. })
  68. // var scene = _Editor.getNode(Engine.application());
  69. // for (var i in scene.children) {
  70. // if (scene.children[i].properties.DisplayName.indexOf("leapmotion") > -1) {
  71. // this.leapHandsID = (scene.children[i].id);
  72. // }
  73. // }
  74. }
  75. });