PageSourceSearch

https://cdnn.1prime.ru//js/libs/ria.sock.js

js 1prime.ru collected 2026-10-01 08:33:01 UTC 3,647 bytes, 122 lines download raw bytes

1var RIA_SOCK_DEFAULT_INTERVALS = [10000, 15000, 45000, 70000, 300000];
2
3var ria_sock = {
4    events: {},
5    instance: null,
6    connected: false,
7    connectionInterval: null,
8    connectionIntervalTime: 30000,
9    reconnectIntervals: RIA_SOCK_DEFAULT_INTERVALS.concat([]),
10    url: GLOBAL.sock.server,
11    on: function (eventName, fn) {
12        this.events[eventName] = this.events[eventName] || [];
13        this.events[eventName].push(fn);
14    },
15    off: function (eventName, fn) {
16        if (this.events[eventName]) {
17            for (var i = 0; i < this.events[eventName].length; i++) {
18                if (this.events[eventName][i] === fn) {
19                    this.events[eventName].splice(i, 1);
20                    break;
21                }
22            };
23        }
24    },
25    emit: function (eventName, data) {
26        if (this.events[eventName]) {
27            this.events[eventName].forEach(function (fn) {
28                fn(data);
29            });
30        }
31    },
32    get: function() {
33        return this.instance;
34    },
35    send: function(data) {
36        data.message.lang = 'rus';
37        data.message.project = GLOBAL.project || 'prime';
38        this.instance && this.instance.send(JSON.stringify(data));
39    },
40    connect: function() {
41        ria_sock.instance = new SockJS(ria_sock.url, null, {
42            transports: ['websocket']
43        });
44    },
45    reconnect: function() {
46        if (!ria_sock.reconnectIntervals.length) {
47            return;
48        }
49
50        if (ria_sock.connected) {
51            return;
52        }
53
54        // jitter ±25%: delay in [0.75*interval, 1.25*interval]
55        var interval = ria_sock.reconnectIntervals.shift();
56        var delay = interval * (0.75 + Math.random() * 0.5);
57        
58        // setTimeout(function() {
59        //     ria_sock.init();
60        // }, ria_sock.reconnectIntervals.shift())
61
62        setTimeout(function() {
63            ria_sock.init({
64                reconnect: true
65            });
66        }, delay);
67    },
68    init: function() {
69        if (!ria_sock.instance) {
70            ria_sock.connect();
71        }
72    
73        this.instance.onmessage = function(e) {
74            var data = JSON.parse(e.data);
75            ria_sock.emit(data.type, data);
76            ria_sock.emit('onmessage', e);
77        }
78    
79        this.instance.onopen = function() {
80            if (ria_sock.connectionInterval) {
81                clearInterval(ria_sock.connectionInterval)
82            }
83            
84            ria_sock.connected = true;
85
86            ria_sock.connectionInterval = setInterval(function() {
87                ria_sock.reconnectIntervals = RIA_SOCK_DEFAULT_INTERVALS.concat([]);
88                clearInterval(ria_sock.connectionInterval);
89            }, ria_sock.connectionIntervalTime);
90
91            ria_sock.send({
92                type: 'user_join',
93                message: {
94                    user_id: GLOBAL.user.id || null,
95                    obj_id: (GLOBAL.article && GLOBAL.article.id) || (location.pathname === '/' ? 'main' : 'page')
96                }
97            });
98
99            ria_sock.emit('onopen');
100        }
101    
102        this.instance.onclose = function(e) {
103            if (ria_sock.connectionInterval) {
104                clearInterval(ria_sock.connectionInterval)
105            }
106
107            ria_sock.connected = false;
108            
109            ria_sock.instance = null;
110            ria_sock.reconnect();
111
112            ria_sock.emit('onclose', e);
113        }
114    
115        this.instance.onerror = function(e) {
116            console.error("Sock connection error", e);
117            ria_sock.emit('onerror', e);
118        }
119    }
120};
121
122ria_sock.init();

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.