Skip to content

Add a JavaScript sample to demonstrate SignalR Trigger #103

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions samples/bidirectional-chat/js/Function/.funcignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
*.js.map
*.ts
.git*
.vscode
local.settings.json
test
tsconfig.json
94 changes: 94 additions & 0 deletions samples/bidirectional-chat/js/Function/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache

# next.js build output
.next

# nuxt.js build output
.nuxt

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TypeScript output
dist
out

# Azure Functions artifacts
bin
obj
appsettings.json
local.settings.json
22 changes: 22 additions & 0 deletions samples/bidirectional-chat/js/Function/broadcast/function.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"disabled": false,
"bindings": [
{
"type": "signalRTrigger",
"direction": "in",
"name": "invocation",
"hubName": "simplechat",
"category": "messages",
"event": "broadcast",
"parameterNames": [
"message"
]
},
{
"type": "signalR",
"direction": "out",
"name": "signalRMessages",
"hubName": "simplechat"
}
]
}
14 changes: 14 additions & 0 deletions samples/bidirectional-chat/js/Function/broadcast/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

module.exports = function (context, invocation) {
context.bindings.signalRMessages = [{
"target": "newMessage",
"arguments": [{
"connectionId": invocation.ConnectionId,
"sender": invocation.UserId,
"text": context.bindingData.message
}]
}];
context.done();
};
18 changes: 18 additions & 0 deletions samples/bidirectional-chat/js/Function/connect/function.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"bindings": [
{
"type": "signalRTrigger",
"direction": "in",
"name": "invocation",
"hubName": "simplechat",
"category": "connections",
"event": "connect"
},
{
"type": "signalR",
"direction": "out",
"name": "signalRMessages",
"hubName": "simplechat"
}
]
}
10 changes: 10 additions & 0 deletions samples/bidirectional-chat/js/Function/connect/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

module.exports = function (context, invocation) {
context.bindings.signalRMessages = [{
"target": "newConnection",
"arguments": [ { "connectionId": invocation.ConnectionId } ]
}];
context.done();
};
11 changes: 11 additions & 0 deletions samples/bidirectional-chat/js/Function/extensions.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<WarningsAsErrors></WarningsAsErrors>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\..\src\SignalRServiceExtension\Microsoft.Azure.WebJobs.Extensions.SignalRService.csproj" />
<PackageReference Include="Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator" Version="1.0.0" />
</ItemGroup>
</Project>
3 changes: 3 additions & 0 deletions samples/bidirectional-chat/js/Function/host.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"version": "2.0"
}
15 changes: 15 additions & 0 deletions samples/bidirectional-chat/js/Function/local.settings.sample.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "",
"AzureWebJobsDashboard": "",
"FUNCTIONS_WORKER_RUNTIME": "node",
"AzureSignalRConnectionString": "",
"AzureSignalRServiceTransportType": "Transient"
},
"Host": {
"LocalHttpPort": 7071,
"CORS": "http://localhost:5500",
"CORSCredentials": true
}
}
23 changes: 23 additions & 0 deletions samples/bidirectional-chat/js/Function/negotiate/function.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"disabled": false,
"bindings": [
{
"authLevel": "anonymous",
"type": "httpTrigger",
"direction": "in",
"name": "req"
},
{
"type": "http",
"direction": "out",
"name": "res"
},
{
"type": "signalRConnectionInfo",
"name": "connectionInfo",
"userId": "{headers.x-ms-signalr-userid}",
"hubName": "simplechat",
"direction": "in"
}
]
}
7 changes: 7 additions & 0 deletions samples/bidirectional-chat/js/Function/negotiate/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

module.exports = function (context, req, connectionInfo) {
context.res = { body: connectionInfo };
context.done();
};
5 changes: 5 additions & 0 deletions samples/bidirectional-chat/js/Function/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions samples/bidirectional-chat/js/Function/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "js",
"version": "1.0.0",
"description": "",
"scripts": {
"start": "func start",
"test": "echo \"No tests yet...\""
},
"dependencies": {},
"devDependencies": {}
}
4 changes: 4 additions & 0 deletions samples/bidirectional-chat/js/Function/proxies.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"$schema": "http://json.schemastore.org/proxies",
"proxies": {}
}