lqq пре 8 година
родитељ
комит
d08ada167d
3 измењених фајлова са 141 додато и 95 уклоњено
  1. 70 47
      dist/peer/app-fecaa264f9.js
  2. 1 1
      dist/peer/index.html
  3. 70 47
      peer/src/js/controller/peerController.js

+ 70 - 47
dist/peer/app-fecaa264f9.js

@@ -166,86 +166,109 @@ angular.module('app').run(['$rootScope', '$state', '$stateParams',
 angular.module('templatescache', []).run(['$templateCache', function($templateCache) {$templateCache.put('templates/peer.html','<div style="margin:5px">\n\n</div>');}]);
 'use strict';
 
-angular.module('app').controller('PeerController', ['$scope', '$state', function($scope, $state) {
+angular.module('app').controller('PeerController', ['$scope', '$state', '$timeout', function ($scope, $state, $timeout) {
 
     lxtalkClient.Invoke('{C62F6059-7741-4AC1-8B8F-97EB5F7C116C}', '_Register', '', $scope);
-    var onConnected = function(c){
-        c.on('data', function(data) {
+    var onConnected = function (c) {
+        c.on('data', function (data) {
             //to do
+            console.info(data);
         });
-        c.on('close', function() {
+        c.on('close', function () {
             delete $scope.connectedPeers[c.peer];
         });
         $scope.connectedPeers[c.peer] = 1;
     };
 
-    $scope.init = function(jsonStr){
+    $scope.options = {
+        host: '120.26.136.253',
+        port: 9000,
+        debug: 3,
+        config: {
+            'iceServers': [{
+                    'url': 'stun:lqq@59.110.63.164',
+                    "credential": "123456"
+                },
+                {
+                    "url": "turn:lqq@59.110.63.164",
+                    "credential": "123456"
+                }
+            ]
+        },
+        key: 'peerjs',
+        logFunction: function () {
+            var copy = Array.prototype.slice.call(arguments).join(' ');
+            console.info(copy);
+        }
+    }
+
+    $scope.init = function (jsonStr) {
+        console.log(jsonStr);
         var data = JSON.parse(jsonStr);
-        // $scope.peer = new Peer(
-        //     {
-        //         config:{
-        //             'iceServers': [
-        //                 { 
-        //                     'url': 'stun:lqq@59.110.63.164', 
-        //                     "credential":"123456" 
-        //                 },
-        //                 {
-        //                     "url":"turn:lqq@59.110.63.164", 
-        //                     "credential":"123456"
-        //                 }
-        //             ]},
-        //         key: data.loginName
-        //     }        
-        // );
-        // $scope.connectedPeers = {};
-        // $scope.peer.on('open', function(id){console.log(id);});
-        // $scope.peer.on('connection', onConnected);
-        // $scope.peer.on('error', function(err){console.log(err);});
+        $scope.loginName = data.loginName;
+        $scope.peer = new Peer(
+            $scope.loginName,
+            $scope.options
+        );
+        $scope.connectedPeers = {};
+        $scope.peer.on('open', function (id) {
+            console.log(id);
+        });
+        $scope.peer.on('connection', onConnected);
+        $scope.peer.on('error', function (err) {
+            $timeout(function () {
+                $scope.init(jsonStr);
+            }, 5000);
+        });
     };
 
-    $scope.connect = function(jsonStr){
+    $scope.connect = function (jsonStr) {
         var data = JSON.parse(jsonStr);
         if (!$scope.connectedPeers[data.loginName]) {
             var c = $scope.peer.connect(data.loginName, data);
-            c.on('open', function(){onConnected(c);});
-            c.on('error', function(err){console.log(err);});
+            c.on('open', function () {
+                onConnected(c);
+            });
+            c.on('error', function (err) {
+                console.log(err);
+            });
             $scope.connectedPeers[data.loginName] = 1;
         }
     };
 
-    $scope.send = function(jsonStr, data){
-        // var param = JSON.parse(jsonStr);
+    $scope.send = function (jsonStr, data) {
+        var param = JSON.parse(jsonStr);
         var buf = new Uint8Array(data);
-        var str = utf8.bytesToString(buf);//new TextDecoder().decode(uint8array); data.toString('utf8')//String.fromCharCode.apply(null, buf);
-        
-        console.info(str);
-        var blob = new Blob(buf)
-        // var c = $scope.peer.connections[param.loginName];
-        // if (c){
-        //     c.send(new Blob(data));
-        // }
+        // var str = utf8.bytesToString(buf);//new TextDecoder().decode(uint8array); data.toString('utf8')//String.fromCharCode.apply(null, buf);
 
-        var reader = new FileReader();
-        reader.readAsText(blob, 'utf-8');
-        reader.onload = function (e) {
-            console.info(reader.result);
+        console.info(buf);
+        var blob = new Blob(buf)
+        var c = $scope.peer.connections[param.loginName];
+        if (c) {
+            c.send(blob);
         }
+
+        // var reader = new FileReader();
+        // reader.readAsText(blob, 'utf-8');
+        // reader.onload = function (e) {
+        //     console.info(reader.result);
+        // }
     };
 
-    $scope.close = function(jsonStr){
+    $scope.close = function (jsonStr) {
         var c = $scope.peer.connections[param.loginName];
-        if (c){
+        if (c) {
             c.close();
         }
     };
 
-    $scope.closeAll = function(jsonStr){
-        _.forEach($scope.peer.connections, function(c) {
+    $scope.closeAll = function (jsonStr) {
+        _.forEach($scope.peer.connections, function (c) {
             c.close();
         });
     };
 
-    $scope.destroy = function(jsonStr){
+    $scope.destroy = function (jsonStr) {
         $scope.peer.destroy();
     };
 }]);

+ 1 - 1
dist/peer/index.html

@@ -20,7 +20,7 @@
     <script src="../bower_components/angular/angular.min.js"></script>
     <script src="../bower_components/angular-ui-router/release/angular-ui-router.min.js"></script>
     <script src="../bower_components/angular-animate/angular-animate.min.js"></script>
-    <script src="app-fecaa264f9.js"></script>
+    <script src="app-630fff88a4.js"></script>
 </body>
 
 </html>

+ 70 - 47
peer/src/js/controller/peerController.js

@@ -1,85 +1,108 @@
 'use strict';
 
-angular.module('app').controller('PeerController', ['$scope', '$state', function($scope, $state) {
+angular.module('app').controller('PeerController', ['$scope', '$state', '$timeout', function ($scope, $state, $timeout) {
 
     lxtalkClient.Invoke('{C62F6059-7741-4AC1-8B8F-97EB5F7C116C}', '_Register', '', $scope);
-    var onConnected = function(c){
-        c.on('data', function(data) {
+    var onConnected = function (c) {
+        c.on('data', function (data) {
             //to do
+            console.info(data);
         });
-        c.on('close', function() {
+        c.on('close', function () {
             delete $scope.connectedPeers[c.peer];
         });
         $scope.connectedPeers[c.peer] = 1;
     };
 
-    $scope.init = function(jsonStr){
+    $scope.options = {
+        host: '120.26.136.253',
+        port: 9000,
+        debug: 3,
+        config: {
+            'iceServers': [{
+                    'url': 'stun:lqq@59.110.63.164',
+                    "credential": "123456"
+                },
+                {
+                    "url": "turn:lqq@59.110.63.164",
+                    "credential": "123456"
+                }
+            ]
+        },
+        key: 'peerjs',
+        logFunction: function () {
+            var copy = Array.prototype.slice.call(arguments).join(' ');
+            console.info(copy);
+        }
+    }
+
+    $scope.init = function (jsonStr) {
+        console.log(jsonStr);
         var data = JSON.parse(jsonStr);
-        // $scope.peer = new Peer(
-        //     {
-        //         config:{
-        //             'iceServers': [
-        //                 { 
-        //                     'url': 'stun:lqq@59.110.63.164', 
-        //                     "credential":"123456" 
-        //                 },
-        //                 {
-        //                     "url":"turn:lqq@59.110.63.164", 
-        //                     "credential":"123456"
-        //                 }
-        //             ]},
-        //         key: data.loginName
-        //     }        
-        // );
-        // $scope.connectedPeers = {};
-        // $scope.peer.on('open', function(id){console.log(id);});
-        // $scope.peer.on('connection', onConnected);
-        // $scope.peer.on('error', function(err){console.log(err);});
+        $scope.loginName = data.loginName;
+        $scope.peer = new Peer(
+            $scope.loginName,
+            $scope.options
+        );
+        $scope.connectedPeers = {};
+        $scope.peer.on('open', function (id) {
+            console.log(id);
+        });
+        $scope.peer.on('connection', onConnected);
+        $scope.peer.on('error', function (err) {
+            $timeout(function () {
+                $scope.init(jsonStr);
+            }, 5000);
+        });
     };
 
-    $scope.connect = function(jsonStr){
+    $scope.connect = function (jsonStr) {
         var data = JSON.parse(jsonStr);
         if (!$scope.connectedPeers[data.loginName]) {
             var c = $scope.peer.connect(data.loginName, data);
-            c.on('open', function(){onConnected(c);});
-            c.on('error', function(err){console.log(err);});
+            c.on('open', function () {
+                onConnected(c);
+            });
+            c.on('error', function (err) {
+                console.log(err);
+            });
             $scope.connectedPeers[data.loginName] = 1;
         }
     };
 
-    $scope.send = function(jsonStr, data){
-        // var param = JSON.parse(jsonStr);
+    $scope.send = function (jsonStr, data) {
+        var param = JSON.parse(jsonStr);
         var buf = new Uint8Array(data);
-        var str = utf8.bytesToString(buf);//new TextDecoder().decode(uint8array); data.toString('utf8')//String.fromCharCode.apply(null, buf);
-        
-        console.info(str);
-        var blob = new Blob(buf)
-        // var c = $scope.peer.connections[param.loginName];
-        // if (c){
-        //     c.send(new Blob(data));
-        // }
+        // var str = utf8.bytesToString(buf);//new TextDecoder().decode(uint8array); data.toString('utf8')//String.fromCharCode.apply(null, buf);
 
-        var reader = new FileReader();
-        reader.readAsText(blob, 'utf-8');
-        reader.onload = function (e) {
-            console.info(reader.result);
+        console.info(buf);
+        var blob = new Blob(buf)
+        var c = $scope.peer.connections[param.loginName];
+        if (c) {
+            c.send(blob);
         }
+
+        // var reader = new FileReader();
+        // reader.readAsText(blob, 'utf-8');
+        // reader.onload = function (e) {
+        //     console.info(reader.result);
+        // }
     };
 
-    $scope.close = function(jsonStr){
+    $scope.close = function (jsonStr) {
         var c = $scope.peer.connections[param.loginName];
-        if (c){
+        if (c) {
             c.close();
         }
     };
 
-    $scope.closeAll = function(jsonStr){
-        _.forEach($scope.peer.connections, function(c) {
+    $scope.closeAll = function (jsonStr) {
+        _.forEach($scope.peer.connections, function (c) {
             c.close();
         });
     };
 
-    $scope.destroy = function(jsonStr){
+    $scope.destroy = function (jsonStr) {
         $scope.peer.destroy();
     };
 }]);