This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>SocketCluster Inventory Tracking Sample</title> | |
<link href="/styles/bootstrap.min.css" rel="stylesheet" type="text/css"> | |
<link rel="icon" type="image/png" href="/favicon.ico"> | |
<style> | |
body { | |
padding: 10px; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import getCategoryListPageComponent from '/pages/page-category-list.js'; | |
import getCategoryDetailsPageComponent from '/pages/page-category-details.js'; | |
import getProductDetailsPageComponent from '/pages/page-product-details.js'; | |
import getLoginPageComponent from '/pages/page-login.js'; | |
let socket = socketCluster.create(); | |
let pageOptions = { | |
socket | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getPageComponent(pageOptions) { | |
let socket = pageOptions.socket; | |
return Vue.extend({ | |
data: function () { | |
return { | |
error: null, | |
username: 'bob', | |
password: 'password123' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SCCollection from '/node_modules/sc-collection/sc-collection.js'; | |
import SCModel from '/node_modules/sc-model/sc-model.js'; | |
function getPageComponent(pageOptions) { | |
return Vue.extend({ | |
props: { | |
categoryId: String | |
}, | |
data: function () { | |
this.categoryModel = new SCModel({ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var SCWorker = require('socketcluster/scworker'); | |
var fs = require('fs'); | |
var express = require('express'); | |
var serveStatic = require('serve-static'); | |
var path = require('path'); | |
var dummyData = require('./sc_modules/dummy-data'); | |
var authentication = require('./sc_modules/authentication'); | |
var scCrudRethink = require('sc-crud-rethink'); | |
class Worker extends SCWorker { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports.attach = function (scServer, socket) { | |
var tokenExpiresInSeconds = 10 * 60; | |
var tokenRenewalIntervalInMilliseconds = Math.round( | |
1000 * tokenExpiresInSeconds / 3 | |
); | |
// Keep renewing the token (if there is one) at a predefined interval to make | |
// sure that it doesn't expire while the connection is active. | |
var renewAuthTokenInterval = setInterval(function () { | |
var currentToken = socket.getAuthToken(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// --- in server.js --- | |
// Asyngular/WebSocket connection handling loop. | |
(async () => { | |
for await (let {socket} of agServer.listener('connection')) { | |
// Handle socket connection. | |
} | |
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// --- in server.js --- | |
// Asyngular/WebSocket connection handling loop. | |
(async () => { | |
for await (let {socket} of agServer.listener('connection')) { | |
// Handle socket connection. | |
(async () => { | |
// Set up a loop to handle and respond to RPCs for a procedure. | |
for await (let req of socket.procedure('customProc')) { | |
if (req.data && req.data.bad) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// --- in public/index.html --- | |
// This logic should already be in public/index.html by default. | |
let socket = asyngularClient.create(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// --- in public/index.html --- | |
// ... After the socket is created. | |
(async () => { | |
let result = await socket.invoke('customProc', {foo: 'bar'}); | |
// result will be 'Success' | |
})(); |
OlderNewer